Squeezeでアクティブ/バックアップモードのbonding(teaming)を設定す

■「ifenslave-2.6」の導入

$ apt-cache search ifenslave
ifenslave-2.6 - Attach and detach slave interfaces to a bonding device
$ sudo apt-get install -y ifenslave-2.6

■カーネルモジュールの読み込み

$ sudo modprobe bonding
$ lsmod | grep bonding
bonding                73991  0
$ echo "bonding" | sudo tee -a /etc/modules
$ cat /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

loop
8021q
bonding

■wifi以外のサンプルを確認。

$ find /usr/share/doc/ifenslave-2.6/examples/ -type f ! -iname "*wifi*" -print | \
  grep . `xargs` | sed s%".*/"%%g
two_ethernet:A simple configuration with two ethernet (wire) interfaces.
two_ethernet:-----8<----------8<----------8<----------8<----------8<-----
two_ethernet:auto bond0
two_ethernet:iface bond0 inet dhcp
two_ethernet:   bond-slaves eth0 eth1
two_ethernet:   bond-mode 1
two_ethernet:   bond-miimon 100
two_ethernet:   bond-primary eth0 eth1
two_ethernet:-----8<----------8<----------8<----------8<----------8<-----
two_ethernet:You do not need an "iface eth0" nor an "iface eth1" stanza.
two_hotplug_ethernet:A configuration with two hotplug ethernet (wire) interfaces.
two_hotplug_ethernet:-----8<----------8<----------8<----------8<----------8<-----
two_hotplug_ethernet:auto bond0
two_hotplug_ethernet:iface bond0 inet dhcp
two_hotplug_ethernet:   bond-slaves none
two_hotplug_ethernet:   bond-mode 1
two_hotplug_ethernet:   bond-miimon 100
two_hotplug_ethernet:allow-hotplug eth0
two_hotplug_ethernet:iface eth0 inet manual
two_hotplug_ethernet:   bond-master bond0
two_hotplug_ethernet:   bond-primary eth0 eth1
two_hotplug_ethernet:allow-hotplug eth1
two_hotplug_ethernet:iface eth0 inet manual
two_hotplug_ethernet:   bond-master bond0
two_hotplug_ethernet:   bond-primary eth0 eth1
two_hotplug_ethernet:-----8<----------8<----------8<----------8<----------8<-----
two_hotplug_ethernet:The "auto bond0" stanza is required, else bond0 won’t bring up.

■Lenny用の設定を参考にしながら。

 Bonding(debian wiki)
 http://wiki.debian.org/Bonding

■Wikiにある、以下のようなbondingの警告ログがでる分は対処します。

$ sudo grep 'bonding: Warning' /var/log/syslog | sed s/".*bonding\: "//g | sort -u | sed s/",\|\!"/"&\n"/g
Warning: either miimon or arp_interval and arp_ip_target module parameters must be specified,
 otherwise bonding will not detect link failures!
 see bonding.txt for details.

■Wikiにある「options」行は「ineterfaces」で設定するのでここでは行わない。
 が、「bond0」のエイリアスだけは行っておく。

$ echo "alias bond0 bonding" | \
  sudo tee -a /etc/modprobe.d/aliases-bond.conf
alias bond0 bonding

■おまけ(WOL設定の確認)

 第1回 節電のためにWake-On-Lanを使う
 http://thinkit.co.jp/story/2011/07/05/2188?page=0,1

$ sudo ethtool eth0 | grep Wake
        Supports Wake-on: g
        Wake-on: g

$ sudo ethtool eth1 | grep Wake
        Supports Wake-on: pumbg
        Wake-on: g

■「two_ethernet」をベースに設定。DHCPは無効でしょうw。。。
 「examples」にあるように、eth0/eth1の双方がスレーブ。
 プライマリも理由がない限り、双方にしておく方が無難。

 ※「ethernet-wol」の設定は不要、むしろ設定するとWOL起動できなかったのでコメントアウト。
  設定なしでWOL起動した。確認は「ethtool」の通り。

$ grep -v "^#\|^\$" /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet manual
	 #ethernet-wol g
iface eth1 inet manual
auto bond0
iface bond0 inet static
address 192.168.188.88
netmask 255.255.255.0
gateway 192.168.188.1
broadcast 192.168.188.255
        bond-slaves eth0 eth1
        bond-mode 1
        bond-miimon 100
        arp_interval 2000
        arp_ip_target 192.168.11.254
        bond-downdelay 200
        bond-updelay 200
        #bond-primary eth0 eth1

■初回設定時はeth0をオフ後iniスクリプトの再起動
 ※eth0でネットワーク経由で操作しているならばシステムの再起動
  再起動後からはinitスクリプトの再起動でよい。

$ sudo ifconfig eth0 down && sudo /etc/init.d/networking restart
$ sudo shutdown -r now

$ sudo /etc/init.d/networking restart


■以下のように設定が反映されていることを確認。
 「Link Failure Count」が0であること。

$ cat /proc/net/bonding/bond0 | sed s/"\(Permanent HW addr: \).*"/"\1[MAC Address]"/g
Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth0
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
Link Failure Count: 0
Permanent HW addr: [MAC Address]

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: [MAC Address]

■アクティブバックアップモードの確認

$ cat /sys/class/net/bond0/bonding/mode
active-backup 1

■MACアドレスは1種類のみ(eth0のもの)。
 [MAC Address] bond0 = eth0 = eth1 

$ env LANG=C /sbin/ifconfig | grep HWaddr | grep "bond0\|eth0\|eth1" | awk '{print $5}' | sort -u | wc -l
1

■RX/TXのエラーやコリジョンが無いこと。

$ env LANG=C /sbin/ifconfig bond0 | \
  grep -v inet6 | sed s/"\(HWaddr \).*\$"/"\1XX:XX:XX:XX:XX:XX:XX"/
bond0     Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX:XX
          inet addr:192.168.188.88  Bcast:192.168.188.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:4263 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3460 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:655666 (640.2 KiB)  TX bytes:708936 (692.3 KiB)

■eth0をアクティブにする。

$ sudo ifenslave -c bond0 eth0;sudo grep bonding /var/log/syslog | tail -1 | sed s/".*bonding\: "//
bond0: making interface eth0 the new active one.

■eth0をダウンさせる。

$ sudo ifenslave -d bond0 eth0;sudo grep bonding /var/log/syslog | tail -1 | sed s/".*bonding\: "//
bond0: making interface eth1 the new active one.

■eth0をバックアップとして有効にする。

$ sudo ifenslave bond0 eth0;sudo grep bonding /var/log/syslog | tail -1 | sed s/".*bonding\: "//
bond0: enslaving eth0 as a backup interface with a down link.

■eth0をアクティブにする。

$ sudo ifenslave -c bond0 eth0;sudo grep bonding /var/log/syslog | tail -1 | sed s/".*bonding\: "//
bond0: making interface eth0 the new active one.

■eth1をダウンさせる。

$ sudo ifenslave -d bond0 eth1;sudo grep bonding /var/log/syslog | tail -1 | sed s/".*bonding\: "//
bond0: releasing backup interface eth1

■eth1をバックアップとして有効にする。

$ sudo ifenslave bond0 eth1;sudo grep bonding /var/log/syslog | tail -1 | sed s/".*bonding\: "//
bond0: enslaving eth1 as a backup interface with a down link.

■eth1をアクティブにする。

$ sudo ifenslave -c bond0 eth1;sudo grep bonding /var/log/syslog | tail -1 | sed s/".*bonding\: "//
bond0: making interface eth1 the new active one.

■eth0をアクティブに戻す。

$ sudo ifenslave -c bond0 eth0;sudo grep bonding /var/log/syslog | tail -1 | sed s/".*bonding\: "//
bond0: making interface eth0 the new active one.

■NECが良い資料を出している。正直、めずらしいと思う。。。

 Linux LANポート二重化機能 動作確認
 http://www.express.nec.co.jp/linux/distributions/confirm/bonding.html

■NECのFT検証の手順通り、pingを打ったまま、LANケーブルの抜き差しをします。

 1.eth1のLANケーブルが抜き、リンクダウン
 2.eth1のLANケーブルを挿し、リンクアップ
 3.eth0のLANケーブルが抜き、リンクダウン
 4.eth0のLANケーブルを挿し、リンクアップ

$ tail -50 /var/log/syslog | \
  grep kernel | sed s/".*kernel\: \[.*\] "//g0040] bonding: bond0: making inte
userif-4: sent link up event.
bonding: bond0: link status definitely up for interface eth1.
r8169 0000:03:05.0: eth1: link down
bonding: bond0: link status down for backup interface eth1, disabling it in 200 ms.
userif-4: sent link down event.
userif-4: sent link up event.
bonding: bond0: link status definitely down for interface eth1, disabling it
r8169 0000:03:05.0: eth1: link up
bonding: bond0: link status up for interface eth1, enabling it in 200 ms.
userif-4: sent link down event.
userif-4: sent link up event.
bonding: bond0: link status definitely up for interface eth1.
tg3 0000:03:08.0: eth0: Link is down
bonding: bond0: link status down for active interface eth0, disabling it in 200 ms.
userif-4: sent link down event.
userif-4: sent link up event.
bonding: bond0: link status definitely down for interface eth0, disabling it
bonding: bond0: making interface eth1 the new active one.
tg3 0000:03:08.0: eth0: Link is up at 100 Mbps, full duplex
tg3 0000:03:08.0: eth0: Flow control is off for TX and off for RX
bonding: bond0: link status up for interface eth0, enabling it in 200 ms.
userif-4: sent link down event.
userif-4: sent link up event.
bonding: bond0: link status definitely up for interface eth0.
bonding: bond0: making interface eth0 the new active one.