Contents

Linux - Teaming 網路

Teamd 是一種可以達成網路高可用性或是合併頻寬的手法,RHEL 可以使用 nmcli 非常容易地達成目的。

1. Teaming 網路簡介

為了保持網路高可用性或是更高的頻寬可以透過 Linux 中的程序 teamd 來達成目的。參考 Redhat 官方文件


2. Teaming 不同的用途 :

  1. 負載平衡 -> loadbalance
  2. 網路輪詢 -> roundrobin
  3. 提升頻寬 -> lacp
  4. 故障轉移 -> activebackup
Tip
LACP 並須 Switch 支援 802.3ad 協議並且啟用才能生效。

3. 使用方式:

  1. 創建 team master group
1
nmcli con add con-name $CONN_NAME ifname $IFACE_NAME type team team.runner $TEAM_RUNNER ipv4.addresses $IP ipv4.method manual
  1. 創建 team slave port
1
nmcli con add type team-slave con-name $CONN_NAME ifname $NIC master team0
  1. 啟用 team master & slave
1
2
nmcli con up $TEAM_MASTER
nmcli con up $TEAM_SLAVE
  1. 檢查 teaming 狀態
1
teamdctl $TEAM_MASTER state

4. Lab 操作練習

Teaming 操作必須具備兩張以上網路卡並且連線至同個交換器,才有實際效果,可以使用 HowHow 第二版 Lab 環境 (已經設定完成多網卡及連接交換器) 來操作。

  • Lab 網路拓譜圖(使用 Server A eth1 與 eth2 與 serverb eth1 )

https://hackmd.io/_uploads/rJSikWk5s.png
網路拓樸

4.1. 查看網路介面卡 (Server A)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[root@servera ~]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:00:00:01 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:18:dc:c0 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:12:92:6e brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:0d:ed:1e brd ff:ff:ff:ff:ff:ff

4.3. 創建 team master group (Server A)

1
2
[root@servera ~]# nmcli con add con-name team0 type team ifname team0 ipv4.addresses 192.168.100.100/24 ipv4.method manual  team.runner activebackup
Connection 'team0' (1f5a9d56-db22-4906-9f51-3cb3f0c83e54) successfully added.

4.4. 創建 team slave port (Server A)

1
2
3
4
[root@servera ~]# nmcli con add type team-slave con-name team0-eth1 ifname eth1 master team0
Connection 'team0-eth1' (4e063a35-45d7-416d-9fc8-d8a64f62ec7d) successfully added.
[root@servera ~]# nmcli con add type team-slave con-name team0-eth2 ifname eth2 master team0
Connection 'team0-eth2' (f41d78a6-7e4a-4a34-9bc1-dd78892e0c57) successfully added.

4.5. 啟用 team master & slave (Server A)

1
2
3
4
5
6
7
8
9
[root@servera ~]# nmcli con up team0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/232)
[root@servera ~]# nmcli con up team0-eth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/235)

[root@servera ~]# ip -4 a s team0
7: team0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 192.168.100.100/24 brd 192.168.100.255 scope global noprefixroute team0
       valid_lft forever preferred_lft forever
Tip
上述可以觀察 team master 群組已經啟用。

4.6. 檢查 teaming 狀態 (Server A)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
[root@servera ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  eth1
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
  eth2
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: eth2
Note
上述可以觀察目前流量均會走 eth2 網路介面卡。

4.6. 設定 ServerB 網路及啟用並發送 ICMP (Server B)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
[root@serverb ~]# nmcli con add con-name eth1 ipv4.addresses 192.168.100.11/24 ipv4.method manual ifname eth1 type ethernet
Connection 'eth1' (ccd0e3f8-68dd-4e53-bb17-5be449874fe6) successfully added.
[root@serverb ~]# nmcli con up eth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/484)
[root@serverb ~]# ip -4a s eth1
Option "-4a" is unknown, try "ip -help".
[root@serverb ~]# ip -4 a s eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    inet 192.168.100.11/24 brd 192.168.100.255 scope global noprefixroute eth1
       valid_lft forever preferred_lft forever
       
[root@serverb ~]# ping 192.168.100.100
PING 192.168.100.100 (192.168.100.100) 56(84) bytes of data.
64 bytes from 192.168.100.100: icmp_seq=1 ttl=64 time=1.79 ms
64 bytes from 192.168.100.100: icmp_seq=2 ttl=64 time=0.974 ms
...

4.7. 將 Server A 的 eth2 網路介面關閉 (Server A)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
[root@servera ~]# ip link set eth2 down
[root@servera ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  eth1
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 1
  eth2
    link watches:
      link summary: down
      instance[link_watch_0]:
        name: ethtool
        link: down
        down count: 1
runner:
  active port: eth1
Note
停用 eth2 網路卡會因綁定 Teaming 後會自動切換至 eth1 網路介面卡,並且 Server B 的 ICMP 封包發送不會因此而斷開。

5. 小結

透過 nmtcli 可以很輕鬆且快速的配置好網路 Teaming,此功能在實體機器上使用率非常高,是非常好用的核心模組。



如果你還沒有註冊 Like Coin,你可以在文章最下方看到 Like 的按鈕,點下去後即可申請帳號,透過申請帳號後可以幫我的文章按下 Like,而 Like 最多可以點五次,而你不用付出任何一塊錢,就能給我寫這篇文章的最大的回饋!