G9安装centos7.2做网卡绑定

问题

网卡绑定遇到一张网卡切换慢,5分钟才能恢复网络访问。查询相关文章后总算解决

解决过程

解决方法为绑定参数添加arp_interval=1000 arp_ip_target=gw,设置定时去ping网关。
网卡绑定脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#关闭防火墙,网卡管理软件,selinux
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
#检查并加载bond模块到内核
modprobe bonding
lsmod | grep bonding
cd /etc/sysconfig/network-scripts/
cp ifcfg-eno50 bak_ifcfg-eno50
cp ifcfg-ens1f1 bak_ifcfg-ens1f1
cat > /etc/sysconfig/network-scripts/ifcfg-bond_prod <<EOF
DEVICE=bond_prod
BOOTPROTO=static
TYPE=Bond
BONDING_MASTER=yes
ONBOOT=yes
IPADDR=$1
NETMASK=gw
GATEWAY=gw
USERCTL=no
BONDING_OPTS="mode=1 miimon=100 arp_interval=1000 arp_ip_target=gw"
EOF
cat >/etc/sysconfig/network-scripts/ifcfg-eno50<<EOF
DEVICE=eno50
BOOTPROTO=none
ONBOOT=yes
MASTER=bond_prod
SLAVE=yes
USERCTL=no
EOF
cat >/etc/sysconfig/network-scripts/ifcfg-ens1f1<<EOF
DEVICE=ens1f1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond_prod
SLAVE=yes
USERCTL=no
EOF
service network restart
cat /proc/net/bonding/bond_prod

执行ansible -i hosts-28 ip -m script -a 'bond-hp-DL380.sh ip'

参考资料

https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s3-modules-bonding-directives.html
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/sec-network_configuration_using_sysconfig_files