星期二, 二月 07, 2012

RHEL 5.4 network bonding

http://tosian.blogspot.com/2009/05/linux-channel-bonding.html
網路上這篇文章已經說明得非常清楚了,不過針對自己使用上遇到的問題做點補充。

根據該篇文章,設定網卡bonding需要幾個步驟:
1. 新增一張 ifcfg-bond0 設定
2. 修改 ifcfg-eth0 設定
3. 修改 ifcfg-eth1 設定
4. 修改 /etc/modprobe.conf 設定
5. 我們可以從 /proc/net/bonding/bond0 這個檔案瞭解目前設定的情況

不過在使用上,卻遇到 modprobe.conf 裡面的設定 mode=1 (或是 mode=active-backup)是沒有效果的,結果就是設定會採用預設的Round-Robin,而不是Active-backup。這個情況造成要配合Switch設定的網卡bonding有問題,而出現 network flapping ,network flapping 會造成switch cpu飆高以及網路流量負載變重的結果。
解決方式為,在 ifcfg-bond0 的設定中,可以加入 BONDING_MODULE_OPTS="mode=active-backup miimon=100" 這個設定,設定完成並且重啟網路卡以後,就可以在  /proc/net/bonding/bond0  檔案裡面看到,我們採用的是 Active-backup 而不再是 Round-Robin 。

文末附上各個檔案的設定:
ifcfg-bond0
---------------
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETWORK=10.0.0.0
NETMASK=255.255.255.0
IPADDR=10.0.0.1
USERCTL=no
BONDING_MODULE_OPTS="mode=active-backup miimon=100"
=======================
ifcfg-eth0
---------------
DEVICE=eth0
BOOTPROTO=none
HWADDR=xx:xx:xx:xx:xx:xx
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
=======================
ifcfg-eth1
---------------
DEVICE=eth1
BOOTPROTO=none
HWADDR=xx:xx:xx:xx:xx:xx
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
=======================
modprobe.conf
---------------
alias eth0 bnx2
alias eth1 bnx2
alias scsi_hostadapter megaraid_sas
alias scsi_hostadapter1 ata_piix
alias bond0 bonding
options bond0 miimon=100 mode=1 Primary=eth0
=======================
最後是 /proc/net/bonding/bond0
---------------
Bonding Mode: load balancing (Active-backup)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xx

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xx

參考網頁:
http://www.linuxfoundation.org/collaborate/workgroups/networking/bonding
http://tosian.blogspot.com/2009/05/linux-channel-bonding.html