os: centos 7.6
bonding 有 0-6 七种模式
第一种模式:mod=0,即:(balance-rr)Round-robin policy(平衡抡循环策略)交换机配置Eth-Trunk
第二种模式:mod=1,即:(active-backup)Active-backup policy(主-备份策略)
第三种模式:mod=2,即:(balance-xor)XOR policy(平衡策略)
第四种模式:mod=3,即:broadcast(广播策略)
第五种模式:mod=4,即:(802.3ad)IEEE 802.3ad Dynamic link aggregation(IEEE802.3ad 动态链接聚合)
第六种模式:mod=5,即:(balance-tlb)Adaptive transmit load balancing(适配器传输负载均衡)
第七种模式:mod=6,即:(balance-alb)Adaptive load balancing(适配器适应性负载均衡)
本次使用 bonding 的工作方式为 1
centos 7 默认是不加载bonding模块的
# systemctl stop NetworkManager;
systemctl disable NetworkManager;
# vi /etc/modprobe.d/bond.conf
alias bond0 bonding
options bond0 miimon=200 mode=1
# lsmod | grep bonding
# modprobe bonding
# modinfo -F filename bonding
filename /lib/modules/3.10.0-957.27.2.el7.x86_64/kernel/drivers/net/bonding/bonding.ko.xz
配置系统启动时加载bonding模块
# vim /etc/sysconfig/modules/bonding.modules
#!/usr/bin/bash
/usr/sbin/modinfo -F filename bonding > /dev/null 2>&1
if [ $? -eq 0 ];then
/usr/sbin/modprobe bonding
fi
设置执行权限
# chmod 755 /etc/sysconfig/modules/bonding.modules
物理网卡 enp0s8
# cp /etc/sysconfig/network-scripts/ifcfg-enp0s8 /etc/sysconfig/network-scripts/ifcfg-enp0s8.bak
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
TYPE=Ethernet
DEVICE=enp0s8
BOOTPROTO=none
USERCTL=no
ONBOOT=yes
NAME=enp0s8
MASTER=bond0
SLAVE=yes
物理网卡 enp0s9
# cp /etc/sysconfig/network-scripts/ifcfg-enp0s9 /etc/sysconfig/network-scripts/ifcfg-enp0s9.bak
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s9
TYPE=Ethernet
DEVICE=enp0s9
BOOTPROTO=none
USERCTL=no
ONBOOT=yes
NAME=enp0s9
MASTER=bond0
SLAVE=yes
bond0 配置文件
# cp /etc/sysconfig/network-scripts/ifcfg-bond0 /etc/sysconfig/network-scripts/ifcfg-bond0.bak
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Bond
#TYPE=Ethernet
DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
USERCTL=no
NM_CONTROLLED=no
BONDING_MASTER=yes
BONDING_OPTS="fail_over_mac=1 miimon=200 mode=1"
NAME=bond0
IPADDR=192.168.56.119
PREFIX=24
NETMASK=255.255.255.0
GATEWAY=192.168.56.1
重启network服务,并检查
# systemctl restart network;
查看 bonding 信息
# cat /proc/net/bonding/bond0;
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: enp0s8
MII Status: up
MII Polling Interval (ms): 200
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: enp0s8
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:dd:ce:b1
Slave queue ID: 0
Slave Interface: enp0s9
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:74:1a:f4
Slave queue ID: 0
打开一个窗口一直 ping
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.119 的回复: 字节=32 时间<1ms TTL=64
vmware 移除虚拟机的网卡 enp0s8
# cat /proc/net/bonding/bond0;
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: enp0s9
MII Status: up
MII Polling Interval (ms): 200
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: enp0s8
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 08:00:27:dd:ce:b1
Slave queue ID: 0
Slave Interface: enp0s9
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:74:1a:f4
Slave queue ID: 0
显示 Currently Active Slave: enp0s9
已经由 enp0s8 切换到 enp0s9 了.
参考:
https://wiki.centos.org/zh/Manuals/ReleaseNotes/CentOS7.1810?action=show&redirect=zh%2FManuals%2FReleaseNotes%2FCentOS7
切换
# rpm -qf `which ifenslave`
# rpm -qa |grep -i iputils
# ifenslave -c bond0 enp0s9
BONDING_OPTS 选项
BONDING_OPTS="resend_igmp=1 updelay=0 use_carrier=1 miimon=100 downdelay=0 xmit_hash_policy=0 primary_reselect=0 fail_over_mac=0 arp_validate=0 mode=balance-alb arp_interval=0 ad_select=0"