centos 7.6 双网卡绑定 bonding 实现 mod=1 activebackup 主备模式

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

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"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据库人生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值