4案例4:配置聚合鏈路
4.1問題
本例要求在兩個虛擬機server0、desktop0之間配置一個鏈路,要求如下:
- 此鏈路使用接口eth1和eth2
- 此鏈路在其中一個接口失效時仍然能工作
- 此鏈路在server0上使用下面的地址172.16.3.20/255.255.255.0
- 此鏈路在desktop0上使用下面的地址172.16.3.25/255.255.255.0
- 此鏈路在系統重啓之後依然保持正常狀態
4.2方案
聚合鏈路(team):指的是網絡連接的捆綁/組隊,通過將多個實際網卡(team-slave)整個爲邏輯上的單個連接,實現負載均衡、熱備份的單塊網卡難以完成的功能。
聚合連接的類型:熱備份activebackup、輪詢負載均衡roundrobin
定義聚合連接的類型配置時,採用JSON語法標記,主要特點如下:
- 標記一個對象-----{對象}
- 每一個對象----- 名稱:值
- 每一個字符串----- “字符串”
熱備份-聚合連接(activebackup):
{ "runner":{ "name":"activebackup" } }
負載均衡-聚合連接(roundrobin):
{ "runner":{ "name":"roundrobin" } }
4.3步驟
除了所配置的IP地址不一樣之外,在server0、desktop0主機上的其他操作相同。此處僅列在server0上的配置過程。
實現此案例需要按照如下步驟進行。
步驟一:準備練習用網卡環境
新建的聚合鏈路將組合新增的兩塊網卡eth1、eth2。
[root@server0 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.0.11 netmask 255.255.255.0 broadcast 172.25.0.255
inet6 2003:ac18::305 prefixlen 64 scopeid 0x0<global>
inet6 fe80::5054:ff:fe00:b prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:00:0b txqueuelen 1000 (Ethernet)
RX packets 172995 bytes 23870389 (22.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 54053 bytes 34274222 (32.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:f8:86:c1 txqueuelen 1000 (Ethernet)
RX packets 104217 bytes 5437855 (5.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 171 bytes 17171 (16.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:38:79:d9 txqueuelen 1000 (Ethernet)
RX packets 104118 bytes 5428927 (5.1 MiB)
RX errors 0 dropped 2060 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
.. ..
步驟二:創建聚合連接配置
1)新建聚合連接
[root@server0 ~]# nmcli con add con-name team0 type team ifname team0 config '{ "runner":{ "name":"activebackup" } }'
Connection 'team0' (8e61d730-50ff-4a7b-8ca0-fcf5955f6ea7) successfully added.
2)配置IPv4地址
[root@server0 ~]# nmcli con modify team0 ipv4.method manual ipv4.addresses '172.16.3.20/24' connection.autoconnect yes
3)新建聚合成員連接
[root@server0 ~]# nmcli con add con-name team0-p1 type team-slave ifname eth1 master team0
Connection 'team0-p1' (a62d23a2-9a2a-4855-8fbc-60ce1fd43f0b) successfully added.
[root@server0 ~]# nmcli con add con-name team0-p2 type team-slave ifname eth2 master team0
Connection 'team0-p2' (f4d4980e-8123-4840-89ac-1af148cc2eea) successfully added.
步驟三:激活聚合連接
1)激活聚合連接
[root@server0 ~]# nmcli connection up team0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
2)激活聚合成員連接
[root@server0 ~]# nmcli connection up team0-p1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
[root@server0 ~]# nmcli connection up team0-p2
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
步驟三:確認聚合連接狀態
1)查看聚合連接地址
[root@server0 ~]# ifconfig team0
team0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.3.20 netmask 255.255.255.0 broadcast 172.16.3.255
inet6 fe80::c80d:efff:fe08:ca57 prefixlen 64 scopeid 0x20<link>
ether ca:0d:ef:08:ca:57 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 36 overruns 0 frame 0
TX packets 68 bytes 8695 (8.4 KiB)
TX errors 0 dropped 1 overruns 0 carrier 0 collisions 0
2)查看聚合連接運行狀態
[root@server0 ~]# teamdctl team0 state
setup:
runner: activebackup //運行模式/類型
ports:
eth1 //成員網卡1
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
eth2 //成員網卡2
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
runner:
active port: eth1 //當前活動的成員網卡