~~~
<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
~~~