2011年3月31日木曜日

コマンド操作によるインターフェースの切り替え


ボンディングのモードをフォールトトレランス(アクティブ-バックアップ)として設定している場合、
プライマリのインターフェースがサーバごとにまちまちになっていると
トラフィック経路に違いがでるため、そろえておきたい。

方法としては2つある。
(1) サーバのインターフェースをダウン・アップさせる。
(2) サーバが接続されているスイッチのインターフェースを
シャットダウン・ノーシャットダウンさせる。

しかしこれ以外にも、サーバ側のコマンド操作で切り替えができることが分かった。


◆ 前提
eth0とeth1の2つのインターフェースでbond0を組んでいる。
eth0はアクティブであり、eth1がバックアップである。
サーバ側で"ifenslave"コマンドを用い、eth0をバックアップにeth1をアクティブに切り替える。



◆ 現状のインターフェースの確認
・ ボンディング状態の確認
# cat /proc/net/bonding/bond0
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0 ← アクティブはeth0である
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 5000
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xx

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: yy:yy:yy:yy:yy:yy




◆ ボンディングの切り替え
rootユーザで、"ifenslave"コマンドを実行する。
# ifenslave -c bond0 eth1

オプション 
-c : --change-active



◆ 切り替え後のインターフェースの確認
・ ボンディング状態の確認
# cat /proc/net/bonding/bond0
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 5000
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: xx:xx:xx:xx:xx:xx

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: yy:yy:yy:yy:yy:yy



・ ログからの確認
# tail -f /var/log/messages
(略) bonding: bond0: making interface eth1 the new active one.