centos多網卡綁定(匯聚),實現冗餘和負載均衡

linux,bonding
from: http://hi.baidu.com/nan5715077/blog/item/0cedf2247c06ac2cd5074246.html
說明:
綁定多塊網卡爲一個虛擬ip,類似csico的etherchannel,實現冗餘或負載均衡和增加帶寬的功能。
內核需要bonding的支持,察看是否掛在bonding,lsmod命令。默認2.6內核中bonding已經被編譯爲M的選項,不需重新編譯內核。

其實Redhat關於bond,在kernel-doc裏有一篇文檔,講述得非常詳細,可以先看看/usr/share/doc/kernel-doc- 2.6.18/Documentation/networking/bonding.txt

一:不需重起的配置方法。
1 modprobe bonding miimon=100
2 ifconfig bond0 192.168.0.1 netmask 255.255.255.0
3 ifenslave bond0 eth0 eth1


二:重起仍然生效的配置方法一。
1關閉要綁定的物理網卡
修改ifcfg-eth0和ifcfg-eth1的啓動項

BOOTPROTO=none
ONBOOT=no

2建立虛擬網卡

在/etc/sysconfig/network-scripts/ 目錄下建立 ifcfg-bond0,並修改 /etc/modprobe.conf文件實現開機自動掛載。

/etc/sysconfig/network-scripts/ifcfg-bond0 配置如下:

DEVICE=bond0
IPADDR=192.168.0.193
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
GATEWAY=192.168.0.3

/etc/modprobe.conf 配置如下:
alias bond0 bonding
options bonding miimon=100 mode=0(miimon是用來進行鏈路監測的。
比如:miimon=100,那麼系統每100ms監測一次鏈路連接狀態,如果有一條線路不通就轉入另一條線路。模式1爲主備模式,模式0爲負載均衡與增加帶寬的模式)
注:以上爲只做一組bonding的方式,如果做多組的話可以更改爲以下的方式:
alias eth0 bnx2
alias eth1 bnx2
alias eth2 e1000
alias eth3 e1000
install bond0 /sbin/modprobe -a eth0 eth1 && /sbin/modprobe bonding
alias bond0 bonding
install bond1 /sbin/modprobe -a eth2 eth3 && /sbin/modprobe bonding
alias bond1 bonding
options bonding mode=0 miimon=100 max_bonds=2

最後執行測試, REBOOT確認bond0是否啓動,如果啓動,配置成功。


查看bonding狀態
cat /proc/net/bonding/bond0


三:重起仍然生效的配置方法二
1 vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.0.193
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
GATEWAY=192.168.0.3


2 vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes

3 vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes

4 vi /etc/modprobe.conf

alias bond0 bonding
options bonding miimon=100 mode=0

5 reboot




四: Linux 的 BONDING 模式

bonding 的應用分爲合併網卡提高帶寬與冗餘兩種功能。

在 linux kernel bonding 的 kernel module 內,可以依據傳入 mode=X 的方式來決定運行模式,其中數值可能結果依據官方文件說明如下:

mode=0 (balance-rr)

Round-robin policy: Transmit packets in sequential order from the first available
slave through the last. This mode provides load balancing and fault tolerance.

mode=1 (active-backup)

Active-backup policy: Only one slave in the bond is active. A different slave
becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port

(network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior

of this mode.

mode=2 (balance-xor)

XOR policy: Transmit based on [(source MAC address XOR'd with destination
MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load

balancing and fault tolerance.

所以可以依據實際需求決定要使用哪種模式來提供 bonding 功能。一般所謂合併與平衡負載功能部份,選擇 mode=0,而若是要達成 active-backup 架構的話,則選擇使用 mode=1 即可,注意,網卡需要支持mii-tool

設定配置文件, /etc/modprobe.conf 放置如下內容即可決定類型:

alias bond0 bonding
options bond0 miimon=100 mode=0

說明:miimon 是用來進行鏈路監測的。如果miimon=100,那麼系統每100ms 監測一次鏈路連接狀態,如果有一條線路不通就轉入另一條線路;mode 的值表 示工作模式,它共有0,1,2,3四種模式,常用的爲0,1兩種。
mode=0 表示load balancing (round-robin)爲負載均衡方式,兩塊網卡都工作。
mode=1 表示fault tolerance (active-backup)提供冗餘功能,工作方式是主備的工作方式,也就是說默認情況下只有一塊網卡工作,另一塊做備份。
max_bonds=2 表示最大的網卡綁定數量爲2。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章