CentOS7 配置聚合链路
- 一、基本介绍
- 二、CentOS7 配置聚合链路
- 1.查看 NetworkManager 服务
- 2.编写脚本来实现聚合链路
- 3.删除原有网卡
- 4.执行脚本
- 5.验证
一、基本介绍
- 作用:将主机的多块网卡通过逻辑的方式聚合在一起,目的是为了加大带宽、冗余备份。
聚合链路的几种状态:
-
active-backup
:主备模式,所有的流量都在主链路上处理,备用链路没有任何流量(当主链路down
掉时,备用链路上场) -
loadbalance
:主动和被动模式;主动模式是team
会智能判断进行负载均衡(被动模式是进行随机的负载均衡) -
roundrobin
:以轮询的方式传输所有端口的包。 -
random
:随机分配。
二、CentOS7 配置聚合链路
准备工作:
主机名 | 操作系统 | IP地址 | 网卡 |
localhost | CentOS7.4 | 192.168.1.1 | 双网卡都是 |
1.查看 NetworkManager 服务
[root@localhost ~]# systemctl status NetworkManager
2.编写脚本来实现聚合链路
- 注意:网卡接口你们要根据自身机器来配置(我的主机网卡是
ens32
和ens34
接口)
[root@localhost ~]# vim 1.sh
#!/bin/bash
# 创建 team0 公共网卡设备. 并且将物理网卡添加到逻辑网卡中
nmcli connection add con-name team0 type team ifname team0 config '{"runner":{"name":"activebackup"}}'
# 将 ens32 和 ens34 添加到 team0
nmcli connection add con-name team0-1 type team-slave ifname ens32 master team0
nmcli connection add con-name team0-2 type team-slave ifname ens34 master team0
# 开启两个物理网卡
nmcli connection up team0-1
nmcli connection up team0-2
# 查看网卡设备信息
nmcli connection show
# 设置休眠时间为 5 秒. 方便查看信息
sleep 5
# 查看聚合链路的状态是否处于冗余备份状态
teamdctl team0 state
# 设置休眠时间为 5 秒. 方便查看信息
sleep 5
# 设置 team0 网卡的临时 IP 地址并且启动该网卡
nmcli connection modify team0 ipv4.addresses 192.168.1.1/24 ipv4.gateway 192.168.1.254 ipv4.method manual
nmcli connection up team0
# 修改 team0 网卡配置文件. 并重启网卡
sed -i 's/none/static/g' /etc/sysconfig/network-scripts/ifcfg-team0
systemctl restart network
# 查看 IP 是否正常
ifconfig
3.删除原有网卡
[root@localhost ~]# rm -rf /etc/sysconfig/network-scripts/ifcfg-ens32
[root@localhost ~]# rm -rf /etc/sysconfig/network-scripts/ifcfg-ens34
[root@localhost ~]# systemctl restart network # 重启网卡
- 重启完网卡后
xshell
会断掉,因为我们把所有网卡都删除掉了。
4.执行脚本
[root@localhost ~]# bash 1.sh
5.验证
1)使用 Xshell
连接 team0
的 IP 地址进行验证
2)将刚才那个活跃的 ens32
接口的物理网卡断开连接
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifconfig
3)查看 team0
公共网卡的状态信息
[root@localhost ~]# teamdctl team0 state