欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Centos7 配置网卡链路聚合

程序员文章站 2022-05-04 13:05:20
一、系统环境1、在VMware Workstation部署Centos7系统2、添加网卡3、查看网卡,看到新加的两张网卡(eno33554984,eno50332208)是没有IP地址的[root@localhost ~]# ip add1: lo: mtu 65536 qdisc noqueue state......

一、系统环境

1、在VMware Workstation部署Centos7系统

2、添加网卡

Centos7 配置网卡链路聚合

Centos7 配置网卡链路聚合

Centos7 配置网卡链路聚合

3、查看网卡,看到新加的两张网卡(eno33554984,eno50332208)是没有IP地址的

[root@localhost ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:10:c4:16 brd ff:ff:ff:ff:ff:ff
    inet 192.168.253.131/24 brd 192.168.253.255 scope global dynamic eno16777736
       valid_lft 1601sec preferred_lft 1601sec
    inet6 fe80::20c:29ff:fe10:c416/64 scope link 
       valid_lft forever preferred_lft forever
3: eno33554984: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:10:c4:20 brd ff:ff:ff:ff:ff:ff
4: eno50332208: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:10:c4:2a brd ff:ff:ff:ff:ff:ff

二、配置过程

1、nmcli查看设备状态,新增的网卡CONNECTION为Wired connection 2和1状态

[root@localhost ~]# nmcli device status
DEVICE       TYPE      STATE      CONNECTION         
eno16777736  ethernet  connected  eno16777736        
eno33554984  ethernet  connected  Wired connection 2 
eno50332208  ethernet  connected  Wired connection 1 
lo           loopback  unmanaged  --  

如果CONNECTION显示:Wired connection,删除即可

[root@localhost ~]# nmcli connection delete Wired\ connection\ 2
Connection 'Wired connection 2' (53ae8d3b-0774-42bb-949c-ae01a7fb22b8) successfully deleted.
[root@localhost ~]# nmcli connection delete Wired\ connection\ 1
Connection 'Wired connection 1' (25511265-8a01-4a1c-a370-14091516243b) successfully deleted.

2、创建链接聚合team1并查看网卡状态

[root@localhost ~]# nmcli connection add type team con-name team1 ifname team1 config '{"runner":{"name":"activebackup"}}'
Connection 'team1' (11162383-33d9-4b86-9cee-1349c9c273f7) successfully added.
[root@localhost ~]# nmcli device status 
DEVICE       TYPE      STATE                                  CONNECTION  
eno16777736  ethernet  connected                              eno16777736 
team1        team      connecting (getting IP configuration)  team1       
eno33554984  ethernet  disconnected                           --          
eno50332208  ethernet  disconnected                           --          
lo           loopback  unmanaged                              --          
[root@localhost ~]# nmcli connection show
NAME         UUID                                  TYPE            DEVICE      
eno16777736  2a18182f-7e85-40bf-93bc-c28fe4564ba3  802-3-ethernet  eno16777736 
team1        11162383-33d9-4b86-9cee-1349c9c273f7  team            team1

3、将两张新网卡添加到这个team1中并查看网卡状态

[root@localhost ~]# nmcli connection add type team-slave con-name eno33554984 ifname eno33554984 master team1
Connection 'eno33554984' (722991e8-a542-4761-b347-334d13cae25a) successfully added.
[root@localhost ~]#
[root@localhost ~]# nmcli connection add type team-slave con-name eno50332208 ifname eno50332208 master team1
Connection 'eno50332208' (154fdde2-f162-47d5-b2d4-11dd89ae3a0f) successfully added.
[root@localhost ~]# nmcli device status 
DEVICE       TYPE      STATE      CONNECTION  
eno16777736  ethernet  connected  eno16777736 
eno33554984  ethernet  connected  eno33554984 
eno50332208  ethernet  connected  eno50332208 
team1        team      connected  team1       
lo           loopback  unmanaged  --          
[root@localhost ~]# nmcli connection show
NAME         UUID                                  TYPE            DEVICE      
eno16777736  2a18182f-7e85-40bf-93bc-c28fe4564ba3  802-3-ethernet  eno16777736 
eno50332208  154fdde2-f162-47d5-b2d4-11dd89ae3a0f  802-3-ethernet  eno50332208 
eno33554984  722991e8-a542-4761-b347-334d13cae25a  802-3-ethernet  eno33554984 
team1        11162383-33d9-4b86-9cee-1349c9c273f7  team            team1 

4、配置team1的IP地址,红色框是需要修改和添加的内容

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-team1

Centos7 配置网卡链路聚合

5、重启网卡服务

[root@localhost ~]# systemctl restart network

查看到网卡状态都是OK

[root@localhost ~]# systemctl status  network
● network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network)
   Active: active (exited) since Mon 2018-07-09 18:29:13 CST; 21s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3353 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
  Process: 3657 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)

Jul 09 18:29:13 localhost.localdomain network[3657]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Jul 09 18:29:13 localhost.localdomain network[3657]: [  OK  ]
Jul 09 18:29:13 localhost.localdomain network[3657]: Bringing up interface eno16777736:  Connection successfully activated (D-Bus active pat...tion/6)
Jul 09 18:29:13 localhost.localdomain network[3657]: [  OK  ]
Jul 09 18:29:13 localhost.localdomain network[3657]: Bringing up interface eno33554984:  Connection successfully activated (D-Bus active pat...tion/7)
Jul 09 18:29:13 localhost.localdomain network[3657]: [  OK  ]
Jul 09 18:29:13 localhost.localdomain network[3657]: Bringing up interface eno50332208:  Connection successfully activated (D-Bus active pat...tion/9)
Jul 09 18:29:13 localhost.localdomain network[3657]: [  OK  ]
Jul 09 18:29:13 localhost.localdomain network[3657]: Bringing up interface team1:  [  OK  ]
Jul 09 18:29:13 localhost.localdomain systemd[1]: Started LSB: Bring up/down networking.
Hint: Some lines were ellipsized, use -l to show in full.

6、查看team1的IP地址和聚合配置,可以看到eno33554984是当前主接口

[root@localhost ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:10:c4:16 brd ff:ff:ff:ff:ff:ff
    inet 192.168.253.131/24 brd 192.168.253.255 scope global dynamic eno16777736
       valid_lft 1727sec preferred_lft 1727sec
    inet6 fe80::20c:29ff:fe10:c416/64 scope link 
       valid_lft forever preferred_lft forever
3: eno33554984: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master team1 state UP qlen 1000
    link/ether 00:0c:29:10:c4:20 brd ff:ff:ff:ff:ff:ff
4: eno50332208: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master team1 state UP qlen 1000
    link/ether 00:0c:29:10:c4:20 brd ff:ff:ff:ff:ff:ff
6: team1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 00:0c:29:10:c4:20 brd ff:ff:ff:ff:ff:ff
    inet 192.168.253.140/24 brd 192.168.253.255 scope global team1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe10:c420/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# teamdctl team1 state
setup:
  runner: activebackup
ports:
  eno33554984
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
  eno50332208
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: eno33554984

7、模拟接口故障,关掉一个接口测试,主接口变为eno50332208

[root@localhost ~]# ifdown eno33554984
Device 'eno33554984' successfully disconnected.
[root@localhost ~]# teamdctl team1 state
setup:
  runner: activebackup
ports:
  eno50332208
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: eno50332208

8、当故障接口恢复也不会抢占主接口,从而避免网络抖动

[root@localhost ~]# ifup eno33554984
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
[root@localhost ~]# teamdctl team1 state
setup:
  runner: activebackup
ports:
  eno33554984
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
  eno50332208
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: eno50332208

 

本文地址:https://blog.csdn.net/tladagio/article/details/80974422