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 //当前活动的成员网卡