Linux之Bonding
Linux 的 BONDING 設定使用
要使用 linux bonding 之前,前提當然是主機要有多張網路卡可以連結到實體的 SWITCH 上面,所以假定目前網路環境有兩張網路卡,系統已經驅動配置可以使用,那結果顯示如下:

要配置使用 bonding 功能,首先要掛入 bonding 的 kernel module:
# modprobe bonding miimon=100
其中 miimon 是提供 bonding module 要多久透過 MII 的介面檢查網路卡狀態,100 表示 100 milliseconds。
當掛入成功之後,執行 lsmod 可以查閱是否已經掛入,或者是執行 dmesg 也可以檢閱相關核心提示載入成功資訊。
當載入成功後,系統會建立 bond0 介面,如此即可配置該介面 IP:
# ifconfig bond0 192.168.1.1 netmask 255.255.255.0
完成 bond0 介面的 IP 配置後,後續要告訴系統哪幾個網路介面要綁入到bond0 介面,作法如下:
# ifconfig eth0 down
# ifconfig eth1 down
# ifenslave bond0 eth0 eth1
上面作法,也就是先先確認 eth0 與 eth1 網路介面關閉,然後將 eth0 與eth1 介面放入 bond0 內,告訴系統 bond0 是使用實體 eth0 與 eth1 網路卡提供該實際連結服務。
所以說,整個流程就是使用的命令操作如下:
# modprobe bonding
# ifconfig bond0 192.168.1.1 netmask 255.255.255.0
# ifconfig eth0 down
# ifconfig eth1 down
# ifenslave bond0 eth0 eth1

另外由於 Linux 目前已經逐漸使用 ip 工具取代了 ifconfig 與 route 等指令操作,所以原本上面使用 ifconfig 的指令,可以換成 ip 指令操作。下面也提供使用 ip 指令操作的方式。
# modprobe bonding miimon=100
# ip addr add 192.168.1.1/24 dev bond0
# ip link set eth0 down
# ip link set eth1 down
# ifenslave bond0 eth0 eth1
不過要注意到,這樣只有內部網路通了而已,一般還要配置 default gateway 才可以連結對外,所以不要忘記還要使用像是:
# route add default gw 192.168.1.254 dev bond0
或者是使用 ip route 取代 route 指令
# ip route add default via 192.168.1.254 dev bond0
Linux 的 BONDING 設定檔案
上面已經談完手動配置方式後,下面來談如何在 suse linux 上面設定每次開機都能夠自動完成該組態配置。
目前系統的 eth0 網路卡資訊與配置檔案如下:

而另外一張 eth1 網路卡資訊與配置檔案如下:

其中設定檔案名稱都是以 ifcfg-eth-id- 開頭的,後面接網路卡的卡號,所以檔案分別為 ifcfg-eth-id-00:0c:29:05:e1:d9 與ifcfg-eth-id-00:0c:29:05:e1:e3。這些檔案組成就是應對到 eth0 與 eth1 的設定,內容主要是設定如下:
BOOTPROTO=none
STARTUPMODE=off
也就是該介面開啟不要開啟,這樣才可以正常給 bond0 介面套入使用,所以整個結果就是:

後續要建立的就是 ifcfg-bond0 的介面設定檔案,還有配置掛入 bonding 的 kernel module,作法就是於 /etc/sysconfig/network/ 目錄建立 ifcfg-bond0,與修改 /etc/modprobe.conf 檔案達成該需求。
檔案項目,/etc/sysconfig/network/ifcfg-bond0 檔案內容如下:
IPADDR=192.168.1.1
NETMASK=255.255.255.0
BOOTPROTO=static
STARTUPMODE=onboot
BONDING_MASTER=br0
BONDING_SLAVE0=eth0
BONDING_SLAVE0=eth1
檔案項目,由於 /etc/modprobe.conf 會引入 /etc/modprobe.conf.local,所以直接於 /etc/modprobe.conf.local 放置如下內容:
aias bond0 bonding
都完成後,配置的結果如下:

若是要傳給 bonding module 的參數的話,通常可以在於該檔案加上:
options bonding miimon=100
最後測試方式,執行 /etc/init.d/network restart,或者是 rcnetwork restart,確認 bond0 介面是否起來,有的話就表示成功了。

Linux 的 BONDING 模式
前面有提到 bonding 的應用有區分合併 nic 頻寬與備援兩大種功能,剩下來談談這部份與 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 即可。
設定檔案配置,於 /etc/modprobe.conf.local 放置如下內容即可決定類型:
aias bond0 bonding
options bond0 miimon=100 mode=1
Next in This Category: Ubuntu 9.10 安裝USB網卡
學習筆記!!(1)

Sealed (Sep 5)
No one can comment