┌──[root@workstation.lab.example.com]-[~/web] └─$yum list teamd Last metadata expiration check: 0:41:27 ago on Sun 17 Apr 2022 08:34:23 PM CST. Installed Packages teamd.x86_64 1.28-4.el8 @anaconda Available Packages teamd.i686 1.28-4.el8 rhel-8.1-for-x86_64-baseos-rpms ┌──[root@workstation.lab.example.com]-[~/web] └─$rpm -qc teamd /etc/dbus-1/system.d/teamd.conf /usr/lib/systemd/system/teamd@.service ┌──[root@workstation.lab.example.com]-[~/web] └─$nmcli connection add type team team team-slave
网络Team是由内核驱动程序和用户空间守护程序(teamd)实现:
内核驱动程序,有效地处理网络数据包。
teamd守护程序,处理逻辑和接口。
既然冗余,那一定会涉及负载,team通过runner来定义负载类型,常见的负载类型:
runner:
描述
activebackup
主备模式
roundrobin
轮询
broadcast
广播
loadbalance
哈希负载均衡
lacp
类似负载均衡
random
随机
1 2 3
┌──[root@servera.lab.example.com]-[~] └─$nmcli con add con-name team0 ifname team0 type team team.runner activebackup broadcast lacp loadbalance random roundrobin
┌──[root@servera.lab.example.com]-[~] └─$nmcli con modify team0 ipv4.method manual ipv4.addresses 192.168.0.100/24 ┌──[root@servera.lab.example.com]-[~] └─$nmcli con up team0 Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/33)
添加eth1网络接口team0-port1,设置master为team0,并激活
1 2 3 4 5 6
┌──[root@servera.lab.example.com]-[~] └─$nmcli con add con-name team0-port1 type team-slave ifname eth1 master team0 Connection 'team0-port1' (fd24db64-6f9a-41d3-87a5-79f825731d7f) successfully added. ┌──[root@servera.lab.example.com]-[~] └─$nmcli con up team0-port1 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/29)
添加eth2网络接口team0-port2,设置master为team0,并激活
1 2 3 4 5 6
┌──[root@servera.lab.example.com]-[~] └─$nmcli con add con-name team0-port2 type team-slave ifname eth2 master team0 Connection 'team0-port2' (16a95c2a-b581-4b99-ab5a-b9d5ea6b3a87) successfully added. ┌──[root@servera.lab.example.com]-[~] └─$nmcli con up team0-port2 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/32)
查看当前的网络接口信息
1 2 3 4 5 6 7 8 9 10
┌──[root@servera.lab.example.com]-[~] └─$nmcli con show NAME UUID TYPE DEVICE team0 2053fe72-6785-4b16-90f0-256c2bf8c4f3 team team0 ethO-static 7c6d44fe-8349-45ea-beb5-226fe674225b ethernet eth0 team0-port1 fd24db64-6f9a-41d3-87a5-79f825731d7f ethernet eth1 team0-port2 16a95c2a-b581-4b99-ab5a-b9d5ea6b3a87 ethernet eth2 。。。。。。。。 ┌──[root@servera.lab.example.com]-[~] └─$
┌──[root@servera.lab.example.com]-[~] └─$ping -I team0 -c 4 192.168.0.254 PING 192.168.0.254 (192.168.0.254) from 192.168.0.100 team0: 56(84) bytes of data. 64 bytes from 192.168.0.254: icmp_seq=1 ttl=64 time=0.663 ms 64 bytes from 192.168.0.254: icmp_seq=2 ttl=64 time=0.675 ms 64 bytes from 192.168.0.254: icmp_seq=3 ttl=64 time=0.670 ms 64 bytes from 192.168.0.254: icmp_seq=4 ttl=64 time=0.701 ms
--- 192.168.0.254 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 69ms rtt min/avg/max/mdev = 0.663/0.677/0.701/0.023 ms ┌──[root@servera.lab.example.com]-[~] └─$ping -c 4 192.168.0.254 PING 192.168.0.254 (192.168.0.254) 56(84) bytes of data. 64 bytes from 192.168.0.254: icmp_seq=1 ttl=64 time=1.32 ms 64 bytes from 192.168.0.254: icmp_seq=2 ttl=64 time=0.891 ms 64 bytes from 192.168.0.254: icmp_seq=3 ttl=64 time=1.10 ms 64 bytes from 192.168.0.254: icmp_seq=4 ttl=64 time=0.677 ms
┌──[root@servera.lab.example.com]-[~] └─$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: eth1 ┌──[root@servera.lab.example.com]-[~] └─$
┌──[root@servera.lab.example.com]-[~] └─$tcpdump -i eth1 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes 01:55:45.049388 IP servera.lab.example.com > 192.168.0.254: ICMP echo request, id 3324, seq 47, length 64 01:55:45.050152 IP 192.168.0.254 > servera.lab.example.com: ICMP echo reply, id 3324, seq 47, length 64 01:55:45.833842 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8004, length 35 01:55:46.073251 IP servera.lab.example.com > 192.168.0.254: ICMP echo request, id 3324, seq 48, length 64 01:55:46.073964 IP 192.168.0.254 > servera.lab.example.com: ICMP echo reply, id 3324, seq 48, length 64 01:55:47.097140 IP servera.lab.example.com > 192.168.0.254: ICMP echo request, id 3324, seq 49, length 64 01:55:47.098096 IP 192.168.0.254 > servera.lab.example.com: ICMP echo reply, id 3324, seq 49, length 64 ^C 7 packets captured 7 packets received by filter 0 packets dropped by kernel ┌──[root@servera.lab.example.com]-[~] └─$
eth2没有流量通过,属于空闲状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──[root@servera.lab.example.com]-[~] └─$tcpdump -i eth2 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth2, link-type EN10MB (Ethernet), capture size 262144 bytes 01:56:11.817347 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8005, length 35 01:56:13.801263 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8005, length 35 01:56:15.121093 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 52:54:00:02:fa:0d (oui Unknown), length 286 01:56:15.849784 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8005, length 35 ^C 4 packets captured 4 packets received by filter 0 packets dropped by kernel ┌──[root@servera.lab.example.com]-[~] └─$
使用nmcli con down命令将eth1的连接中断,模拟eth1网络接口异常
1 2 3
┌──[root@servera.lab.example.com]-[~] └─$nmcli con down team0-port1 Connection 'team0-port1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/34)
监控网络接口的流量信息,会发现eht2持续发送ICMP包,eth1接口空闲。
1 2 3 4 5 6 7 8 9 10 11 12
┌──[root@servera.lab.example.com]-[~] └─$tcpdump -i eth1 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes 01:57:15.817487 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8004, length 35 01:57:17.802205 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8004, length 35 01:57:19.849582 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8004, length 35 01:57:21.834175 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8004, length 35 ^C 4 packets captured 4 packets received by filter 0 packets dropped by kernel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
┌──[root@servera.lab.example.com]-[~] └─$tcpdump -i eth2 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth2, link-type EN10MB (Ethernet), capture size 262144 bytes 01:57:25.721245 IP servera.lab.example.com > 192.168.0.254: ICMP echo request, id 3324, seq 146, length 64 01:57:25.722066 IP 192.168.0.254 > servera.lab.example.com: ICMP echo reply, id 3324, seq 146, length 64 01:57:25.801453 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8005, length 35 01:57:26.722599 IP servera.lab.example.com > 192.168.0.254: ICMP echo request, id 3324, seq 147, length 64 01:57:26.723161 IP 192.168.0.254 > servera.lab.example.com: ICMP echo reply, id 3324, seq 147, length 64 01:57:27.737269 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 52:54:00:01:fa:0a (oui Unknown), length 286 01:57:27.769125 IP servera.lab.example.com > 192.168.0.254: ICMP echo request, id 3324, seq 148, length 64 01:57:27.769796 IP 192.168.0.254 > servera.lab.example.com: ICMP echo reply, id 3324, seq 148, length 64 01:57:27.850081 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:d7:bc:61.8005, length 35 ^C 9 packets captured 9 packets received by filter 0 packets dropped by kernel ┌──[root@servera.lab.example.com]-[~] └─$
┌──[root@servera.lab.example.com]-[~] └─$teamdctl team0 state setup: runner: activebackup ports: eth2 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 runner: active port: eth2 ┌──[root@servera.lab.example.com]-[~] └─$
┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$teamdctl No team device specified. teamdctl [options] teamdevname command [command args] -h --help Show this help -v --verbose Increase output verbosity -o --oneline Force output to one line if possible -D --force-dbus Force to use D-Bus interface -Z --force-zmq=ADDRESS Force to use ZeroMQ interface [-Z[Address]] -U --force-usock Force to use UNIX domain socket interface Commands: config dump config dump noports config dump actual state state dump state view state item get ITEMPATH state item set ITEMPATH VALUE port add PORTDEV port remove PORTDEV port present PORTDEV port config update PORTDEV PORTCONFIG port config dump PORTDEV
┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$nmcli con mod team0 team.config team.conf
激活team接口
1 2 3
┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$nmcli con up team0 Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/51)
┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$teamdctl team0 state setup: runner: activebackup ports: eth2 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 runner: active port: eth2
删除子接口eth2
1 2 3 4 5 6 7 8
┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$teamdctl team0 port remove eth2 ┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$teamdctl team0 state setup: runner: activebackup runner: active port:
添加子接口eth2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$teamdctl team0 port add eth2 ┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$teamdctl team0 state setup: runner: activebackup ports: eth2 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 runner: active port: eth2 ┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$
故障排除的命令teamnl 命令操作team
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$teamnl No team device specified.
teamnl [options] teamdevname command [command args] -h --help Show this help -p --port_name team slave port name -a --array_index team option array index Commands: ports options getoption OPT_NAME setoption OPT_NAME OPT_VALUE monitor OPT_STYLE
查看子接口状态、id
1 2 3 4 5 6 7 8
┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$teamnl team0 port 4: eth2: up 4294967295Mbit FD ┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$teamnl team0 getoption activeport 4 ┌──[root@servera.lab.example.com]-[/etc/sysconfig/network-scripts] └─$