2012年10月31日 星期三

(6) NIC bonding -- Debain GNU/Linux

Bonding on Debian

就Debian的設定而言,如果安裝了X window則預設會是以Network Manager來管理網路設定。本文專注在使用手動設定TCP/IP網路設定。

Bonding on Debian/Ubuntu

本文預設使用mode=6(也可以寫作mode=balance-alb)來作為範例,假設你要bond eth0, eth1兩張NIC到192.168.10.198/24:
  1. 安裝bonding介面卡管理程式:ifenslave
  2. aptitude install ifenslave-2.6 chkconfig -y
    ifenslave是製作bonding所必須的工具,因此務必確定他有被正確的安裝。
  3. 修改/etc/modprobe.d/aliases.conf
  4. 新增一行alias:
    alias bond0 bonding
    (備註) 在一些比較早期的版本裡可能需要寫在/etc/modprobe.conf。
  5. 關閉network-manager並啟動bonding:
  6. 相信在先前的章節你已經關閉了network-manager了...但是還是提醒一下就是了。有些人認為要刪除network-manager比較心安,就看個人意見了。
    service network-manager stop
    chkconfig network-manager off #aptitude remove network-manager
    modprobe bond0
  7. 修改/etc/network/interfaces:
  8. # The loopback network interface
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet manual
    bond-master bond0
    
    auto eth1
    iface eth1 inet manual
    bond-master bond0
    
    auto bond0
    iface bond0 inet static
     address 192.168.10.198
     netmask 255.255.255.0
     bond-slaves     eth0 eth1
     bond-mode       6
     bond-miimon     100
     bond-downdelay  200
     bond-updelay    200
    
    需注意此時在interfaces裡的eth0/eth1兩個bonding的slave都必須設定為manual並註明master是bond0。另外如果是早期的Ubuntu/Debian,其bond的設定可能如下:
    pre-up ifenslave bond0 eth0 eth1
    post-down ifenslave -d bond0 eth0 eth1

    這幾行設定在Ubuntu/Debian也適用,詳細考古文章可以參考Ubuntu Bonding合併網卡-Debian and ubuntu with a 2.6 kernel
  9. 重新啟動網路服務:
  10. /etc/init.d/networking restart
    如果沒有錯誤訊息的話,使用ip a指令來查看一切是否設定正確:
    maxsolar@Ubuntu1204-amd64:~$ ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP qlen 1000
        link/ether 84:34:97:11:00:d8 brd ff:ff:ff:ff:ff:ff
    3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP qlen 1000
        link/ether 84:34:97:11:00:d9 brd ff:ff:ff:ff:ff:ff
    4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
        link/ether 84:34:97:11:00:d8 brd ff:ff:ff:ff:ff:ff
        inet 192.168.10.198/24 brd 192.168.10.255 scope global bond0
        inet6 fe80::8634:97ff:fe11:d8/64 scope link 
           valid_lft forever preferred_lft forever
    我們可以發現此時bond0的MAC位置跟eth0相同,原因是現在Mode6(balance-alb)主要的slave是eth0。可以查看bonding狀態來求證:
    cat /proc/net/bonding/bond0
    看起來會是這個樣子:
    Bonding Mode: adaptive load balancing
    Primary Slave: None
    Currently Active Slave: eth0
    MII Status: up
    MII Polling Interval (ms): 100
    Up Delay (ms): 200
    Down Delay (ms): 200
    
    Slave Interface: eth0
    MII Status: up
    Speed: 1000 Mbps
    Duplex: full
    Link Failure Count: 0
    Permanent HW addr: 84:34:97:11:00:d8
    Slave queue ID: 0
    
    Slave Interface: eth1
    MII Status: up
    Speed: 1000 Mbps
    Duplex: full
    Link Failure Count: 0
    Permanent HW addr: 84:34:97:11:00:d9
    Slave queue ID: 0
    

當然你也可以把bonding設定為dhcp!很簡單吧!但是請記得bonding的裝置只能是實體裝置(不能是br0+br1或是bond0+bond1),也只能是同類型的網路界面(不能是eth0+wlan0)。

參考文章:

Share

沒有留言: