1.檢查你的系統是否支援bonding
首先,執行命令:
$rpm -qf /sbin/ifup
它會返回一行文本,以“initscripts”或"sysconfig"開頭,他是提供網路初始化指令碼的包。
下一步,為了確定你的安裝是否支援bonding,執行命令:
$grep ifenslave /sbin/ifup
如果返回任何匹配記錄,則表示你的initscripts 或sysconfig 支援bonding
2.修改網路介面卡的配置
針對現在的網路介面卡設定檔進行修改,設定檔都放在/etc/sysconfig/network-scripts目錄下,如下:
第一個網路介面卡:
vim /etc/sysconfig/network-scripts/eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
第二個網路介面卡:
vim /etc/sysconfig/network-scripts/eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
3.建立bonding的網路指令碼
vim /etc/sysconfig/network-scripts/bond0
DEVICE=bond0
IPADDR=192.168.1.66
NETMASK=255.255.255.0
NETWORK=192.168.1.0
BROADCAST=192.168.1.255
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
4.bond驅動的選項
bonding驅動的選項是通過在載入時制定參數來設定的,通常在以下兩個檔案裡面指定。
編輯/etc/modprobe.conf,添加以下兩行:
alias bond0 bonding
options bond0 mode=1 million=100
說明:
mode指定了bond0的工作模式,常用的是0和1,0表示負載平衡方式,1表示主從方式,可根據需要自行配置。常用的為0,1兩種。mode=0表示 load balancing (round-robin)為負載平衡方式,兩塊網卡都工作。mode=1表示fault-tolerance (active-backup)提供冗餘功能,工作方式是主備的工作方式,也就是說預設情況下只有一塊網卡工作,另一塊做備份。bonding只能提供鏈路監測,即從主機到交換器的鏈路是否接通。如果只是交換器對外的鏈路down掉了,而交換器本身並沒有故障,那麼bonding會認為鏈路沒有問題而繼續使用。 miimon是用來進行鏈路監測的。比如:miimon=100,那麼系統每100ms監測一次鏈路串連狀態,如果有一條線路不通就轉入另一條線路。
5.啟用bonding
#service network restart
6.測試
cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v2.6.3-rh (June 8, 2005)
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 Link Failure Count: 0
Permanent HW addr: 00:0c:29:6e:40:9d
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6e:40:a7
如果這時把eth0串連的網線拔掉,eth1會接替變成active
Currently Active Slave: eth0
Slave Interface: eth0
MII Status: down
Slave Interface: eth1
MII Status: up
表明bonding的模式1,是一種主備HA的模式。
Ethernet Channel Bonding Driver: v2.6.3-rh (June 8, 2005)
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
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6e:40:9d
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6e:40:a7
如果這時把
eth0
串連的網線拔掉,
eth1
會接替變成
active
Currently Active Slave: eth0
Slave Interface: eth0
MII Status: down
Slave Interface: eth1
MII Status: up
表明
bonding
的模式
1
,是一種主備
HA
的模式。
Ethernet Channel Bonding Driver: v2.6.3-rh (June 8, 2005)
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
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6e:40:9d
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:6e:40:a7
如果這時把
eth0
串連的網線拔掉,
eth1
會接替變成
active
Currently Active Slave: eth0
Slave Interface: eth0
MII Status: down
Slave Interface: eth1
MII Status: up
表明
bonding
的模式
1
,是一種主備
HA
的模式。