bond,是一种双网卡绑定技术。即将多块物理网卡绑定成一个逻辑网卡,并实现网卡冗余、流量均衡等的一种可靠性强且高可用技术。
七种bond模式:
一、mod=0即banlance-rr(平衡轮循环策略)
特点:传输数据包的顺序是依次传输,第一个走eth0,第二个包走eth1……一直这样循环下去,直到传输完成。该模式提供负载均衡和容错能力。
假如当一个连接或会话的数据包从不同的接口发出,并经过不同的链路,客户端可能会出现数据包无序到达的情况,这样导致无序到达的数据需重新被发送,便会导致网络的吞吐量的下降。
二、mod=1即active-backup(主-备份策略)
特点:只有一个网卡设备处于活动状态,当处于primary的网卡出现故障或宕掉,便会立即将slave网卡转换为master网卡,接应原来主网卡的流量传输。该模式只提供了容错的能力。
网卡的mac地址是独一的,是bond的mac地址是唯一的,这也避免了交换机发生混乱,产生arp广播风暴。一方面该模式能够提供网卡连接的可用性;另一方面只有一块网卡处理活跃状态,资源的利用率低。
三、mod=2即balance-xor(平衡策略)
特点:基于指定的传输HASH策略传输数据包。该模式提供负载均衡和容错能力。
四、mode=3即broadcast(广播策略)
特点:在每个slave接口上传输每个数据包,该模式提供了容错能力。
五、mod=4即802.3ad(IEEE802.3ad动态链接聚合)
特点:创建一个聚合组,它们共享同样的速率和双工设定。外出流量slave选举是基于传输hash策略,该策略可以通过xmit_hash_policy选项从缺省的XOR策略改变到其他策略。
条件:ethbool支持获取每个slave的速率和双工设定;交换机支持IEEE802.3ad;
大多数交换机需要经过特定配置才能支持802.3ad模式。
六、mod=5即balance-tlb(适调器传输负载均衡)
特点:不需要任何特别的交换机支持的通道bonding。在每个slave根据当前的负载分配外出流量。如果正在接受数据的slave出现故障了,另一个slave接管失败的slave的mac地址。
条件:ethbool支持获取每个slave的速率。
七、mode=6即balance-alb(适调器适应性负载均衡)
特点:该模式包含了balance-tlb模式,同时加上针对ipv4流量的接收负载均衡,而且不需要交换机的支持。接收负载均衡是通过ARP协商实现的。
实验以centos7.2进行网卡绑定的过程:
一、创建一个bond0
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cat ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
IPADDR=172.25.254.200
NETMASK=255.255.255.0
GATEWAY=172.25.254.2
NETWORK=172.25.254.0
DNS1=202.96.134.133
BONDING_OPTS="mode=1 miimon=100 primary=eno16777736"
USERCTL=no
[[email protected] network-scripts]#
二、修改双网卡的配置文件
[[email protected] network-scripts]# cat ifcfg-eno16777736
DEVICE=eno16777736
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
NM_CONTORLLED=no
[[email protected] network-scripts]# cat ifcfg-eno33554992
DEVICE=eno33554992
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
NM_CONTORLLED=no
[[email protected] network-scripts]#
三、重启网络服务
[[email protected] network-scripts]# systemctl restart network
#加载bonding模块
[[email protected] network-scripts]# cat /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bond0 miimon=100 mode=1
[[email protected] network-scripts]# modprobe bonding
四、实验验证
[[email protected] network-scripts]# ip add show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether 00:0c:29:fa:56:68 brd ff:ff:ff:ff:ff:ff
3: eno33554992: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether 00:0c:29:fa:56:68 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 00:0c:29:fa:56:68 brd ff:ff:ff:ff:ff:ff
inet 172.25.254.200/24 brd 172.25.254.255 scope global bond0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fefa:5668/64 scope link
valid_lft forever preferred_lft forever
[[email protected] network-scripts]#
五、通过/proc/net/bonding/bond0进行查看模式以及网卡状态等信息
[[email protected] network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eno16777736 (primary_reselect always)
Currently Active Slave: eno16777736
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eno16777736
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fa:56:68
Slave queue ID: 0
Slave Interface: eno33554992
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fa:56:72
Slave queue ID: 0
[[email protected] network-scripts]#
六、当处于active的网卡宕掉后,slave网卡便会立即接应它的任务
[[email protected] ~]# ifconfig eno16777736 down
[[email protected] ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eno16777736 (primary_reselect always)
Currently Active Slave: eno33554992
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eno16777736
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fa:56:68
Slave queue ID: 0
Slave Interface: eno33554992
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fa:56:72
Slave queue ID: 0
[[email protected] ~]# ping baidu.com
PING baidu.com (180.149.132.47) 56(84) bytes of data.
64 bytes from 180.149.132.47: icmp_seq=1 ttl=128 time=39.4 ms
64 bytes from 180.149.132.47: icmp_seq=2 ttl=128 time=39.3 ms
64 bytes from 180.149.132.47: icmp_seq=3 ttl=128 time=39.2 ms
64 bytes from 180.149.132.47: icmp_seq=4 ttl=128 time=39.1 ms
64 bytes from 180.149.132.47: icmp_seq=5 ttl=128 time=40.0 ms