为了增加网络牢固性,linux服务器通过多块网卡来实现网卡冗余或链路聚合、负载均衡的技术。
网卡绑定mode共有七种(0~6) bond0、bond1、bond2、bond3、bond4、bond5、bond6
常用的有三种
mode=0:平衡负载模式,有自动备援,但需要”Switch”支援及设定。
mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。
mode=6:平衡负载模式,有自动备援,不必”Switch”支援及设定。
以mode=6为例,配置方法如下
1.在服务管理中关闭NetworkManager服务并禁用自动启动 #service NetworkManager status #查看状态 #service NetworkManager stop #停止服务 #chkconfig NetworkManager off #禁用服务,下次不自动启动 2.配置网卡 #cd /etc/sysconfig/network-scripts/ #cp ifcfg-eth0 ifcfg-bond0 #创建bond0
bond0配置
#su root #进入root用户下 #vi ifcfg-eth0 DEVICE=bond0 BOOTPROTO=none #不指定IP获取放松 ONBOOT=yes #随系统启动 IPADDR=192.168.0.100 NETMASK=255.255.255.0 NETWORK=192.168.0.0 BROADCAST=192.168.0.255 #:wq!
eth1和eth0配置
DEVICE=eth1BOOTPROTO=noneMASTER=bond0SLAVE=yes DEVICE=eth0BOOTPROTO=noneMASTER=bond0SLAVE=yes
3.修改modprobe相关设定文件,并加载bonding模块:
#vi /etc/modprobe.d/bonding.conf #追加 alias bond0 bonding options bonding mode=6 miimon=200 #mode选择6,检测时长200ms
保存退出
4.重启网络service network restart,或者重启系统 init 6
#su root #ifup bond0 #如果重启后没有启动,激活bond0 #ifconfig #查看是否启动 # ifconfig | grep HWaddr #查看运行状态
5.如果不能上网
# vi /etc/rc.d/rc.local #追加 ifenslave bond0 eth0 eth1 route add default gw 192.168.0.1 #增加默认网关
修改DNS
修改/etc/resolv.conf文件
# vi /etc/resolv.conf nameserver 8.8.8.8 #google域名服务器 nameserver 114.144.114.114 #国内域名服务器
#init 6
#常见错误
1.重启系统后ifcfg-bond0 配置出错“e=bond0″–修改为”DEVICE=bond0“
#注意事项
Bonding导致丢包严重问题:
(1)Bonding的mode设置不正确,使用mode=1,负载均衡模式,需要交换机的支持和配置;
(2)采用mode=6来进行负载均衡,不需要交换机的支撑;
Bonding导致网卡重启变化问题:
(1)配置过程中,没有设置具体的MAC地址,导致重启后网卡变化,从而导致bond发生错误;
(2)配置的过程中,一定记得备份文件,在发生错误的时候进行恢复;使用cpxy命令