网卡链路聚合

链路聚合

1.链路聚合的介绍

网卡的链路聚合就是将多块网卡连接起来,当一块网卡损坏,网络依旧可以正常运行,可以有效的防止因为网卡损坏带来的损失,同时也可以提高网络访问速度。

网卡的链路聚合方式:

  • bond:最多可以添加两块网卡
  • team:最多可以添加八块网卡

bond的常用的2种模式:

  • bond0(balance-rr)
    • bond0用于负载轮询(2个网单独都是100MB,聚合为1个网络传输带宽为200MB)
  • bond1(active-backup)
    • bond1用于高可用,其中一条线若断线,其他线路将会自动备援

team的常用模式

  • roundrobin 负载轮询
  • activebackup 主备(必考)
  • loadbalance 负载均衡
  • broadcast 广播容错
  • lacp 需要交换机支持lacp协议

Team是基于一个小型内核驱动实现聚合链路,在用户层提供teamd命令实现链路管理。
使用teaming实现聚合链路,能够提供网卡绑定之后的网络吞吐性能,并且提供网卡的故障切换处理能力。

2.链路聚合配置

2.1 配置bond聚合链路

2.1.1 配置bond0
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION 
ens33   ethernet  已连接        ens33      
ens36   ethernet  已连接        ens36      
ens37   ethernet  已连接        ens37      
lo      loopback  连接(外部)  lo       
//创建bond0, 模式为balance-rr
[root@localhost ~]# nmcli connection add type bond mode balance-rr con-name bond0 ifname bond0 ipv4.method manual ipv4.addr 192.168.116.200/24 ipv4.gateway 192.168.116.2 ipv4.dns 114.114.114.114
连接 "bond0" (4f6213e9-44b3-4998-9b84-786d7b41806f) 已成功添加。
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION 
ens33   ethernet  已连接        ens33      
ens36   ethernet  已连接        ens36      
ens37   ethernet  已连接        ens37      
lo      loopback  连接(外部)  lo         
bond0   bond      已连接        bond0      
//添加物理网卡连接至bond0
[root@localhost ~]# nmcli connection add type bond-slave con-name bond-slave0 ifname ens36 master bond0
连接 "bond-slave0" (e21b2a63-2a56-47ff-9d23-bb896d70988c) 已成功添加。
[root@localhost ~]# nmcli connection add type bond-slave con-name bond-slave1 ifname ens37 master bond0
连接 "bond-slave1" (4d5ac747-0547-4bc7-adf1-eba08404348b) 已成功添加。
[root@localhost ~]# nmcli con
NAME         UUID                                  TYPE      DEVICE 
ens33        5144446b-02f9-3137-b291-29bd54c2257b  ethernet  ens33  
ens36        f97502c3-b676-3da8-b5af-226f9cc9e72a  ethernet  ens36  
ens37        064dedee-7e11-3187-b2fe-50a826df5435  ethernet  ens37  
lo           3a3b5850-003d-432a-8bcf-46b987a878e7  loopback  lo     
bond0        4f6213e9-44b3-4998-9b84-786d7b41806f  bond      bond0  
bond-slave0  e21b2a63-2a56-47ff-9d23-bb896d70988c  ethernet  --     
bond-slave1  4d5ac747-0547-4bc7-adf1-eba08404348b  ethernet  --     
//启用连接
[root@localhost ~]# nmcli connection up bond-slave0
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6)
[root@localhost ~]# nmcli connection up bond-slave1
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/7)
[root@localhost ~]# nmcli con
NAME         UUID                                  TYPE      DEVICE 
ens33        5144446b-02f9-3137-b291-29bd54c2257b  ethernet  ens33  
bond0        4f6213e9-44b3-4998-9b84-786d7b41806f  bond      bond0  
lo           3a3b5850-003d-432a-8bcf-46b987a878e7  loopback  lo     
bond-slave0  e21b2a63-2a56-47ff-9d23-bb896d70988c  ethernet  ens36  
bond-slave1  4d5ac747-0547-4bc7-adf1-eba08404348b  ethernet  ens37  
ens36        f97502c3-b676-3da8-b5af-226f9cc9e72a  ethernet  --     
ens37        064dedee-7e11-3187-b2fe-50a826df5435  ethernet  --     
//查看bond配置信息
[root@localhost ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v5.14.0-362.8.1.el9_3.x86_64

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens36
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:ed:2b:1a
Slave queue ID: 0

Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:ed:2b:24
Slave queue ID: 0
//关闭ens3网卡, 测试bond0是否正常
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION  
ens33   ethernet  已连接        ens33       
bond0   bond      已连接        bond0       
lo      loopback  连接(外部)  lo          
ens36   ethernet  已连接        bond-slave0 
ens37   ethernet  已连接        bond-slave1 
[root@localhost ~]# nmcli dev disconnect ens36
成功断开设备 "ens36"。
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION  
ens33   ethernet  已连接        ens33       
bond0   bond      已连接        bond0       
lo      loopback  连接(外部)  lo          
ens37   ethernet  已连接        bond-slave1 
ens36   ethernet  已断开        --          
[root@localhost ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v5.14.0-362.8.1.el9_3.x86_64

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:ed:2b:24
Slave queue ID: 0
[root@localhost ~]# ping 192.168.116.200
PING 192.168.116.200 (192.168.116.200) 56(84) 比特的数据。
64 比特,来自 192.168.116.200: icmp_seq=1 ttl=64 时间=0.050 毫秒
64 比特,来自 192.168.116.200: icmp_seq=2 ttl=64 时间=0.047 毫秒
64 比特,来自 192.168.116.200: icmp_seq=3 ttl=64 时间=0.056 毫秒
^C
--- 192.168.116.200 ping 统计 ---
已发送 3 个包, 已接收 3 个包, 0% packet loss, time 2071ms
rtt min/avg/max/mdev = 0.047/0.051/0.056/0.003 ms
2.1.2配置bond1
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION 
ens33   ethernet  已连接        ens33      
ens36   ethernet  已连接        ens36      
ens37   ethernet  已连接        ens37      
lo      loopback  连接(外部)  lo         
//创建bond1,模式为active-backup
[root@localhost ~]# nmcli connection add type bond con-name bond1 ifname bond1 mode active-backup ipv4.method manual ipv4.addr 192.168.116.250/24 ipv4.gateway 192.168.116.2 ipv4.dns 114.114.114.114
连接 "bond1" (25649193-df34-41c8-8ef6-5a02d7a1e505) 已成功添加。
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION 
ens33   ethernet  已连接        ens33      
ens36   ethernet  已连接        ens36      
ens37   ethernet  已连接        ens37      
lo      loopback  连接(外部)  lo         
bond1   bond      已连接        bond1      
//添加物理网卡连接至bond1
[root@localhost ~]# nmcli connection add type bond-slave con-name bond-slave0 ifname ens36 master bond1
连接 "bond-slave0" (60ebf05c-e537-474d-88a0-16408b4c298f) 已成功添加。
[root@localhost ~]# nmcli connection add type bond-slave con-name bond-slave1 ifname ens37 master bond1
连接 "bond-slave1" (5810f9cc-84a1-4201-92d4-1a5c47d19bf4) 已成功添加。
[root@localhost ~]# nmcli con
NAME         UUID                                  TYPE      DEVICE 
ens33        5144446b-02f9-3137-b291-29bd54c2257b  ethernet  ens33  
ens36        f97502c3-b676-3da8-b5af-226f9cc9e72a  ethernet  ens36  
ens37        064dedee-7e11-3187-b2fe-50a826df5435  ethernet  ens37  
lo           95dd6f56-dd91-48e7-9e31-b56bbadf1b74  loopback  lo     
bond1        25649193-df34-41c8-8ef6-5a02d7a1e505  bond      bond1  
bond-slave0  60ebf05c-e537-474d-88a0-16408b4c298f  ethernet  --     
bond-slave1  5810f9cc-84a1-4201-92d4-1a5c47d19bf4  ethernet  --     
//启用连接
[root@localhost ~]# nmcli con
NAME         UUID                                  TYPE      DEVICE 
ens33        5144446b-02f9-3137-b291-29bd54c2257b  ethernet  ens33  
ens36        f97502c3-b676-3da8-b5af-226f9cc9e72a  ethernet  ens36  
ens37        064dedee-7e11-3187-b2fe-50a826df5435  ethernet  ens37  
lo           95dd6f56-dd91-48e7-9e31-b56bbadf1b74  loopback  lo     
bond1        25649193-df34-41c8-8ef6-5a02d7a1e505  bond      bond1  
bond-slave0  60ebf05c-e537-474d-88a0-16408b4c298f  ethernet  --     
bond-slave1  5810f9cc-84a1-4201-92d4-1a5c47d19bf4  ethernet  --     
[root@localhost ~]# nmcli con up bond-slave0
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6)
[root@localhost ~]# nmcli con up bond-slave1
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/7)
[root@localhost ~]# nmcli con
NAME         UUID                                  TYPE      DEVICE 
ens33        5144446b-02f9-3137-b291-29bd54c2257b  ethernet  ens33  
bond1        25649193-df34-41c8-8ef6-5a02d7a1e505  bond      bond1  
lo           95dd6f56-dd91-48e7-9e31-b56bbadf1b74  loopback  lo     
bond-slave0  60ebf05c-e537-474d-88a0-16408b4c298f  ethernet  ens36  
bond-slave1  5810f9cc-84a1-4201-92d4-1a5c47d19bf4  ethernet  ens37  
ens36        f97502c3-b676-3da8-b5af-226f9cc9e72a  ethernet  --     
ens37        064dedee-7e11-3187-b2fe-50a826df5435  ethernet  --     
//验证
[root@localhost ~]# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-362.8.1.el9_3.x86_64

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens36
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens36
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:ed:2b:1a
Slave queue ID: 0

Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:ed:2b:24
Slave queue ID: 0
//停止eth0物理网卡设备
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION  
ens33   ethernet  已连接        ens33       
bond1   bond      已连接        bond1       
lo      loopback  连接(外部)  lo          
ens36   ethernet  已连接        bond-slave0 
ens37   ethernet  已连接        bond-slave1 
[root@localhost ~]# nmcli dev disconnect ens36
成功断开设备 "ens36"。
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION  
ens33   ethernet  已连接        ens33       
bond1   bond      已连接        bond1       
lo      loopback  连接(外部)  lo          
ens37   ethernet  已连接        bond-slave1 
ens36   ethernet  已断开        --          
//eth1物理网卡设备会进行自动切换
[root@localhost ~]# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-362.8.1.el9_3.x86_64

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens37
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:ed:2b:24
Slave queue ID: 0

2.2.配置team聚合链路

[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION 
ens33   ethernet  已连接        ens33      
ens36   ethernet  已连接        ens36      
ens37   ethernet  已连接        ens37      
lo      loopback  连接(外部)  lo         
//创建team,模式为主备(activebackup)
[root@localhost ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}' ipv4.addr 192.168.116.210/24 ipv4.gateway 192.168.116.2 ipv4.dns 114.114.114.114 ipv4.method manual
连接 "team0" (3d88b3fd-e528-4cff-840a-a62012080ac1) 已成功添加。
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION 
ens33   ethernet  已连接        ens33      
ens36   ethernet  已连接        ens36      
ens37   ethernet  已连接        ens37      
lo      loopback  连接(外部)  lo         
team0   team      已连接        team0      
//添加物理网卡连接至team0
[root@localhost ~]# nmcli connection add type team-slave con-name team0-slave0 ifname ens36 master team0
连接 "team0-slave0" (7fbb2294-d5d4-4c74-b07b-4a3e89ad0d9b) 已成功添加。
[root@localhost ~]# nmcli connection add type team-slave con-name team0-slave1 ifname ens37 master team0
连接 "team0-slave1" (5c61d096-01a0-4769-a351-fb2ae15076a8) 已成功添加。
[root@localhost ~]# nmcli con
NAME          UUID                                  TYPE      DEVICE 
ens33         5144446b-02f9-3137-b291-29bd54c2257b  ethernet  ens33  
ens36         f97502c3-b676-3da8-b5af-226f9cc9e72a  ethernet  ens36  
ens37         064dedee-7e11-3187-b2fe-50a826df5435  ethernet  ens37  
lo            19b0fcab-74b7-4824-b65f-3d7d80de830d  loopback  lo     
team0         3d88b3fd-e528-4cff-840a-a62012080ac1  team      team0  
team0-slave0  7fbb2294-d5d4-4c74-b07b-4a3e89ad0d9b  ethernet  --     
team0-slave1  5c61d096-01a0-4769-a351-fb2ae15076a8  ethernet  --     
//检查team0状态
[root@localhost ~]# ping -I team0 192.168.116.210
PING 192.168.116.210 (192.168.116.210) from 192.168.116.210 team0: 56(84) 比特的数据。
64 比特,来自 192.168.116.210: icmp_seq=1 ttl=64 时间=0.033 毫秒
64 比特,来自 192.168.116.210: icmp_seq=2 ttl=64 时间=0.045 毫秒
^C
--- 192.168.116.210 ping 统计 ---
已发送 2 个包, 已接收 2 个包, 0% packet loss, time 1062ms
rtt min/avg/max/mdev = 0.033/0.039/0.045/0.006 ms
[root@localhost ~]# teamdctl team0 state
setup:
  runner: activebackup
runner:
  active port: 
//激活网卡
[root@localhost ~]# nmcli con
NAME          UUID                                  TYPE      DEVICE 
ens33         5144446b-02f9-3137-b291-29bd54c2257b  ethernet  ens33  
ens36         f97502c3-b676-3da8-b5af-226f9cc9e72a  ethernet  ens36  
ens37         064dedee-7e11-3187-b2fe-50a826df5435  ethernet  ens37  
lo            19b0fcab-74b7-4824-b65f-3d7d80de830d  loopback  lo     
team0         3d88b3fd-e528-4cff-840a-a62012080ac1  team      team0  
team0-slave0  7fbb2294-d5d4-4c74-b07b-4a3e89ad0d9b  ethernet  --     
team0-slave1  5c61d096-01a0-4769-a351-fb2ae15076a8  ethernet  --     
[root@localhost ~]# nmcli con up team0-slave0
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6)
[root@localhost ~]# nmcli con up team0-slave1
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/7)
[root@localhost ~]# nmcli con
NAME          UUID                                  TYPE      DEVICE 
ens33         5144446b-02f9-3137-b291-29bd54c2257b  ethernet  ens33  
lo            19b0fcab-74b7-4824-b65f-3d7d80de830d  loopback  lo     
team0         3d88b3fd-e528-4cff-840a-a62012080ac1  team      team0  
team0-slave0  7fbb2294-d5d4-4c74-b07b-4a3e89ad0d9b  ethernet  ens36  
team0-slave1  5c61d096-01a0-4769-a351-fb2ae15076a8  ethernet  ens37  
ens36         f97502c3-b676-3da8-b5af-226f9cc9e72a  ethernet  --     
ens37         064dedee-7e11-3187-b2fe-50a826df5435  ethernet  --     
//再次检查team0状态
[root@localhost ~]# ping -I team0 192.168.116.210
PING 192.168.116.210 (192.168.116.210) from 192.168.116.210 team0: 56(84) 比特的数据。
64 比特,来自 192.168.116.210: icmp_seq=1 ttl=64 时间=0.040 毫秒
64 比特,来自 192.168.116.210: icmp_seq=2 ttl=64 时间=0.059 毫秒
^C
--- 192.168.116.210 ping 统计 ---
已发送 2 个包, 已接收 2 个包, 0% packet loss, time 1005ms
rtt min/avg/max/mdev = 0.040/0.049/0.059/0.009 ms
[root@localhost ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  ens36
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
  ens37
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: ens36
//断掉一个网卡后检测
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION   
ens33   ethernet  已连接        ens33        
lo      loopback  连接(外部)  lo           
team0   team      已连接        team0        
ens36   ethernet  已连接        team0-slave0 
ens37   ethernet  已连接        team0-slave1 
[root@localhost ~]# nmcli dev disconnect ens36
成功断开设备 "ens36"。
[root@localhost ~]# nmcli dev
DEVICE  TYPE      STATE         CONNECTION   
ens33   ethernet  已连接        ens33        
lo      loopback  连接(外部)  lo           
team0   team      已连接        team0        
ens37   ethernet  已连接        team0-slave1 
ens36   ethernet  已断开        --           
//再次检查当前状态和主网卡
[root@localhost ~]# ping -I team0 192.168.116.210
PING 192.168.116.210 (192.168.116.210) from 192.168.116.210 team0: 56(84) 比特的数据。
64 比特,来自 192.168.116.210: icmp_seq=1 ttl=64 时间=0.039 毫秒
64 比特,来自 192.168.116.210: icmp_seq=2 ttl=64 时间=0.122 毫秒
^C
--- 192.168.116.210 ping 统计 ---
已发送 2 个包, 已接收 2 个包, 0% packet loss, time 1041ms
rtt min/avg/max/mdev = 0.039/0.080/0.122/0.041 ms
[root@localhost ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  ens37
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
runner:
  active port: ens37
  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值