1. 程式人生 > >Linux 鏈路聚合

Linux 鏈路聚合

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

 

注:去掉一塊網絡卡,可以看到網路依舊連通