To be a better coder
分类: LINUX
2019-03-27 14:49:59
Linux bonding 主备模式slave网卡切换的方法
我们有时候做演练或测试,测试bonding slave网卡切换,或者疑是因为一块网卡有问题,想切换到另外一块slave网卡,通常情况下,我们可能采用ifdown eth0或ifconfig eth0 down的方法来切换到另外一块网卡,但是这种方法在 生产环境中可能出现网络及系统告警或者可能丢包,也可能也存在一些风险。
下面介绍一种方法,不需要ifdown网卡就能切换,比较适合于在生产环境中正在提供业务的linux服务器,比如出现了丢包,或者有闪断、网络慢或者日志有网络报错,怀疑是此网卡硬件或固件有问题,想切换到另外一块slave网卡,而又不想断网出现监控系统告警,业务中断等对业务高可用要求比较高的情况。
# ifenslave -c bond0 eth1 将一个物理接口eth1作为active接口
不建议# ifenslave -d bond0 eth0 //从bond0中删除掉eth0
如下所示(适用于主备模式)
[root@ ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:5a:9d:28
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:5a:9d:32
Slave queue ID: 0
[root@redhat ~]# ifenslave -c bond0 eth1
[root@redhat ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:5a:9d:28
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:5a:9d:32
Slave queue ID: 0
[root@redhat ~]#
整个过程没有出现丢包,断网