ubuntu-多网卡聚合-bond技术 mode=1 (active-backup)(主备模式) mode=6 (balance-alb) Adaptive load balancing
  ETWZF7L1nsXD 2023年11月13日 19 0

ubuntu-多网卡聚合-bond技术

Linux bonding一共有7种工作模式(mode),
 如果是想要加大网卡的吞吐量,通常会使用mode=6的模式,
 如果是注重网络的稳定,通常会使用mode=1的模式

1、Bond的工作模式
Linux bonding驱动能把多张网卡绑定为一个逻辑网卡,用于网络负载均衡及网络冗余。

bonding一共有7种工作模式(mode):

1)、mode=0,(balance-rr)(轮询均衡模式)
传输数据包顺序是依次传输,直到最后一个传输完毕,此模式提供负载平衡和容错能力,服务器对外只有一个MAC地址,其物理网卡是没有MAC地址的,因此需要交换机做链路聚合,否则不知道要将数据包发送给哪个网卡.

2)、mode=1,(active-backup)(主备模式)
只有一个主设备处于活动状态。一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得。此模式提供了容错能力。不需要交换机特别配置,配置access端口就可以了。

3)、mode=2,(balance-xor)(平衡策略)
特点:基于指定的传输HASH策略传输数据包。此模式提供负载平衡和容错能力。

4)、mode=3,(broadcast) (广播策略)
特点:在每个网卡上传输每个数据包,广播包太多,一般不使用此模式。将所有数据包传输给所有设备。此模式提供了容错能力。

5)、mode=4,(802.3ad) IEEE 802.3ad Dynamic link aggregation. IEEE 802.3ad 动态链接聚合
创建共享相同的速度和双工设置的聚合组。此模式提供了容错能力。每个设备需要基于驱动的重新获取速度和全双工支持;如果使用交换机,交换机也需启用 802.3ad 模式。

6)、mode=5,(balance-tlb) Adaptive transmit load balancing(适配器传输负载均衡)
特点:不需要任何特别的switch(交换机)支持的通道bonding。在每个网卡上根据当前的负载(根据速度计算)分配外出流量。如果正在接受数据的网卡出故障了,另一个网卡接管失败的网卡的MAC地址。交换机上可见多个网卡的MAC,因此不需要交换机做链路聚合配置。

7)、mode=6,(balance-alb) Adaptive load balancing: (适配器适应性负载均衡)
特点:该模式包含了balance-tlb模式,同时加上针对IPV4流量的接收负载均衡(receiveload balance, rlb),而且不需要任何switch(交换机)的支持。交换机上也是可见多个网卡的MAC,不需要做链路聚合配置。

    以下部分是mode=6实现原理,了解一下:

    1.bond接收负载均衡是通过ARP协议实现的。bonding驱动截获本机发送的ARP应答,并把源MAC地址改写为bond中某个网卡的MAC地址,从而使得交换机上学习到的ARP是服务器想要分配流量的MAC地址,向服务器发送的流量则会发送到相对应的MAC地址。

    2.bond发送负载均衡也是通过ARP协议实现的。当服务器发起ARP请求时,bonding驱动把对端的IP信息从ARP包中复制并保存下来。当ARP应答从对端到达时,bonding驱动把它的MAC地址提取出来,并伪造一个ARP应答给bond中的某个网卡,以此实现从指定的网卡发出数据包。

   3.当有网卡出现故障或ARP过期时,bond都会重新计算,将流量重新分配到各个网卡。

2、配置步骤

mode=6 模式的双网卡绑定

步骤,其他模式的方法一样;

2.1、安装ifenslave软件
fenslave为一种粘合和分离式的软件,可以将数据包有效的分配到bonding驱动

sudo apt install ifenslave

2.2、/etc/modules文件
在/etc/modules文件中加入以下配置

bonding mode=6 miimon=100

mode=6 表示采用模式6;
miimon是用来进行链路监测的。比如miimon=100,表示系统每100ms监测一次链路连接状态,如果有一条线路不通就切换另一条线路。

2.3、修改/etc/network/interfaces文件配置
首先需要确定网卡接口的名称,可以通过ifconfig命令查看,当前是网卡接口分别是ens33和ens34;在/etc/network/interfaces文件增加如下配置

# 双网卡配置
auto ens33
iface ens33 inet manual
bond-master bond0auto ens34
iface ens34 inet manual
bond-master bond0auto bond0
iface bond0 inet static
address 192.168.20.10
netmask 255.255.255.0
gateway 192.168.20.2
dns-nameservers 192.168.20.1 119.29.29.29
bond-slaves ens33 ens34
bond-lacp-rate 1
bond-mode 6
bond-miimon 100

2.4、加载binding模块

#  载入模块
$ sudo modprobe bonding
# 查看模块,如果模块已经加载,显示出来
$ sudo lsmod|grep bonding
bonding               163840  0

2.5、查看状态
查看网络配置

$ ifconfig
bond0     Link encap:以太网  硬件地址 00:0c:29:34:7a:4a  inet 地址:192.168.20.10  广播:192.168.20.255  掩码:255.255.255.0inet6 地址: fe80::20c:29ff:fe34:7a4a/64 Scope:LinkUP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  跃点数:1接收数据包:964 错误:0 丢弃:0 过载:0 帧数:0发送数据包:4205 错误:0 丢弃:0 过载:0 载波:0碰撞:0 发送队列长度:1000 接收字节:75022 (75.0 KB)  发送字节:300032 (300.0 KB)ens33     Link encap:以太网  硬件地址 00:0c:29:34:7a:4a  UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  跃点数:1接收数据包:2740 错误:0 丢弃:0 过载:0 帧数:0发送数据包:3416 错误:0 丢弃:0 过载:0 载波:0碰撞:0 发送队列长度:1000 接收字节:3899473 (3.8 MB)  发送字节:278409 (278.4 KB)ens34     Link encap:以太网  硬件地址 00:0c:29:34:7a:54  UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  跃点数:1接收数据包:1369 错误:0 丢弃:0 过载:0 帧数:0发送数据包:2125 错误:0 丢弃:0 过载:0 载波:0碰撞:0 发送队列长度:1000 接收字节:106846 (106.8 KB)  发送字节:139061 (139.0 KB)

查看binding状态

$ cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)Bonding Mode: adaptive load balancing
Primary Slave: None
Currently Active Slave: ens33
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: ens33
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:34:7a:4a
Slave queue ID: 0Slave Interface: ens34
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:34:7a:54
Slave queue ID: 0

2.6、验证测试
物理上关闭一个网卡(拔网线)

# 关闭前,速率是2000Mb/s
$ ethtool bond0
Settings for bond0:Supported ports: [ ]Supported link modes:   Not reportedSupported pause frame use: NoSupports auto-negotiation: NoAdvertised link modes:  Not reportedAdvertised pause frame use: NoAdvertised auto-negotiation: NoSpeed: 2000Mb/sDuplex: FullPort: OtherPHYAD: 0Transceiver: internalAuto-negotiation: off
Cannot get wake-on-lan settings: Operation not permittedLink detected: yes# 关闭后,速率速率变成1000Mb/s
$ ethtool bond0
Settings for bond0:Supported ports: [ ]Supported link modes:   Not reportedSupported pause frame use: NoSupports auto-negotiation: NoAdvertised link modes:  Not reportedAdvertised pause frame use: NoAdvertised auto-negotiation: NoSpeed: 1000Mb/sDuplex: FullPort: OtherPHYAD: 0Transceiver: internalAuto-negotiation: off
Cannot get wake-on-lan settings: Operation not permittedLink detected: yes

注意:不可以使用ifdown 关闭网卡,会导致网络中断

 mode=1(active-backup)(主备模式)

ubuntu-多网卡聚合-bond技术 mode=1 (active-backup)(主备模式) mode=6 (balance-alb) Adaptive load balancing_链路

、编辑配置文件

root@ubuntu:~# vim /etc/netplan/00-installer-config.yaml

network:

    version:2

    ethernets:

        ens160:

           dhcp4:no

        ens192:

            dhcp4:no

     bonds:

         bond0:

            interfaces:

               - ens160

               - ens192

            addresses:[192.168.2.50/24]

            gateway4:192.168.2.1

            nameservers:

                addresses:[114.114.114.114]

            parameters:

                mode:active-backup

                mii-monitor-interval:100

三、重启网络后验证

# sudo netplan apply                                  //更新网络

# cat /proc/net/bonding/bond0                   //查看bond配置信息

3、总结
Linux bonding一共有7种工作模式(mode),如果是想要加大网卡的吞吐量,通常会使用mode=6的模式,如果是注重网络的稳定,通常会使用mode=1的模式

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月13日 0

暂无评论

推荐阅读
  jnZtF7Co41Wg   2023年12月06日   27   0   0 sedlinux数据
  eHipUjOuzYYH   2023年12月06日   33   0   0 sedbootstrapIPV6
  xIUntf9oR6GI   2023年11月28日   31   0   0 sedvim基础命令
  oIa1edJoFmXP   2023年11月24日   30   0   0 AppsedVue
ETWZF7L1nsXD