链路聚合(网卡绑定)
- 链路聚合(7系列起),也叫聚合连接、网卡组队、网卡绑定(5、6系列)。
- 链路聚合:由多块(两块足够)网卡
team-slave
一起组建而成的虚拟网卡 team
,常见配置方式:轮询(roundrobin)、热备份(activebackup)、负载均衡(loadbalance)等。
- 热备份:主网卡故障后,备份网卡成为主网卡,原先的主网卡修复后成为新的备份网卡。
- 配置链路聚合需要的软件:
teamd
、NetworkManager-team
(是软件NetworkManager
的插件,服务NetworkManager.service
) - 步骤:装包、重启服务——》创建链路聚合网卡——》添加组成链路聚合网卡的真实网卡——》配置链路聚合网卡——》删除干扰的网卡配置文件——》重启
- 命令:
man teamd.conf
:查找链路聚合的示例。例如热备份:"runner": {"name": "activebackup"
nmcli connection add type team ifname 自定义链路聚合网卡名 con-name 链路聚合网卡别名 config '{"runner": {"name": "activebackup"}}'
:创建链路聚合网卡,热备份方式。nmcli connection add type team-slave ifname 网卡本名 con-name 网卡别名 master 链路聚合网卡别名
:指定提供链路聚合网卡功能的真实网卡。teamdctl 链路聚合网卡名 state
:查看链路聚合网卡的状态。可以查看使用真实网卡。nmcli device show 链路聚合网卡别名
:详细信息。
创建一台虚拟机team,配置网卡命名规则,关机增加网卡硬件,两张网卡选择同一个网络(例如192.168.88.0网络),开机,重启
虚拟机team:
[root@team ~]# ifconfig eth0 | head -2
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.184 netmask 255.255.255.0 broadcast 192.168.88.255
[root@team ~]# ifconfig eth1 | head -2
eth1: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:89:31:6c txqueuelen 1000 (Ethernet)
[root@team ~]# yum repoinfo
[root@team ~]# yum install -y teamd NetworkManager-team
[root@team ~]# systemctl enable NetworkManager.service
[root@team ~]# systemctl restart NetworkManager.service
[root@team ~]# nmcli connection show
NAME UUID TYPE DEVICE
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 ethernet eth0
[root@team ~]# nmcli connection delete System\ eth0
[root@team ~]# man teamd.conf
[root@team ~]# nmcli connection add type team ifname team0 con-name team0 config '{"runner": {"name": "activebackup"}}'
[root@team ~]# nmcli connection add type team-slave ifname eth0 con-name team0-1 master team0
[root@team ~]# nmcli connection add type team-slave ifname eth1 con-name team0-2 master team0
[root@team ~]# nmcli connection modify team0 ipv4.method manual ipv4.address 192.168.88.154/24 autoconnect yes
[root@team ~]# nmcli connection show
NAME UUID TYPE DEVICE
team0 3645c543-f167-4410-a8f2-f9b4490aba03 team team0
team0-1 e07c3d15-f6cf-4c78-a234-3544455469f7 ethernet eth0
team0-2 28d06030-e479-4241-933d-6791b2f9bbf0 ethernet --
[root@team ~]# rm -f /etc/sysconfig/network-scripts/ifcfg-{eth0,eth1}
[root@team ~]# reboot
[root@team ~]# teamdctl team0 state
setup:
runner: activebackup
ports:
eth0
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
eth1
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: eth1
[root@team ~]# ping 192.168.88.254
[root@team ~]# nmcli connection down team0-2
[root@team ~]# ping 192.168.88.254
[root@team ~]# nmcli connection up team0-2
[root@team ~]# teamdctl team0 state
setup:
runner: activebackup
ports:
eth0
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
eth1
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: eth0
[root@team ~]# nmcli connection show
NAME UUID TYPE DEVICE
team0 3645c543-f167-4410-a8f2-f9b4490aba03 team team0
team0-1 e07c3d15-f6cf-4c78-a234-3544455469f7 ethernet eth0
team0-2 28d06030-e479-4241-933d-6791b2f9bbf0 ethernet eth1
[root@team ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:a9:53:63 txqueuelen 1000 (Ethernet)
RX packets 15 bytes 806 (806.0 B)
RX errors 0 dropped 3 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:a9:53:63 txqueuelen 1000 (Ethernet)
RX packets 591 bytes 36756 (35.8 KiB)
RX errors 0 dropped 515 overruns 0 frame 0
TX packets 7 bytes 390 (390.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 24 bytes 1600 (1.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24 bytes 1600 (1.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
team0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.154 netmask 255.255.255.0 broadcast 192.168.88.255
ether 52:54:00:a9:53:63 txqueuelen 1000 (Ethernet)
RX packets 5 bytes 190 (190.0 B)
RX errors 0 dropped 5 overruns 0 frame 0
TX packets 7 bytes 390 (390.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0