现状:
目前一台物理机4个网卡,em1-em2-em3-em4,需要实现1、2网卡绑定,3、4网卡绑定,模式为主备。即:一个网卡处于活动状态 ,一个处于备份状态,所有流量都在主链路上处理。当活动网卡down掉时,启用备份的网卡
附:linux有七种网卡绑定模式:0. round robin,1.active-backup,2.load balancing (xor), 3.fault-tolerance (broadcast), 4.lacp, 5.transmit load balancing, 6.adaptive load balancing。
自动化脚本如下:function init_em() {
cat>/etc/sysconfig/network-scripts/ifcfg-em1<
DEVICE=em1
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
EOF
cat>/etc/sysconfig/network-scripts/ifcfg-em2<
DEVICE=em2
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
EOF
cat>/etc/sysconfig/network-scripts/ifcfg-em3<
DEVICE=em3
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond1
SLAVE=yes
USERCTL=no
EOF
cat>/etc/sysconfig/network-scripts/ifcfg-em4<
DEVICE=em4
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond1
SLAVE=yes
USERCTL=no
EOF
}
function init_bond() {
cat>/etc/sysconfig/network-scripts/ifcfg-bond0<
DEVICE=bond0
TYPE=Ethernet
BOOTPROTO=static
ONBOOT=yes
IPADDR=$1
NETMASK=255.255.255.224
GATEWAY=27.111.176.33
USERCTL=no
EOF
cat>/etc/sysconfig/network-scripts/ifcfg-bond1<
DEVICE=bond1
TYPE=Ethernet
BOOTPROTO=static
ONBOOT=yes
IPADDR=$2
NETMASK=255.255.252.0
USERCTL=no
EOF
}
function init_other() {
cat>>/etc/modprobe.d/dist.conf<
# active bonding configuration
alias bond0 bonding
alias bond1 bonding
options bond0 mode=1 miimon=100 fail_over_mac=1
options bond1 mode=1 miimon=100 fail_over_mac=1
EOF
}
function init_dns() {
cat>/etc/resolv.conf<
; generated by /sbin/dhclient-script
nameserver 8.8.8.8
nameserver 4.4.4.4
options attempts:1 timeout:1
search localhost
EOF
}
if [ $# -ne 3 ]
then
echo "args: sh a.sh Publick_IP Native_IP HOSTNAME"
exit 1
fi
init_bond $1 $2
init_em
init_other
init_dns
原文:http://jishuweiwang.blog.51cto.com/6977090/1897558