Contents
はじめに
RHEL7系のネットワークは設定ファイルを直接編集するのではなくNetworkManagerを使うことが推奨されているので、nmcliコマンドを使って、Bonding + Bridge + VLAN の環境を構築してみました。
OSはCentOS7.2です。7.0から7.1でネットワークの設定方法に変更が入っていたり、今後も変更が入る可能性もあるので参考までに。
前提
対向のスイッチはトランクが設定されている
各VLANネットワークにGATEWAYの設定がされている
物理NIC
物理デバイス | 用途 |
enp2s0 | SSHログイン用 |
enp3s0f0 | Bonding + Bridge + VLAN(KVMで作成した仮想マシンのネットワーク環境) |
enp3s0f1 | Bonding + Bridge + VLAN(KVMで作成した仮想マシンのネットワーク環境) |
Bonding構成
・Active - Standbyの構成
・Bonding名:bond0
・物理NICはenp3s0f0とenp3s0f1を使用
VLAN構成
device名とconnection名は共通
VLAN ID | VLANデバイス名 | Bridgeデバイス名 | IPアドレス | GATEWAY |
10 | bond0.10 | br10 | 172.16.10.5/24 | 172.16.10.254 |
11 | bond0.11 | br11 | 172.16.11.5/24 | 172.16.11.254 |
手順
デバイスの確認
[root@localhost ~]# nmcli device DEVICE TYPE STATE CONNECTION enp2s0 ethernet connected enp2s0 enp3s0f0 ethernet disconnected -- enp3s0f1 ethernet disconnected -- enp0s31f6 ethernet unavailable -- lo loopback unmanaged --
Active-BackupモードでBondingデバイスを作成する
[root@localhost ~]# nmcli connection add type bond con-name bond0 ifname bond0 mode active-backup Connection 'bond0' (10d790c0-bf8b-4678-83fe-039dbcc8dd79) successfully added. [root@localhost ~]# nmcli connection mod bond0 ipv4.method disabled ipv6.method ignore
Bondingデバイスが作成されたことを確認
[root@localhost ~]# nmcli device DEVICE TYPE STATE CONNECTION enp2s0 ethernet connected enp2s0 bond0 bond connecting (getting IP configuration) bond0 enp3s0f0 ethernet disconnected -- enp3s0f1 ethernet disconnected -- enp0s31f6 ethernet unavailable -- lo loopback unmanaged --
bond0にぶらさげるためのスレーブインターフェースを作成する
[root@localhost ~]# nmcli connection add type bond-slave autoconnect yes ifname enp3s0f0 master bond0 Connection 'bond-slave-enp3s0f0' (48424058-f2c7-4e52-ab0e-5117555b1929) successfully added. [root@localhost ~]# nmcli connection add type bond-slave autoconnect yes ifname enp3s0f1 master bond0 Connection 'bond-slave-enp3s0f1' (6b7160ef-a95a-4dad-b953-02f33bef68ee) successfully added.
bond0のスレーブインターフェースが作成されたことを確認する
[root@localhost ~]# nmcli device DEVICE TYPE STATE CONNECTION bond0 bond connected bond0 enp2s0 ethernet connected enp2s0 enp3s0f0 ethernet connected bond-slave-enp3s0f0 enp3s0f1 ethernet connected bond-slave-enp3s0f1 enp0s31f6 ethernet unavailable -- lo loopback unmanaged --
VLAN10用のBridgeデバイスの追加とスパニングツリー無効、IP設定
[root@localhost ~]# nmcli connection add type bridge autoconnect yes con-name br10 ifname br10 Connection 'br10' (012f6bde-a3e2-485e-8794-c63f75396708) successfully added. [root@localhost ~]# nmcli connection modify br10 bridge.stp no [root@localhost ~]# nmcli connection modify br10 ipv4.method manual ipv4.address 172.16.10.5/24 ipv4.gateway 172.16.10.254 ipv4.dns 8.8.8.8
VLAN11用のBridgeデバイスの追加とスパニングツリー無効、IP設定
[root@localhost ~]# nmcli connection add type bridge autoconnect yes con-name br11 ifname br11 Connection 'br11' (45e1f163-0be9-4cd3-afad-0c8f5f4ccb6a) successfully added. [root@localhost ~]# nmcli connection modify br11 bridge.stp no [root@localhost ~]# nmcli connection modify br11 ipv4.method manual ipv4.address 172.16.11.5/24 ipv4.gateway 172.16.11.254 ipv4.dns 8.8.8.8
追加したBridgeデバイスの確認
[root@localhost ~]# nmcli device DEVICE TYPE STATE CONNECTION bond0 bond connected bond0 enp2s0 ethernet connected enp2s0 enp3s0f0 ethernet connected bond-slave-enp3s0f0 enp3s0f1 ethernet connected bond-slave-enp3s0f1 br10 bridge connecting (getting IP configuration) br10 br11 bridge connecting (getting IP configuration) br11 enp0s31f6 ethernet unavailable -- lo loopback unmanaged --
ネットワーク再起動
[root@localhost ~]# systemctl restart network
デバイスの確認
[root@localhost ~]# nmcli device DEVICE TYPE STATE CONNECTION bond0 bond connected bond0 br10 bridge connected br10 br11 bridge connected br11 enp2s0 ethernet connected enp2s0 enp3s0f0 ethernet connected bond-slave-enp3s0f0 enp3s0f1 ethernet connected bond-slave-enp3s0f1 enp0s31f6 ethernet unavailable -- lo loopback unmanaged --
Bridgeに設定したIPアドレスを確認する
[root@localhost ~]# ip addr | egrep 'br10|br11' | grep inet inet 172.16.10.5/24 brd 172.16.10.255 scope global br10 inet 172.16.11.5/24 brd 172.16.11.255 scope global br11
VLAN10デバイスの作成とブリッジ接続の設定、有効化
[root@localhost ~]# nmcli connection add type vlan autoconnect yes con-name bond0.10 ifname bond0.10 dev bond0 id 10 Connection 'bond0.10' (5e73b935-b897-4712-9942-9e10bcd937a5) successfully added. [root@localhost ~]# nmcli connection modify bond0.10 connection.master br10 connection.slave-type bridge [root@localhost ~]# nmcli connection up bond0.10 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/47)
VLAN11デバイスの作成とブリッジ接続の設定、有効化
[root@localhost ~]# nmcli connection add type vlan autoconnect yes con-name bond0.11 ifname bond0.11 dev bond0 id 11 Connection 'bond0.11' (2d449486-6cc1-48ed-aac5-37390dd468ae) successfully added. [root@localhost ~]# nmcli connection modify bond0.11 connection.master br11 connection.slave-type bridge [root@localhost ~]# nmcli connection up bond0.11 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/49)
GATEWAYにpingを打ってみる
[root@localhost ~]# ping 172.16.10.254 PING 172.16.10.254 (172.16.10.254) 56(84) bytes of data. 64 bytes from 172.16.10.254: icmp_seq=1 ttl=64 time=2.98 ms 64 bytes from 172.16.10.254: icmp_seq=2 ttl=64 time=1.53 ms 64 bytes from 172.16.10.254: icmp_seq=3 ttl=64 time=1.57 ms 64 bytes from 172.16.10.254: icmp_seq=4 ttl=64 time=1.56 ms 64 bytes from 172.16.10.254: icmp_seq=5 ttl=64 time=1.56 ms ^C --- 172.16.10.254 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4006ms rtt min/avg/max/mdev = 1.530/1.840/2.980/0.571 ms [root@localhost ~]# ping 172.16.11.254 PING 172.16.11.254 (172.16.11.254) 56(84) bytes of data. 64 bytes from 172.16.11.254: icmp_seq=1 ttl=64 time=29.6 ms 64 bytes from 172.16.11.254: icmp_seq=2 ttl=64 time=8.07 ms 64 bytes from 172.16.11.254: icmp_seq=3 ttl=64 time=30.8 ms 64 bytes from 172.16.11.254: icmp_seq=4 ttl=64 time=9.82 ms 64 bytes from 172.16.11.254: icmp_seq=5 ttl=64 time=32.0 ms ^C --- 172.16.11.254 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4006ms rtt min/avg/max/mdev = 8.076/22.075/32.049/10.758 ms
Bondingの確認(Currently Active SlaveのNICが現在ActiveになっているNICです)
[root@localhost ~]# 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: enp3s0f0 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: enp3s0f0 MII Status: up Speed: 100 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: **:**:**:**:**:** Slave queue ID: 0 Slave Interface: enp3s0f1 MII Status: up Speed: 100 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: **:**:**:**:**:** Slave queue ID: 0
コマンドでスレーブインターフェースが切り替わるか確認
[root@localhost ~]# ifenslave -c bond0 enp3s0f0 [root@localhost ~]# ifenslave -c bond0 enp3s0f1
片方のケーブルを抜いて"Currently Active Slave"のNICが切り替わるか確認。別ウインドウでping打ちながら、watchコマンドで見るといいかもしれません。私の環境では切り替わりに約20秒ぐらいでした。
[root@localhost ~]# watch -n 1 "grep 'Currently Active Slave' /proc/net/bonding/bond0"
最後に
Active-Standbyの切り替えにダウンタイムが発生することを考えると、リンクアグリゲーションの方がパフォーマンス的にもいいかなと思います。
ちなみに対向のスイッチは当初catalyst2960を使う予定でしたが、ファンがうるさいのでcisco1812jのLANポートを使って確認しました。cisco1812jのLAN側はおまけのようなものですのでリンクアグリゲーションが使えません。また別の機会に試せたらと思います。
参考
RHEL7/CentOS7のnmcliコマンドでTeamデバイス/Bondingデバイス/VLAN/ブリッジを組み合わせる方法
CentOS7/ネットワーク設定
RHEL7/CentOS7 NetworkManager徹底入門