天天看点

CentOS7 配置链路聚合

作者:涛哥运维笔记

CentOS7 配置链路聚合

一、基本介绍

二、CentOS7 配置链路聚合

  1. 查看 NetworkManager 服务
  2. 编写脚本来实现聚合链路
  3. 删除原有网卡
  4. 执行脚本
  5. 验证

一、基本介绍

作用:将主机的多块网卡通过逻辑的方式聚合在一起,目的是为了加大带宽、冗余备份。

聚合链路的几种状态:

  • active-backup:主备模式,所有的流量都在主链路上处理,备用链路没有任何流量(当主链路 down 掉时,备用链路上场)
  • loadbalance:主动和被动模式;主动模式是 team 会智能判断进行负载均衡(被动模式是进行随机的负载均衡)
  • roundrobin:以轮询的方式传输所有端口的包。
  • random:随机分配。

二、CentOS7 配置链路聚合

准备工作:

主机名 操作系统 IP地址 网卡
ITTestCentos CentOS Linux release 7.2 172.16.8.222 VMXNET3 VLAN8
CentOS7 配置链路聚合

1.查看 NetworkManager 服务

[root@ITTestCentos ~]# systemctl status NetworkManager           
CentOS7 配置链路聚合
[root@ITTestCentos ~]# ifconfig           

确认下2块网卡的名称,后面聚合的时候要用到,我这边是eno16780032和eno33559296

CentOS7 配置链路聚合

2.编写脚本来实现聚合链路

注意:网卡接口你们要根据自身机器来配置(我的主机网卡是eno16780032和eno33559296 接口)

[root@ITTestCentos ~]# vim 1.sh           
#!/bin/bash
# 创建 team0 公共网卡设备. 并且将物理网卡添加到逻辑网卡中
nmcli connection add con-name team0 type team ifname team0 config '{"runner":{"name":"activebackup"}}'
# 将 eno16780032 和 eno33559296  添加到 team0
nmcli connection add con-name team0-1 type team-slave ifname eno16780032 master team0
nmcli connection add con-name team0-2 type team-slave ifname eno33559296 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 172.16.8.222/24 ipv4.gateway 172.16.8.1 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@ITTestCentos ~]# rm -rf /etc/sysconfig/network-scripts/ifcfg-eno16780032
[root@ITTestCentos ~]# rm -rf /etc/sysconfig/network-scripts/ifcfg-eno33559296           
[root@ITTestCentos ~]# systemctl restart network  #重启网卡           

4.执行脚本

[root@ITTestCentos ~]# bash 1.sh           
CentOS7 配置链路聚合
CentOS7 配置链路聚合

5.验证

1)开启一个cmd窗口,然后ping172.16.8.222

CentOS7 配置链路聚合

2)将刚才那个活跃的 eno33559296接口的物理网卡断开连接

CentOS7 配置链路聚合

再查看下聚合链路信息

[root@ITTestCentos ~]# teamdctl team0 state           
CentOS7 配置链路聚合

再切换到CMD窗口可以看到ping并没有出现丢包,说明链路没有中断

CentOS7 配置链路聚合

在实际生产环境中,一般大型企业核心交换机都是主备模式,服务器主备链路也是非常的有必要,万一哪天挂了一个核心呢![抠鼻]

继续阅读