RedHat7 链路聚合

1、什么是链路聚合

NIC teaming,简单的说就是多个物理端口绑定在一起当成一个逻辑端口使用,以便提高带宽,实现负载平衡或高可用的功能。RHEL7里面是通过runner (可以视作一段代码)来实现不同的目的。

配置的基本过程就是配置一个逻辑端口的连接,视作master;然后把需要的物理端口配置成slave 连接,绑定到组。然后把这个逻辑端口分配IP就可以用了

2、配置链路聚合

2.1 首先准备好两块网卡,它们有不同的MAC地址

1
[root@localhost ~]# ifconfig

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:a3:35:37 txqueuelen 1000 (Ethernet)
RX packets 13 bytes 4446 (4.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eno33554992: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::20c:29ff:fea3:3541 prefixlen 64 scopeid 0x20
ether 00:0c:29:a3:35:41 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 37 bytes 6318 (6.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

2.2 创建一个新连接,类型是team连接名称team0

1
2
3
[root@localhost ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner": {"name": "activebackup"}}'

Connection 'team0' (d2c3f64b-c59d-4e5f-af0a-4b9299919b59) successfully added.

activebackup表示热备

loadbalance表示负载均衡

2.3 master 配置好了,还得配置slave

eno16777736eno33554960两块网卡加入到team0,并命名为team0-1team0-2

1
2
3
4
5
[root@localhost ~]# nmcli connection add type team-slave con-name team0-1 ifname eno33554992 master team0
Connection 'team0-1' (054962e7-e958-453f-ad8c-fd7aa44da399) successfully added.
[root@localhost ~]# nmcli connection add type team-slave con-name team0-2 ifname eno16777736 master team0

Connection 'team0-2' (dc7fbdf7-7325-49ab-a76e-dc2090f57a69) successfully added.

2.4 执行nmcli connection show命令查看team0-1和team0-2的状态

上图可以看出team0-1和team0-2没有连接,执行下列命令连接team0-1和team0-2

执行ifconfig,发现网卡的地址都一样了,这样交换机才能转发包到同一个逻辑端口

1
[root@localhost ~]# ifconfig

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:a3:35:37 txqueuelen 1000 (Ethernet)
RX packets 40 bytes 13482 (13.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 205 bytes 35294 (34.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eno33554992: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:a3:35:37 txqueuelen 1000 (Ethernet)
RX packets 94 bytes 26966 (26.3 KiB)
RX errors 0 dropped 90 overruns 0 frame 0
TX packets 106 bytes 18332 (17.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

2.5 最后给team0 分配一个IP地址

(也可以直接用图形工具设置IP地址)

1
2
[root@localhost ~]# nmcli connection modify team0 ipv4.addresses '192.168.10.10/24'
[root@localhost ~]# nmcli connection modify team0 ipv4.method manual

测试一下,先看看team0当前状态

1
[root@localhost ~]# teamdctl team0 state

setup:
runner: activebackup
ports:
eno16777736
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
eno33554992
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0runner:
active port: eno16777736

2.6 关掉eno16777736的连接

自动切换到第二个物理端口了,测试成功

1
2
3
[root@localhost ~]# nmcli connection down team0-2
Connection 'team0-2' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/67)
[root@localhost ~]# teamdctl team0 state

setup:
runner: activebackup
ports:
eno33554992
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: eno33554992

2.7 改为负载均衡

如果想把热备(activebackup)改为负载均衡(loadbalance),可直接修改配置文件,也可以用命令修改

修改配置文件

1
2
3
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-team0
DEVICE=team0
TEAM_CONFIG="{\"runner\": {\"name\": \"loadbalance\"}}"

改activebackup为loadbalance

或者用命令修改

1
[root@localhost network-scripts]# nmcli connection modify team0 team.config '{"runner": {"name": " loadbalance "}}'

重启网卡服务,再次查看team0状态

1
2
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# teamdctl team0 state

setup:
runner: loadbalance
ports:
eno33554992
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
eno16777736
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0

-------------本文结束感谢您的阅读-------------