Linux 链路聚合

Posted 丁海龙

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 链路聚合相关的知识,希望对你有一定的参考价值。

   链路聚合与双网卡绑定几乎相同,可以实现多网卡绑定主从荣誉,负载均衡,提高网络访问流量。但链路聚合与双网卡绑定技术(bond)不同点就在于,双网卡绑定只能使用两个网卡绑定,而链路聚合最多可将8个网卡汇聚同时做绑定,此聚合模式称之为team

team 四种模式

  • 广播容错:"broadcast"
  • 平衡轮询:"roundrobin"
  •     主备:"activebackup"
  • 负载均衡:"loadbalance"

team nmcli 界面窗口实现链路聚合

环境

  • 已添加网卡1 ens33
  • 已添加网卡2 ens34
  • 已添加网卡3 ens35
[root@localhost ~]# ifconfig
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.20  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::20c:29ff:fe1d:8469  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:1d:84:69  txqueuelen 1000  (Ethernet)
        RX packets 9  bytes 819 (819.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 31  bytes 4271 (4.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554968: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:1d:84:73  txqueuelen 1000  (Ethernet)
        RX packets 11  bytes 939 (939.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

eno50332192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:1d:84:7d  txqueuelen 1000  (Ethernet)
        RX packets 11  bytes 939 (939.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

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 0  (Local Loopback)
        RX packets 514  bytes 43660 (42.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 514  bytes 43660 (42.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

[root@localhost ~]# nm-connection-editor 

{"runner":{"name":"activebackup"}}

[root@localhost ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  eno16777728
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
  eno33554968
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
  eno50332192
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
runner:
  active port: eno16777728
[root@localhost ~]# ifconfig
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:1d:84:69  txqueuelen 1000  (Ethernet)
        RX packets 134009  bytes 9775632 (9.3 MiB)
        RX errors 0  dropped 133408  overruns 0  frame 0
        TX packets 137  bytes 15624 (15.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554968: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:1d:84:69  txqueuelen 1000  (Ethernet)
        RX packets 334  bytes 26564 (25.9 KiB)
        RX errors 0  dropped 10  overruns 0  frame 0
        TX packets 134607  bytes 9823318 (9.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno50332192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:1d:84:69  txqueuelen 1000  (Ethernet)
        RX packets 134310  bytes 9801759 (9.3 MiB)
        RX errors 0  dropped 134247  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        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 0  (Local Loopback)
        RX packets 806  bytes 69200 (67.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 806  bytes 69200 (67.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

team0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.10  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::20c:29ff:fe1d:8469  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:1d:84:69  txqueuelen 0  (Ethernet)
        RX packets 36  bytes 2132 (2.0 KiB)
        RX errors 0  dropped 14  overruns 0  frame 0
        TX packets 71  bytes 6369 (6.2 KiB)
        TX errors 0  dropped 2 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ping 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.119 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.099 ms
64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.100 ms
64 bytes from 192.168.10.10: icmp_seq=4 ttl=64 time=0.092 ms
64 bytes from 192.168.10.10: icmp_seq=5 ttl=64 time=0.092 ms
64 bytes from 192.168.10.10: icmp_seq=6 ttl=64 time=0.100 ms
64 bytes from 192.168.10.10: icmp_seq=7 ttl=64 time=0.095 ms
64 bytes from 192.168.10.10: icmp_seq=8 ttl=64 time=0.11

 


team nmcli 命令实现链路聚合

环境

  • 已添加网卡1 eno16777728
  • 已添加网卡2 eno33554968
  • 已添加网卡3 eno50332192

1、新建 team master 配置文件,选择模式为主备,并添加地址。

# nmcli connection add con-name 配置文件名称 type 模式类型 ifname 设备名称 config \'{"runner":{"name":"模式"}}\'
nmcli connection add con-name team0 type team ifname team0 config \'{"runner":{"name":"activebackup"}}\'

# nmcli connection modify 设备名称 ipv4.addresses "IP地址/掩码" connection.autoconnect 开启 ipv4.method 手动
nmcli connection modify team0 ipv4.addresses "192.168.10.10/24" connection.autoconnect yes ipv4.method manual

2、新建 team-slave 配置文件,添加给 team master

# nmcli connection add con-name 配置文件名称 ifname 设备名称 type 模式类型 master master设备名称
nmcli connection add con-name eth1 ifname eno16777728 type team-slave master team0 
nmcli connection add con
-name eth2 ifname eno33554968 type team-slave master team0
nmcli connection add con
-name eth3 ifname eno50332192 type team-slave master team0

3、启动已创建的网络设备

nmcli connection up team0
nmcli connection up eno16777728
nmcli connection up eno33554968
nmcli connection up eno50332192

4、查看详情

teamdctl team0 state

5、测试

ifconfig eno33554968 down

注:去掉一块网卡,可以看到网络依旧连通着。

以上是关于Linux 链路聚合的主要内容,如果未能解决你的问题,请参考以下文章

Linux 链路聚合

Linux7/Centos7新特性之链路聚合

Linux链路聚合

linux初学者-网卡的链路聚合篇

Linux进阶之链路聚合

Linux6/Centos6 聚合链路