为了提供网络的高可用性,我们可能需要将多块网卡绑定成一块虚拟网卡对外提供服务,这样即使其中的一块物理网卡出现故障,也不会导致连接中断。比如我们能够将eth0和eth1绑定成虚拟网卡bond0
1. 首先在/etc/sysconfig/network-scripts/下创建虚拟网卡bond0的配置文档ifcfg-bond0,内容如下
DEVICE=bond0
BOOTPROTO=static
BONDING_OPTS="mode=1 miimon=500"
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.0.125
USERCTL=no
mode=0代表负载均衡模式(round-robin),mode=1代表热备模式。
可以通过:cat /proc/net/bonding/bond0查看。
miimon=500代表每500ms检查一次网卡是否active
2. 然后分别修改eth0和eth1的配置文件
ifcfg-eth0内容:
DEVICE=eth0
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
ONBOOT=yes
USERCTL=no
ifcfg-eth1内容:
DEVICE=eth1
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
ONBOOT=yes
USERCTL=no
3. 编辑 /etc/modules.conf 文件,加入如下内容,以使系统在启动时加载bonding模块,对外虚拟网络接口设备为 bond0:
alias bond0 bonding
4.vi /etc/rc.local
加入 ifenslave bond0 eth0 eth1 eth2
5. vi /etc/modules.conf
加入 alias net-pf-lo off
alias ipv6 off
最后可以通过 cat /proc/net/bonding/bond0 查看bond信息