多网卡冗余配置

更新时间:
2024-03-14
下载文档

多网卡冗余配置

概述

冗余含义是指人为增加重复部分,其目的是用来对原本的单一部分进行备份,以达到增强其安全性的目的。

多网卡冗余就是通过工具将两块或者两块以上的网卡虚拟成一块网卡,虚拟出的网卡与外界进行网络通信。

网卡冗余的好处有以下几点:

  • 提高网络可用性。通过配置多块网卡,可以避免单点故障导致网络中断。当一块网卡出现故障时,可以快速切换到其他网卡,网络可以持续可用。
  • 实现负载平衡。可以将不同网络流量分别通过不同网卡进行传输,以实现负载平衡和容错能力。
  • 提供备份。多块网卡可以作为备份网卡,在工作网卡出现故障时替代工作网卡,提高网络可靠性。
  • 支持链路聚合。多块网卡可以配置链路聚合,将多条链路打包成一个逻辑链路,扩展带宽和提高链路的利用率与容错能力。

冗余策略

在 SylixOS 系统中,通常使用 netbonding 命令来配置多网卡冗余,netbonding 是一种 SylixOS 系统下的网卡绑定技术,可以把板卡上 n 个物理网卡在系统内部抽象(绑定)成一个逻辑上的网卡,实现了网卡冗余、负载平衡等功能,有很多优势。

目前,SylixOS 支持 3 种网卡绑定模式:

  • 平衡循环策略。
  • 主 - 备份策略。
  • 广播策略。

平衡循环策略

平衡循环策略是每个数据包只从一个网口发送,并且整个完整数据(由多个数据包组成)是选取有效的网卡轮询发送。简单地说,就是第 1 个数据包走 eth0 网口,下一个数据包就走 eth1 网口,一直循环下去,直到最后一个数据包传输完毕。

此模式提供了负载平衡和容错能力。

主 - 备份策略

主 - 备份策略是在绑定两个网卡的情况下以其中一个网卡为主网卡进行通信,另一个网卡只有在主网卡出现故障后才自动替换原主卡进行通信。

此模式只提供了容错能力,该模式的优点是可以提供高网络连接的可用性,但是它的资源利用率较低,只有一个接口处于工作状态,在有 N 个网络接口的情况下,资源利用率为 1/N。

广播策略

广播策略表示所有数据包从所有网络接口发出,这个不均衡,只有冗余机制,但过于浪费资源。

此模式提供了容错能力。

netbonding 命令

在 SylixOS 系统的Shell界面中,使用 help netbonding 命令可以查看 netbonding 命令的具体使用方法

[root@sylixos:/root]# help netbonding
add / delete / control net bonding.
eg. netbonding show bond0              (Show all net device in 'bond0' net bonding)
    netbonding addbd bond0 [...]       (Add a net bonding named 'bond0')
    netbonding changebd bond0 [...]    (Change a net bonding named 'bond0')

    [...]: [ab|bl|bc] [-t|-a|-l] [interval] [time to alive]

    ab           : Active Backup mode
    bl           : Balance RR mode
    bc           : Broadcast mode
    -t           : Traffic detect in 'Active Backup' mode
    -a           : ARP detect in 'Active Backup' mode
    -l           : Linkup detect only in 'Active Backup' mode
    interval     : ARP detect interval (milliseconds)
    time to alive: When detect OK how long does it take to active (milliseconds)

    netbonding delbd bond0             (Delete a net bonding named 'bond0')
    netbonding adddev bond0 ethdev0    (Add a net device in net bonding named 'bond0')
    netbonding deldev bond0 ethdev0    (Delete a net device from net bonding named 'bond0')
    netbonding addif bond0 en1         (Same as 'adddev' but use interface name)
    netbonding delif bond0 en1         (Same as 'deldev' but use interface name)
    netbonding masterdev bond0 ethdev0 (Make net device 'ethdev0' as a master device in 'bond0')
    netbonding masterif bond0 en1      (Same as 'masterdev' but use interface name)
    netbonding addarp bond0 10.0.0.1   (Add a ARP detect target to net bonding named 'bond0')
    netbonding delarp bond0 10.0.0.1   (Delete a ARP detect target from net bonding named 'bond0')
netbonding [...]
[root@sylixos:/root]# 

参数说明如下:

  • addbd :添加新的 bond 设备。
  • changebd :更改 bond 设备名字。
  • delbd:删除 bond 设备。
  • show:显示在 bond 设备中的所有网络设备。
  • ab:bond 设备使用主 - 备份策略。
  • bl:bond 设备使用平衡循环策略。
  • bc:bond 设备使用广播策略。
  • -t:开启流量探测功能,只在主 - 备份策略中有效。
  • -a:开启 ARP 探测功能,只在主 - 备份策略中有效。
  • -l:在主 - 备份策略中开启 linkup 模式,linkup 模式不再需要设置 “interval” 和 “time to alive” 参数。
  • interval:ARP 探测间隔(毫秒)。
  • time to alive:网络接口生存时间。
  • adddev:将一个网络设备添加到 bond 设备。
  • deldev:将一个网络设备从 bond 设备中删除。
  • addif:将一个网络设备添加到 bond 设备,但是使用的是网络接口名字。
  • delif:将一个网络设备从 bond 设备中删除,但是使用的是网络接口名字。
  • masterdev:将网络设备设置为 bond 中的主设备。
  • masterif:将网络设备设置为 bond 中的主设备,但是使用的是网络接口名字。
  • addarp:添加一个 ARP 探测目标。
  • delarp:删除一个 ARP 探测目标。

注意:
参数 time to alive 值一定要大于等于参数 interval 值。
参数 -t、-a、-l 、interval、time to alive 仅仅在主 - 备份策略下有效,使用其他策略时,这些参数不起任何作用。
参数 interval 要大于等于 10。

添加 bond 设备

  • 增加一个名为 bond0 的设备,使用主 - 备份策略,开启流量探测功能,100 代表 interval 值,在流量探测模式下不起作用,1000 代表网络接口的生存时间 1000 ms,当生存时间减为 0 时,该网络接口不能再向外发送数据包。

    [root@sylixos:/root]# netbonding addbd bond0 ab -t 100 1000
    
  • 增加一个名为 bond0 的设备,使用主 - 备份策略,开启 ARP 探测功能,10 代表 interval 值,表示 bond 网口每隔 10 ms 发一次 ARP 探测包,100 代表网络接口的生存时间 100ms,当生存时间减为 0 时,该网络接口不能再向外发送数据包。

    [root@sylixos:/root]# netbonding addbd bond0 ab -a 10 1000
    
  • 增加一个名为 bond0 的设备,使用平衡循环策略,-l 选项在该策略下,不起任何作用,加上仅仅是为了该命令能够正常解析参数。

    [root@sylixos:/root]# netbonding addbd bond0 bl -l
    
  • 增加一个名为 bond0 的设备,使用广播策略,-l 选项在该策略下,不起任何作用,加上仅仅是为了该命令能够正常解析参数。

    [root@sylixos:/root]# netbonding addbd bond0 bc -l
    

删除 bond 设备

  • 删除一个名为 bond0 的设备,不用区分 bond 设备使用的具体策略。

     [root@sylixos:/root]# netbonding delbd bond0 
    

网络设备添加到 bond 设备

将一个网络设备添加到 bond 设备,有两种方式:

  • 通过网络设备名字添加,bond0 为 bond 设备名,dw_1 为网卡名。

    [root@sylixos:/root]# netbonding adddev bond0 dw_1
    
  • 通过网络接口名字添加,bond0 为 bond 设备名,en1 为网络接口名。

    [root@sylixos:/root]# netbonding addif bond0 en1
    

从 bond 设备删除网络设备

将一个网络设备从 bond 设备中删除,有两种方式:

  • 通过网络设备名字删除,bond0 为 bond 设备名,dw_0 为网卡名。

    [root@sylixos:/root]# netbonding deldev bond0 dw_0
    
  • 通过网络接口名字删除,bond0 为 bond 设备名,en1 为网络接口名。

    [root@sylixos:/root]# netbonding delif bond0 en1
    

显示 bond 中所有的网络设备

[root@sylixos:/root]# netbonding show bond0
Net bonding summary >>

Device      : bond0
Ifname      : bd4
Mode        : Balance RR

Net bonding device list >>

<0> Dev: dw_0 Prev-Ifname: en1 Spd: 1000 Mbps Active: Yes Master: No Linkup: Enable Prev-HWaddr: 00:11:22:33:44:98
[root@sylixos:/root]# 

设置主设备

使网络设备作为主设备,该功能只在主 - 备份策略中使用。

设置主设备有两种方式:

  • 通过网络设备名字设置,bond0 为 bond 设备名,dw_0 为网卡名。

    [root@sylixos:/root]# netbonding masterdev bond0 dw_0 
    
  • 通过网络接口名字设置,bond0 为 bond 设备名,en1 为网络接口名。

    [root@sylixos:/root]# netbonding masterif bond0 en1
    

添加 ARP 探测目标

该功能只在主 - 备份策略的 ARP 探测模式中使用。

  • 添加一个 ARP 探测目标

    [root@sylixos:/root]#  netbonding addarp bond0 10.0.0.1
    

删除 ARP 探测目标

该功能只在主 - 备份策略的 ARP 探测模式中使用。

  • 删除一个 ARP 探测目标

    [root@sylixos:/root]#  netbonding delarp bond0 10.0.0.1
    
文档内容是否对您有所帮助?
有帮助
没帮助