CentOS 双网卡绑定

admin2015-12-01linux126
 jhj 准备工作:一定要在服务管理中关闭NetworkManager服务并禁用自动启动。
service NetworkManager stop
chkconfig NetworkManeger off
第一步:创建绑定网卡ifcfg-bond0并配置
[root@root network-scripts]# vim ifcfg-bond0    //(IP、MASK、子网掩码按服务器配置来)
BOOTPROTO=none
DEVICE=bond0
ONBOOT=yes
IPADDR=192.168.10.101
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
USERCTL=no
TYPE=Ethernet
IPV6INIT=no
第二步:修改2个实际网卡的配置 重点的配置在 MASTER=bond0 //创建绑定网卡的名称 SLAVE=yes //开启salve模式
[root@root network-scripts]# vim ifcfg-eth0
BOOTPROTO=none
DEVICE=eth0
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
TYPE=Ethernet
IPV6INIT=no
[root@root network-scripts]# vim ifcfg-eth1
BOOTPROTO=none
DEVICE=eth1
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
TYPE=Ethernet
IPV6INIT=no
  第三步:开启绑定网卡模块 这里mode=1是配合2台交换机做了双活
[root@root ~]# vi /etc/modprobe.d/dist.conf
//加载bonding模块,对外虚拟网络接口设备为bond0,在最后加入以下2行
alias bond0 bonding
options bond0 mode=1 miimon=100
  说明:(这个是上网抄的,自己最好了解下) miimon是用来进行链路监测的。比如:miimon=100,单位是ms(毫秒)这边的100,是100ms,即是0.1秒那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0、1两种。 mode共有七种(0~6),这里解释两个常用的选项。 mode=0:表示load balancing (round-robin)为负载均衡方式,两块网卡都在工作。 mode=1:表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,其中一块网卡在工作(若eth0断掉),则自动切换到另一个块网卡(eth1做备份)。 bonding只能提供链路监测,即从主机到交换机的链路是否接通。如果只是交换机对外的链路down掉了,而交换机本身并没有故障,那么bonding会认为链路没有问题而继续使用。 第四步:重启网络服务,使配置生效
[root@root network-scripts]# service network restart
第五步:验证是否双网卡绑定成功
[root@root network-scripts]# cat /proc/net/bonding/bond0
  可以看到主网卡是eth1,如果把eth1网线拔掉自动切换为eth2 Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eth1      // eth1主模式 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0   Slave Interface: em1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:c9:6d:18 Slave queue ID: 0   Slave Interface: em2 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:c9:6d:22 Slave queue ID: 0