RHEL8でBonding(active-backup)をしてみる

どうも、Tです。

最近は、物理環境を触る機会も少なくなったのですが、RHELではよく用いられるBondingでパラメーターとかよく忘れてしまうので備忘録です。

Bondingの詳細はいろんなサイトで解説されているので割愛します。

スポンサーリンク
アドセンス1

環境

  • vSphere ESXi:VMware ESXi, 7.0.3, 19482537
  • ゲストOS:Red Hat Enterprise Linux release 8.6

仮想環境でBondingを組むケースは少ないと思いますが、物理環境準備するのが面倒だったので、仮想マシンのゲストOSで実施しています。

仮想マシン「devrhel86」にvNICを2つ付けています。

やりたいこと

仮想NICをつかってactive-backup構成を設定します。

Bondingでは、仮想的に作成するBondingインターフェースをマスターインターフェース、Bondingインターフェースに参加する物理的なNIC(今回は仮想マシンのvNIC)をスレーブインターフェースと呼びます。

設定

bondingモジュールの読込確認

「modinfo bonding」コマンドでbondingモジュールが読み込まれていることを確認します。

[root@devrhel86 ~]# modinfo bonding
filename:       /lib/modules/4.18.0-372.9.1.el8.x86_64/kernel/drivers/net/bonding/bonding.ko.xz
author:         Thomas Davis, tadavis@lbl.gov and many others
description:    Ethernet Channel Bonding Driver, v3.7.1
version:        3.7.1
license:        GPL
alias:          rtnl-link-bond
rhelversion:    8.6
srcversion:     A50817AB9EE01CCBDF2EC8D
depends:        tls
intree:         Y
name:           bonding
vermagic:       4.18.0-372.9.1.el8.x86_64 SMP mod_unload modversions
sig_id:         PKCS#7
signer:         Red Hat Enterprise Linux kernel signing key

余談ですが、RHEL7以前では、bondingモジュールがデフォルトで読み込まれないため、「 modprobe–first-time bonding」を実行して読込しておきましょう。

7.4. コマンドラインインターフェイス (CLI) の使用 Red Hat Enterprise Linux 7 | Red Hat Customer Portal
Access Red Hat’s knowledge, guidance, and support through your subscription.

Red Hat Enterprise Linux 7 では、ボンディングモジュールはデフォルトでは読み込まれません。root で以下のコマンドを実行してこのモジュールを読み込みます。

~]# modprobe --first-time bonding

bondingインターフェースの作成

下記のコマンドを実行して「active-backup」モードのbond0インターフェースを作成します。

nmcli connection add type bond con-name <コネクション名> ifname <インターフェース名> bond.options “mode=active-backup”

[root@devrhel86 ~]# nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=active-backup"
接続 'bond0' (5dd6eb7a-b60e-4b89-bce1-d0a6d8bf2911) が正常に追加されました。

bond0が作成されました。

[root@devrhel86 ~]# nmcli device
DEVICE TYPE STATE CONNECTION
ens192 ethernet 接続済み ens192
ens224 ethernet 接続済み ens224
virbr0 bridge 接続済み (外部) virbr0
bond0 bond 接続中 (IP 設定を取得中) bond0
lo loopback 管理無し --

bondigへインターフェースの割当

bond0(マスターインターフェース)にvNIC(スレーブインターフェース)を割当ます。

nmcli connection modify <接続プロファイル名(コネクション名)> master <マスターインターフェース名>

[root@devrhel86 ~]# nmcli connection modify ens192 master bond0
[root@devrhel86 ~]# nmcli connection modify ens224 master bond0

bondingへIPアドレスの設定

下記のコマンドを実行してbond0に「IPアドレス」「デフォルトゲートウェイ」「DNS」「DNS検索」を設定します。「ipv4.method manual」で静的IPアドレスを明示します。

nmcli connection modify bond0 ipv4.addresses '192.168.10.160/24'
nmcli connection modify bond0 ipv4.gateway '192.168.10.254'
nmcli connection modify bond0 ipv4.dns '192.168.10.170 192.168.10.171'
nmcli connection modify bond0 ipv4.dns-search 'k.local.lab'
nmcli connection modify bond0 ipv4.method manual

「nmcli connection show bond0」コマンドで設定値があっていることを確認します。なお、この時点ではbond0に対してアクティベート(リンクアップ)していないためリンクダウン状態です。

[root@devrhel86 ~]# nmcli connection show bond0
connection.id:                          bond0
connection.uuid:                        05c0a740-199a-4c5e-aa7e-f15ace2d2779
connection.stable-id:                   --
connection.type:                        bond
connection.interface-name:              bond0
connection.autoconnect:                 はい
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.multi-connect:               0 (default)
connection.auth-retries:                -1
connection.timestamp:                   0
connection.read-only:                   いいえ
connection.permissions:                 --
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 --
connection.gateway-ping-timeout:        0
connection.metered:                     不明
connection.lldp:                        default
connection.mdns:                        -1 (default)
connection.llmnr:                       -1 (default)
connection.dns-over-tls:                -1 (default)
connection.wait-device-timeout:         -1
ipv4.method:                            manual
ipv4.dns:                               192.168.10.170,192.168.10.171
ipv4.dns-search:                        k.local.lab
ipv4.dns-options:                       --
ipv4.dns-priority:                      0
ipv4.addresses:                         192.168.10.160/24
ipv4.gateway:                           192.168.10.254

ー長いので割愛ー

接続のアクティベート

下記のコマンドを実行してbond0をアクティベートします。

[root@devrhel86 ~]# nmcli connection up bond0
接続が正常にアクティベートされました (master waiting for slaves) (D-Bus アクティブパス: /org/freedesktop/NetworkManager/ActiveConnection/5)

下記のコマンドを実行するとbond0がアクティベートされ接続済みになります。

[root@devrhel86 ~]# nmcli device
DEVICE TYPE STATE CONNECTION
ens192 ethernet 接続済み ens192
ens224 ethernet 接続済み ens224
bond0 bond 接続済み bond0
virbr0 bridge 接続済み (外部) virbr0
lo loopback 管理無し --

スレーブインターフェースがDHCPで設定されていたため、一旦OSを再起動します。

設定の確認

「ip addr show」を見るとbond0にIPが設定されているのがわかります。

[root@devrhel86 ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
link/ether 00:50:56:95:fc:5c brd ff:ff:ff:ff:ff:ff
3: ens224: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
link/ether 00:50:56:95:fc:5c brd ff:ff:ff:ff:ff:ff permaddr 00:50:56:95:0f:55
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:50:56:95:fc:5c brd ff:ff:ff:ff:ff:ff
inet 192.168.10.160/24 brd 192.168.10.255 scope global noprefixroute bond0
valid_lft forever preferred_lft forever
inet6 fe80::e8c3:aa79:a618:f850/64 scope link noprefixroute
valid_lft forever preferred_lft forever
5: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:d1:ac:6e brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever

「/proc/net/bonding/bond0」ファイルの中にbondingに関する情報が確認できます。Bondingモードが「active-backup」、現在のアクティブなスレーブインターフェースが「ens192」であることがわかります。

[root@devrhel86 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens192
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:95:fc:5c
Slave queue ID: 0

Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:95:0f:55
Slave queue ID: 0

nmtuiの画面にはbond0だけ表示されるようになります。

active-backupに関するオプション

これが全てではないかもしれませんが、active-backupモードに関するよく使うであろうオプションについて記載します。

なお、Bondingの細かい仕様については下記に記載されています。

https://www.kernel.org/doc/Documentation/networking/bonding.txt

MII監視間隔(デフォルト100ms)

Bondingでは、active-backupのインターフェースの切り替えの監視にMIIかARPを利用し、デフォルトはMIIを利用します。MII監視間隔はデフォルト100msですが、下記コマンドで変更できます。設定を反映するためbond0のアクティベートを行っています。

nmcli connection modify <マスターインターフェース> +bond.options ‘miimon=<ミリ章>’

[root@devrhel86 ~]# nmcli connection modify bond0 +bond.options 'miimon=1000'
[root@devrhel86 ~]# nmcli connection up bond0
接続が正常にアクティベートされました (master waiting for slaves) (D-Bus アクティブパス: /org/freedesktop/NetworkManager/ActiveConnection/5)

「bond.options」ではオプションを追加していくとき「+bond.options」で指定してください。+をつけず下記のように指定することも可能です。

[root@devrhel86 ~]# nmcli connection modify bond0 bond.options ‘mode=active-backup,miimon=1000’

MII Polling Interval (ms)が伸びているのがわかります。

[root@devrhel86 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens192
MII Status: up
MII Polling Interval (ms): 1000
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:95:fc:5c
Slave queue ID: 0

Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:95:0f:55
Slave queue ID: 0

このMII監視を用いてリンクダウンを検知して切替を行いますが、あくまで「間隔」のため10000ms(10秒)にして、リンクダウンから10秒後に切り替わるわけではありません。(監視間隔が伸びるので結果的に切り替わりが遅くなる可能性が高いのですが・・・)

なお、デフォルト100msなのでそのままでもいいのですが、オプション指定をしないとnmtui画面では0で表示されるため、明示的にするためにもこのオプションは追加したほうがいいかなと考えています。

プライマリとプライマリセレクト(デフォルト:None)

下記のコマンドでスレーブインターフェースの中で優先度の高いものを指定できます。

nmcli connection modify bond0 +bond.options “primary=<スレーブインターフェース名>,primary_reselect=<設定値>”

[root@devrhel86 ~]# nmcli connection modify bond0 +bond.options "primary=ens192,primary_reselect=always"
[root@devrhel86 ~]# nmcli connection up bond0
接続が正常にアクティベートされました (master waiting for slaves) (D-Bus アクティブパス: /org/freedesktop/NetworkManager/ActiveConnection/8)

primary_reselectは、デフォルトalwaysのため指定する必要はありませんが、参考として記載しました。下記3つのパラメーターがあります。

設定値意味
always or 0 (default)The primary slave becomes the active slave whenever it comes back up.
better or 1The primary slave becomes the active slave when it comes back up, if the speed and duplex of the primary slave is bette than the speed and duplex of the current active slave.
failure or 2The primary slave becomes the active slave only if the current active slave fails and the primary slave is up.

Primary Slaveに「ens192」が設定されました。

root@devrhel86 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: ens192 (primary_reselect always)
Currently Active Slave: ens192
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:95:fc:5c
Slave queue ID: 0

Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:95:0f:55
Slave queue ID: 0

このprimaryオプションのありなしで下記のように動作が変わります。

「Primary SlaveがNone(デフォルト)」の場合、復旧時にActive経路は切り替わりません。復旧した経路はBackup経路となります。

「Primary Slaveがalways」で指定されている場合、復旧時にPrimaryで指定したインターフェースがActive経路に戻ります。

経路を確実に固定しておきたい場合は、Primaryオプションを指定する場合もありますが、復旧時に切替が強制的に発生してしまうため、こちらは運用思想によって要不要がかわってきそうです。

リンクアップ遅延(デフォルト:0ms)

下記のコマンドでリンクアップの遅延を遅らせることができます。ポートフラッピングなどによって、物理としてはリンクアップしているのにOSからは使える状態ではないなどの回避に使えることができます。

なお、updelayはミリ秒指定で監視にMIIを使っておりかつMII Polling Interval値の倍数値である必要があります。倍数値出ない場合は近い倍数に切り捨てられます

nmcli connection modify bond0 +bond.options “updelay=<ミリ秒>”

[root@devrhel86 ~]# nmcli connection modify bond0 +bond.options "updelay=10000"
[root@devrhel86 ~]# nmcli connection up bond0
接続が正常にアクティベートされました (master waiting for slaves) (D-Bus アクティブパス: /org/freedesktop/NetworkManager/ActiveConnection/8)

Up Delayが設定されいてることがわかります。

[root@devrhel86 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: ens192 (primary_reselect always)
Currently Active Slave: ens192
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 10000
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:95:fc:5c
Slave queue ID: 0

Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:95:0f:55
Slave queue ID: 0

遅延中は、対象のスレーブインターフェースが、「MII Status: going back」と表示されます。

[root@devrhel86 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: ens192 (primary_reselect always)
Currently Active Slave: ens224
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 10000
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens192
MII Status: going back
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:50:56:95:fc:5c
Slave queue ID: 0

Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:50:56:95:0f:55
Slave queue ID: 0

なお、試している限り10000ms(10秒)をしてした場合でもアップリンクがぴったり10秒遅れるというわけではなく、数秒前後早くリンクアップ状態になるというズレがありました。

逆にリンクダウンを遅らせる「downdelay」というオプションもありますが、あまり使わなさそうなので割愛します。「downdelay」も監視にMIIを使っておりかつMII Polling Interval値の倍数値である必要があります。倍数値出ない場合は近い倍数に切り捨てられます

【おまけ】BondingとMACアドレス

Bonding(active-backup)では、インターフェースのMACアドレスは、bondインターフェースも含め1つのMACアドレスが使用されます。一度決まると再起動やネットワーク障害が発生しても決まったMACアドレスが使われるようになります。

どのMACアドレスが使われるかのはっきりした仕様がわかりませんでした。Bondingのマニュアルには、「 first active slave interface」という記述がありましたが、手元の環境で確認した限りは、「スレーブインターフェースの若いMACアドレス」のように見受けらます。

「ip a s」コマンドかわらもわかります。ens224の本来のMACアドレスはpermaddrとして表示されています。

[root@devrhel86 ~]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
link/ether 00:50:56:95:fc:5c brd ff:ff:ff:ff:ff:ff
3: ens224: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
link/ether 00:50:56:95:fc:5c brd ff:ff:ff:ff:ff:ff permaddr 00:50:56:95:0f:55
5: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:d1:ac:6e brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
7: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:50:56:95:fc:5c brd ff:ff:ff:ff:ff:ff
inet 192.168.10.160/24 brd 192.168.10.255 scope global noprefixroute bond0
valid_lft forever preferred_lft forever

これが問題になった経験はなく検証も行っていませんが、MACアドレスの挙動を変更する「fail_over_mac」オプションがあったので備忘録として引用しておきます。

fail_over_mac

Specifies whether active-backup mode should set all slaves to
the same MAC address at enslavement (the traditional
behavior), or, when enabled, perform special handling of the
bond’s MAC address in accordance with the selected policy.

Possible values are:

none or 0

This setting disables fail_over_mac, and causes
bonding to set all slaves of an active-backup bond to
the same MAC address at enslavement time. This is the
default.

active or 1

The “active” fail_over_mac policy indicates that the
MAC address of the bond should always be the MAC
address of the currently active slave. The MAC
address of the slaves is not changed; instead, the MAC
address of the bond changes during a failover.

This policy is useful for devices that cannot ever
alter their MAC address, or for devices that refuse
incoming broadcasts with their own source MAC (which
interferes with the ARP monitor).

The down side of this policy is that every device on
the network must be updated via gratuitous ARP,
vs. just updating a switch or set of switches (which
often takes place for any traffic, not just ARP
traffic, if the switch snoops incoming traffic to
update its tables) for the traditional method. If the
gratuitous ARP is lost, communication may be
disrupted.

When this policy is used in conjunction with the mii
monitor, devices which assert link up prior to being
able to actually transmit and receive are particularly
susceptible to loss of the gratuitous ARP, and an
appropriate updelay setting may be required.

follow or 2

The “follow” fail_over_mac policy causes the MAC
address of the bond to be selected normally (normally
the MAC address of the first slave added to the bond).
However, the second and subsequent slaves are not set
to this MAC address while they are in a backup role; a
slave is programmed with the bond’s MAC address at
failover time (and the formerly active slave receives
the newly active slave’s MAC address).

This policy is useful for multiport devices that
either become confused or incur a performance penalty
when multiple ports are programmed with the same MAC
address.

The default policy is none, unless the first slave cannot
change its MAC address, in which case the active policy is
selected by default.

This option may be modified via sysfs only when no slaves are
present in the bond.

This option was added in bonding version 3.2.0. The “follow”
policy was added in bonding version 3.3.0.

参考

https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/configuring-a-network-bond-using-nmcli-commands_configuring-network-bonding
https://www.kernel.org/doc/Documentation/networking/bonding.txt
7.7. チャンネルボンディングの使用 Red Hat Enterprise Linux 7 | Red Hat Customer Portal
Access Red Hat’s knowledge, guidance, and support through your subscription.
7.3. NetworkManager のコマンドラインツール nmcli を使用したネットワークボンディング Red Hat Enterprise Linux 7 | Red Hat Customer Portal
Access Red Hat’s knowledge, guidance, and support through your subscription.
This site has been closed
新しい人生のために過去を捨て去ります。これまでご覧いただきありがとうございました。メンバーの方はOFUSEまたはメンバー用ブログをご確認ください。

まとめ

1回設定しちゃうとあんまり触らないんで忘れちゃうんですよねえぇ・・・Bondingとは別にTeamingドライバもあるようでどっちがいいんだろうなぁと思う今日この頃です。

スポンサーリンク
アドセンス1
アドセンス1
ブログランキング・にほんブログ村へ

シェアする

フォローする