Linux的多网卡绑定

加载bonding模块,options里的一些参数的含义:
miimon 监视网络链接的频度,单位是毫秒。
max_bonds 配置的bond口个数
mode bond模式,在一般的实际应用中,0和1用的比较多。

bond模式:常用的有三种
mode=0:平衡负载模式,有自动备援,但需要”Switch”支援及设定。多个网卡使用一个MAC。
mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。主备模式
mode=6:平衡负载模式,有自动备援,不必”Switch”支援及设定。多个网卡使用不同的MAC。

Linux网口绑定案例:
2个物理网口分别是:eth0,eth1
绑定后的虚拟口是:bond0
服务器IP是:192.168.0.100
1、创建/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
IPADDR=192.168.0.100
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
USERCTL=no
ONBOOT=yes
TYPE=Ethernet
注意:建议不要指定MAC地址
2、修改/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
注意:建议不要指定MAC地址
3、修改/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
注意:建议不要指定MAC地址
第二步,修改modprobe相关设定文件,并加载bonding模块:
1.修改/etc/modprobe.d/dist.conf
[root@test ~]# vi /etc/modprobe.d/dist.conf
#追加
alias bond0 bonding
options bond0 miimon=100 mode=0
(mode=0,表示平衡负载双网卡工作,RR算法,mode=1,自动主备,其中一块工作)
(miimon=100,miimon是指多久时间要检查网路一次,单位是ms(毫秒) ,意思是假设其中有一条网路断线,会在0.1秒内自动备援)
第三步,重启一下网络,然后确认一下状况:
[root@test ~]# /etc/init.d/network restart
[root@test ~]# cat /proc/net/bonding/bond0
 [root@test ~]# ifconfig | grep HWaddr
任意拔掉一根网线,然后再访问你的服务器,看网络是否还是通的。
第四步,系统启动自动绑定、增加默认网关:
[root@test ~]# vi /etc/rc.d/rc.local
#追加
ifenslave bond0 eth0 eth1
route add default gw 192.168.0.1 #如果已在上面三个端口配置网关,可以不配置
-----------------------------------------------------------------------------------------------------------

注意:前面只是2个网口绑定成一个bond0的情况,如果设置多个bond口,比eth0和eth1组成bond0,eth2和eth3组成bond1,
那么/etc/modprobe.d/bonding.conf的配置需要变化,正确的设置方法有2种:
第一种,多个bond口的模式设成相同的:
alias bond0 bonding
alias bond1 bonding
options bonding max_bonds=2 miimon=200 mode=1
第二种,不同的bond口的mode设成不一样:
alias bond0 bonding
options bond0 miimon=100 mode=1
install bond1 /sbin/modprobe bonding -o bond1 miimon=200 mode=0

猜你喜欢

转载自blog.csdn.net/maopc1987/article/details/85232402