牛骨文教育服务平台(让学习变的简单)
<span><span>环境:RHEL6.5+Virtual Box</span></span>
1.确定Linux是否支持bonding
[root@lmsin ~]# modinfo bonding
返回bonding信息,表示支持,空白,就是不支持。不支持,需要重新编译内核(???)
2.检查ifenslave工具是否存在
[root@lmsin ~]# which ifenslave
/sbin/ifenslav
如果没有,需要单独编译出来(??)
下面将eth0和eth1网卡设备绑定为一个网卡,绑定名称为bond0
3.创建/etc/sysconfig/network-scripts/ifcfg-bond0文件,加入以下代码:
[root@lmsin ~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=186.168.100.112
NETMASK=255.255.255.0
IPV6INIT=no
USERCTL=no  #this device is controled only by root
GATEWAY=186.168.100.1
4.更改/etc/sysconfig/network/network-scripts/ifcfg-eth0网卡配置文件的内容:
[root@lmsin ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0  #imply the eth0 bond to bond0
SLAVE=yes
USERCTL=no
5.更改/etc/sysconfig/network/network-scripts/ifcfg-eth1网卡配置文件的内容:
[root@lmsin ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0  #imply the eth0 bond to bond0
SLAVE=yes
USERCTL=no
6.编辑/etc/modprobe.conf文件,加入以下内容:
[root@lmsin ~]# vi /etc/modprobe.conf
#20150914  added by liming testing bonding
alias bond0 bonding
options bond0 miimon=100 mode=1
miimon是用来进行链路检测的。例如miimon=100,表示系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路。mode的值表示工作模式,共有0、1、2、3四中,常用的为0、1两种:
mode=0表示load balancing(round-robin)为负载均衡方式,两个网卡都工作。如果有一个网卡不能正常工作,整个绑定通信将不能正常工作。
mode=1表示fault-tolerance(active-backup)提供冗余功能,采用主备工作方式,也就是说默认情况下只有一个网卡工作,另一个做备份。当一个网卡运行失败,Linux会自动切换到另一个网卡上继续工作。

注:如果需要做成负载均衡,仅仅设置options bond0 miimon=100 mode=0是不够的,还需要交换机支持相应的功能。
7.绑定检查:
[root@lmsin ~]# service network restart
[root@lmsin ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:d1:89:0d
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:b5:d9:aa
Slave queue ID: 0