Bonding

Bonding是個好用的工具,怎麼說呢?因為他可以讓你的雙網卡互相備援、或是發揮最大效應。
會去研究bonding,其實是因為看到市售的NAS主打Link aggregation,讓我看的心癢養,研究後發現原來就是bonding阿,且要達成Link aggregation的話,還得要switch支援才可以,但若是使用bonding的其餘方法,就可以達到類似結果,且不需要switch支援802.3ad的協定。
bonding有哪些模式呢?總共有七種,分別是:

  1. 模式0:循環負載平衡合併頻寬(Round-robin policy, balance-rr)
  2. 模式1:自動備援模式(Active-backup policy, active-backup)
  3. 模式2:負載平衡與容錯功能(XOR policy, balance-xor)
  4. 模式3:廣播模式(Broadcast policy, broadcast)
  5. 模式4:LACP 鏈路聚合模式(IEEE 802.3ad Dynamic link aggregation, 802.3ad)
  6. 模式5:自動調整傳輸負載平衡(Adaptive transmit load balancing, balance-tlb)
  7. 模式6:自動調整全負載平衡(Adaptive load balancing, balance-alb)

比較常用的應該是0、1、5、7吧!詳細的介紹這邊就不贅述了。

首先先確定網卡有無支援bonding,可使用

#mii-tool

或是

#ethtool ethx

看看是否出現

eth0: negotiated 1000baseT-FD flow-control, link ok

Link detected:OK。

接下來建立bonding模組

#vim /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bonding mode=6 miimon=100

然後修改interfaces檔案

#vim /etc/netwotk/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

#auto eth1
#iface eth1 inet dhcp

# PPPoE connection
#auto provider
#iface provider inet ppp
# pre-up /sbin/ifconfig eth0 up
# provider provider

auto bond0
iface bond0 inet dhcp
bond-slaves eth2 eth3
bond-mode 6
bond-miimon 100

allow-hotplug eth2 eth3
auto eth2
iface eth2 inet manual
bond-master bond0
#post-up iptables-restore < /etc/iptables.up.rules

auto eth3
iface eth3 inet manual
bond-master bond0

接下來重新啟動網路後,應該就可以看到bond0出現了,很簡單吧!(但當初我被搞超久的,因為網路上大家都會加入bond-downdelay 200 bond-updelay 200這兩行,但我加了之後都會有問題,不知道為何,拿掉後就OK了。)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料