环境:
CentOS7
CentOS Linux release 7.7.1908 (Core)
网卡1:瑞昱普通千兆板载网卡
网卡2:EB-LINK intel 82599芯片PCI-E X8 10G
光模块千兆单模1310X1
问题描述:
CentOS7 主机网卡怎么配置端口聚合
配置网卡聚合链路的作用
将主机的多块网卡通过逻辑的方式聚合在一起,目的是加大带宽、冗余备份,提供了网卡的高可用
聚合链路的四种模式
注意:聚合链路一般有bond和team两种模式,bond模式最多两块网卡,而team最多可以加8快网卡,最常用的为team模式
聚合链路的几种状态:
1.active-backup:主备模式,所有的流量都在主链路上处理,备用链路没有任何流量(当主链路 down 掉时,备用链路上场)
2.loadbalance:主动和被动模式;主动模式是 team 会智能判断进行负载均衡(被动模式是进行随机的负载均衡)
3.roundrobin:以轮询的方式传输所有端口的包
4.random:随机分配
解决方案:
1.查看 NetworkManager 服务
[root@localhost ~]# systemctl status NetworkManager
网卡接口你们要根据自身机器来配置(我的主机网卡是 enp4s0 和 enp1s0 接口)
[root@localhost ~]#ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether a8:5e:45:70:09:54 brd ff:ff:ff:ff:ff:ff
inet 192.168.137.4/24 brd 192.168.137.255 scope global noprefixroute dynamic enp4s0
valid_lft 598343sec preferred_lft 598343sec
inet6 fe80::4c9c:ca9c:9b48:95ea/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp1s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether 00:1b:21:c4:55:9c brd ff:ff:ff:ff:ff:ff
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:7f:9e:10 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen
2.编写端口聚合脚本
[root@localhost ~]# vim 2.sh
#!/bin/bash
# 创建 n0 汇聚逻辑网卡. 并且将物理网卡添加到逻辑网卡中
nmcli connection add con-name n0 type team ifname n0 config '{"runner":{"name":"loadbalance"}}'
# 将 enp4s0 和 enp1s0 添加到 n0
nmcli connection add con-name n0-1 type team-slave ifname enp4s0 master n0
nmcli connection add con-name n0-2 type team-slave ifname enp1s0 master n0
# 开启两个物理网卡
nmcli connection up n0-1
nmcli connection up n0-2
# 查看网卡设备信息
nmcli connection show
# 设置休眠时间为 5 秒. 方便查看信息
sleep 5
# 查看聚合链路的状态是否处于冗余备份状态
teamdctl n0 state
# 设置休眠时间为 5 秒. 方便查看信息
sleep 5
# 设置 n0 网卡的临时 IP 地址并且启动该网卡
nmcli connection modify n0 ipv4.addresses 192.168.137.4/24 ipv4.gateway 192.168.137.1 ipv4.dns 114.114.114.114 ipv4.method manual
nmcli connection up n0
# 修改 n0 网卡配置文件. 并重启网卡
sed -i 's/none/static/g' /etc/sysconfig/network-scripts/ifcfg-n0
systemctl restart network
3.删除原有网卡
[root@localhost ~]# rm -rf /etc/sysconfig/network-scripts/ifcfg-enp4s0
[root@localhost ~]# rm -rf /etc/sysconfig/network-scripts/ifcfg-enp1s0
[root@localhost ~]# reboot
重启服务器
4.执行脚本
如ssh连不了需本地执行
[root@localhost ~]# bash 2.sh
[root@localhost ~]# bash 2.sh
连接 "n0" (5da681ce-2d9f-481c-9766-cbf874e21b00) 已成功添加。
连接 "n0-1" (39ff0084-92e4-4dbb-9856-482eee943508) 已成功添加。
连接 "n0-2" (e6ea5f2d-ee14-4740-8b77-2b12cb80dd4e) 已成功添加。
Socket error Event: 32 Error: 10053.
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(192.168.137.4) at 18:08:06.
5.查看 IP 是否正常
enp1s0和enp4s0 mac地址一致
ifconfig
[root@localhost ~]# ifconfig
enp1s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether a8:5e:45:70:09:54 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
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
enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether a8:5e:45:70:09:54 txqueuelen 1000 (Ethernet)
RX packets 533 bytes 50321 (49.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 413 bytes 40303 (39.3 KiB)
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 9 bytes 880 (880.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9 bytes 880 (880.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
n0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.137.4 netmask 255.255.255.0 broadcast 192.168.137.255
inet6 fe80::771e:254b:27f2:7aac prefixlen 64 scopeid 0x20<link>
ether a8:5e:45:70:09:54 txqueuelen 1000 (Ethernet)
RX packets 526 bytes 42465 (41.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 416 bytes 41561 (40.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
成功后图像界面