Bonding的目的是爲提高系統可用性,防止物理網口或線路的單點故障
步驟1:檢查Linux環境是否支持bonding,執行如下命令
[root@compute ~]# modinfo bonding
filename: /lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/net/bonding/bonding.ko
author: Thomas Davis, [email protected] and many others
description: Ethernet Channel Bonding Driver, v3.6.0
version: 3.6.0
license: GPL
srcversion: 353B1DC123506708446C57B
depends: 8021q,ipv6
vermagic: 2.6.32-431.el6.x86_64 SMP mod_unload modversions
......(省略後面還有很多信息)
上面返回信息,有庫文件、版本、授權、描述等,表示支持bonding(假如沒有上面信息,可能重新安裝或編譯內核)
步驟2:檢查Linux下有沒有負載均衡的執行文件(負載均衡工具也就是bonding),執行如下命令
[root@compute ~]# which ifenslave
/sbin/ifenslave
步驟3:創建bonding驅動設備配置文件,執行如下命令
[root@compute ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 ifcfg-bond0
[root@compute ~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0 ---設備名稱(必要)
BOOTPROTO=static ---使用靜態IP地址(必要,或者=none也可以)
BROADCAST=192.168.1.255 ---(必要)
IPADDR=192.168.1.10 ---(必要)
NETMASK=255.255.255.0 ---(必要)
GATEWAY=192.168.1.254 ---(必要)
NETWORK=192.168.1.0
ONBOOT=yes ---引導時啓動(必要)
TYPE=Ethernet ---網線類型(可選,最好填上)
USERCTL=no ---USERCTL=no表明該設備只能由root用戶來控制(可選,最好填上)
步驟4:更改ifcfg-eth0網卡的屬性
[root@compute ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
#HWADDR=00:0E:1E:8D:9B:40 ---必須註銷,否則會引起bonding不正常
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0 ---MASTER=bond0表明eth0綁定到bond0設備上。
SLAVE=yes
USERCTL=no
步驟5:更改ifcfg-eth0網卡的屬性
[root@compute ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
#HWADDR=00:0E:1E:8D:9B:41 ---必須註銷,否則會引起bonding不正常
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0 ---MASTER=bond0表明eth0綁定到bond0設備上。
SLAVE=yes
USERCTL=no
以上步驟4、5是把網卡eth0和網卡eth1綁定在虛擬網卡bond0上,做網卡高可用
步驟6:編輯/etc/modprobe.d/bonding.conf文件,加入以下內容
[root@compute ~]# vi /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bond0 miimon=80 mode=0
說明:mode指定了bond0的工作模式(0-6種模式),常用的是0、1、6,0與6表示負載均衡方式,1表示主從方式,可根據需要自行配置。常用的爲0,1、6三種。
mode=0,表示load balancing (round-robin)爲負載均衡方式,兩塊網卡都工作,但是與網卡相連的交換機端口必須做特殊配置(這兩個端口應該採取聚合方式),因爲做bonding的這兩塊網卡是使用同一個MAC地址。
mode=1,表示fault-tolerance (active-backup)提供冗餘功能,工作方式是主備的工作方式,也就是說默認情況下只有一塊網卡工作,另一塊做備份。bonding只能提供鏈路監測,即從主機到交換機的鏈路是否接通。如果只是交換機對外的鏈路down掉了,而交換機本身並沒有故障,那麼bonding會認爲鏈路沒有問題而繼續使用。 miimon是用來進行鏈路監測的。比如:miimon=80,那麼系統每100ms監測一次鏈路連接狀態,如果有一條線路不通就轉入另一條線路。
mode=6,表示load balancing (round-robin)爲負載均衡方式,兩塊網卡都工作,但是該模式下無需配置交換機,因爲做bonding的這兩塊網卡是使用不同的MAC地址
步驟7:加入/etc/rc.d/rc.local 啓動項 (可選)
[root@compute ~]# vi /etc/rc.d/rc.local
ifenslave bond0 eth0 eth1 ----在最後面加入此條命令
步驟8:重啓網絡
[root@compute ~]# service network restart
步驟9:檢查bonding狀態信息
[root@compute12 ~]# more /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 80
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: a8:3a:72:ce:8a:9c
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: a8:3a:72:ce:7a:9d
Slave queue ID: 0
步驟10. 完成後重啓系統,ping 192.168.1.254測試
注意:
1.所有ethxx配置的時候去掉MAC地址;
2.必須徹底關閉NetworkManger服務,否則會和bond網上衝突
- - >service NetworkManger stop
- - >chkconfig NetworkManger off
3.RHEL 6X版本的配“/etc/modprobe.d/”文件下面自己手動新建“bonding.conf”
4.多個bonging文件配置模式一致,例如:
[root@compute modprobe.d]# cat bonding.conf
alias bond0 bonding
alias bond1 bonding
options bond0 miimon=80 mode=0
options bond1 miimon=80 mode=0
註明:以上含“(必要)”是必須要有內容,“(可選)”是可以填上或不填上都行