なんとなくLinux bondingによるネットワークのトランキングを試してみた。
bondingというのがLinuxにおけるポートトランキング実装の名前であり、束ねた仮想的なネットワークインタフェースをmaster、束ねられる物理NICをslaveと呼ぶ。
当方の実験環境は以下の通り。
- PC: hp ML110 G5
- OS: Debian GNU / Linux 6.0 @ Linux 2.6.32-5 (x86)
- NIC1: OnBoard Broadcom Corporation NetXtreme BCM5722(tg3)
- NIC2: PCIe Intel Pro 1000 CT Desktop Adapter(e1000e)
- Intelligent L2SW: Allied Telesis CentreCOM GS924M
- Non-Intelligent L2SW: CG-SW08GTPV2
PC側の設定
Debianでは、bondingはifenslaveというパッケージで提供されているので、まずaptからifenslaveのインストールを行う。
# aptitude install ifenslave
次に、/etc/modulesを編集し、起動時にbondingモジュールを読み込むように設定する。
既存のファイルにbondingという行を追加するだけでいい。
$ 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
bonding
次に、/etc/modprobe.d/にbonding.confのようなファイルを適当に作成し、bondingの設定を記述していく。
options bonding mode=x miimon=0 arp_interval=10000 arp_ip_target=aaa.bbb.ccc.ddd
決めるべきことはbondingのmodeとリンクの死活監視の方法である。
modeについては http://www.jp.redhat.com/magazine/jp/200904/rhel.html この辺を参考に適当なものを選択する。
リンクの死活監視にはMIIが使える環境ならMIIを、使えないならarpを使う。これも適当に設定する。ethtool eth*としたときにbondingに使用するNIC全てでちゃんと出力が出ればMIIでいいらしい。
最後にbondingインタフェースの設定を行う。ディストリによって差が出る部分である。
debianでは/etc/network/interfacesファイルに通常の物理NICと同じようにIPアドレスやネットマスクについて記述すればよい。
当方の環境ではこれまでeth0だった部分をbond0に書き換えて、slaves eth1 eth0という行を追加するだけでよかった。
出来上がりとしてはこのようになる。
# 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# The primary network interface
#allow-hotplug eth0
#iface eth0 inet static
allow-hotplug bond0
iface bond0 inet static
address 192.168.10.100
netmask 255.255.255.0
network 192.168.10.0
broadcast 192.168.10.255
gateway 192.168.10.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 8.8.8.8
slaves eth1 eth0
なお、udevでNICの名前を置き換えているとややこしくなるので、/etc/udev/rules.d/70-persistent-net.rulesを弄ってNAMEを元々認識されるeth*に合わせておいたほうが無難である。(dmesgを調べると分かるはず)
ここまで設定してリブートすると、NICがbondingされた状態で起動するはずである。
ifconfigにbond0というインタフェースが現れ、slavesと設定したNICの状態にUP BROADCAST RUNNING SLAVE MULTICASTのようにSLAVEが含まれていればOKです。
/proc/net/bonding/bond0を読むことでより詳細な情報を得ることができる。
$ cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0802.3ad info
LACP rate: slow
Aggregator selection policy (ad_select): stable
Active Aggregator Info:
Aggregator ID: 1
Number of ports: 1
Actor Key: 17
Partner Key: 1
Partner Mac Address: 00:00:00:00:00:00Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xx
Aggregator ID: 1Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xx
Aggregator ID: 2
実験
ではここから実験の開始。
まずはmode0の実験を行う。
mode0については、参考にするサイトによってポートトランキングに対応したSWが必要と書かれていたり、いなかったりする。
結論から言うと、当方の環境での実験では、トランキング非対応のスイッチでもフェイルオーバーを含めた動作が期待通りに行われた。
したがって、mode0にはポートトランキング対応SWは必須ではないようだ。
ただし、SW→PCのトラフィックがいずれかのNICに偏るなどして本来の性能が発揮できない、といった問題があったりするかもしれない。