本文主要是介绍bond聚合和team聚合,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
链路聚合
网卡的链路聚合就是将多块网卡连接起来,当一块网卡损坏,网络依旧可以正常运行,可以有效的防止因为网卡损坏带来的损失,同时也可以提高网络访问速度。
网卡的链路聚合方式:
bond:最多可以添加两块网卡
team:最多可以添加八块网卡
bond的常用的2种模式:
bond0(balance-rr)
bond0用于负载轮询(2个网单独都是100MB,聚合为1个网络传输带宽为200MB)
bond1(active-backup)
bond1用于高可用,其中一条线若断线,其他线路将会自动备援
--> eth0 ----\app --发送数据到--> bond0 <---> switch --> eth1 ----/
链路聚合配置
bond聚合
bond0test
[root@cjy ~]# nmcli device
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens192 ethernet connected Wired connection 1
ens224 ethernet connected Wired connection 2
lo loopback connected (externally) lo
创建bond0, 模式为balance-rr
[root@cjy ~]# nmcli connection add type bond mode balance-rr con-name bond0 ifname bond0 ipv4.method manual ipv4.addresses 192.168.159.250/24 ipv4.gateway 192.168.159.2 ipv4.dns 192.168.159.2
Connection 'bond0' (2715a7c6-668b-4487-9be1-733a7eb04bd0) successfully added.
添加物理网卡连接至bond0
[root@cjy ~]# nmcli connection add type bond-slave con-name bond-slave0 ifname ens192 master bond0
Connection 'bond-slave0' (c9e7e854-4208-403e-8d56-d90da7d645a2) successfully added.
[root@cjy ~]# nmcli connection add type bond-slave con-name bond-slave1 ifname ens224 master bond0
Connection 'bond-slave1' (2923a403-6998-45fb-b9f6-7fe467b514e8) successfully added.
激活bond-slave0和bond-slave1
[root@cjy ~]# nmcli connection up bond-slave0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
[root@cjy ~]# nmcli connection up bond-slave1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
查看bond配置信息
[root@cjy ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v5.14.0-362.8.1.el9_3.x86_64Bonding 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): 0Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:b5:d1:27
Slave queue ID: 0Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:b5:d1:31
Slave queue ID: 0再删除bond0
[root@cjy ~]# nmcli connection down bond-slave0
Connection 'bond-slave0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
[root@cjy ~]# nmcli connection down bond-slave1
Connection 'bond-slave1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
[root@cjy ~]# nmcli connection
NAME UUID TYPE DEVICE
ens160 5be8f7d1-83b5-3896-8dad-4ea38657f2ab ethernet ens160
bond0 2715a7c6-668b-4487-9be1-733a7eb04bd0 bond bond0
lo 4590f7d0-9e56-4359-98e8-300780d6cacc loopback lo
Wired connection 1 b1db212b-4873-3c5c-a19d-e2163242e0fb ethernet ens192
Wired connection 2 d0109af2-61dd-3e43-96b9-5ee112e9935a ethernet ens224
bond-slave0 c9e7e854-4208-403e-8d56-d90da7d645a2 ethernet --
bond-slave1 2923a403-6998-45fb-b9f6-7fe467b514e8 ethernet --
[root@cjy ~]# nmcli connection delete bond-slave0
Connection 'bond-slave0' (c9e7e854-4208-403e-8d56-d90da7d645a2) successfully deleted.
[root@cjy ~]# nmcli connection delete bond-slave1
Connection 'bond-slave1' (2923a403-6998-45fb-b9f6-7fe467b514e8) successfully deleted.
[root@cjy ~]# nmcli connection down bond0
Connection 'bond0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@cjy ~]# nmcli connection delete bond0
Connection 'bond0' (2715a7c6-668b-4487-9be1-733a7eb04bd0) successfully deleted.
bond1
[root@cjy ~]# nmcli device
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens192 ethernet connected Wired connection 1
ens224 ethernet connected Wired connection 2
lo loopback connected (externally) lo
创建bond1,模式为active-backup
[root@cjy ~]# nmcli connection add type bond con-name bond1 ifname bond1 mode active-backup ipv4.method manual ipv4.addresses 192.168.159.250/24 ipv4.gateway 192.168.159.2 ipv4.dns 192.168.159.2
Connection 'bond1' (69ce3544-e374-48a8-9ce2-5f02a7eb4729) successfully added.
添加物理网卡连接至bond1
[root@cjy ~]# nmcli connection add type bond-slave con-name bond-slave0 ifname ens192 master bond1
Connection 'bond-slave0' (d7b44509-8d0c-4771-9449-105d68269e76) successfully added.
[root@cjy ~]# nmcli connection add type bond-slave con-name bond-slave1 ifname ens224 master bond1
Connection 'bond-slave1' (258a0f19-5b2e-48a5-926f-b9896fcdbb03) successfully added.
启用连接
[root@cjy ~]# nmcli connection up bond1
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)
[root@cjy ~]# nmcli connection up bond-slave0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)
[root@cjy ~]# nmcli connection up bond-slave1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)
查看验证
[root@cjy ~]# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-362.8.1.el9_3.x86_64Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens192
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:b5:d1:27
Slave queue ID: 0Slave Interface: ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:b5:d1:31
Slave queue ID: 0停止ens224会自动切换
[root@cjy ~]# nmcli device disconnect ens224
Device 'ens224' successfully disconnected.
[root@cjy ~]# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-362.8.1.el9_3.x86_64Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens192
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0Slave Interface: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:b5:d1:27
Slave queue ID: 0再删除bond1
[root@cjy ~]# nmcli connection
NAME UUID TYPE DEVICE
ens160 5be8f7d1-83b5-3896-8dad-4ea38657f2ab ethernet ens160
bond1 69ce3544-e374-48a8-9ce2-5f02a7eb4729 bond bond1
lo 4590f7d0-9e56-4359-98e8-300780d6cacc loopback lo
bond-slave0 d7b44509-8d0c-4771-9449-105d68269e76 ethernet ens192
bond-slave1 258a0f19-5b2e-48a5-926f-b9896fcdbb03 ethernet --
Wired connection 1 b1db212b-4873-3c5c-a19d-e2163242e0fb ethernet --
Wired connection 2 d0109af2-61dd-3e43-96b9-5ee112e9935a ethernet --
[root@cjy ~]# nmcli connection delete bond-slave0
Connection 'bond-slave0' (d7b44509-8d0c-4771-9449-105d68269e76) successfully deleted.
[root@cjy ~]# nmcli connection delete bond-slave1
Connection 'bond-slave1' (258a0f19-5b2e-48a5-926f-b9896fcdbb03) successfully deleted.
[root@cjy ~]# nmcli connection delete bond1
Connection 'bond1' (69ce3544-e374-48a8-9ce2-5f02a7eb4729) successfully deleted.
[root@cjy ~]# nmcli connection
NAME UUID TYPE DEVICE
ens160 5be8f7d1-83b5-3896-8dad-4ea38657f2ab ethernet ens160
lo 4590f7d0-9e56-4359-98e8-300780d6cacc loopback lo
Wired connection 1 b1db212b-4873-3c5c-a19d-e2163242e0fb ethernet ens192
Wired connection 2 d0109af2-61dd-3e43-96b9-5ee112e9935a ethernet --
team聚合
创建team0
[root@cjy ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}' ipv4.addresses 192.168.159.250/24 ipv4.gateway 192.168.159.2 ipv4.dns 192.168.159.2 ipv4.method manual
Connection 'team0' (6ba01058-a3ff-491a-be20-9c4457571e39) successfully added.
添加物理网卡连接至team0
[root@cjy ~]# nmcli connection add type team-slave con-name team0-port1 ifname ens192 master team0
Connection 'team0-port1' (79f875f8-5740-458b-b406-9525c13f8b09) successfully added.
[root@cjy ~]# nmcli connection add type team-slave con-name team0-port2 ifname ens224 master team0
Connection 'team0-port2' (6b6a1dd0-7651-4fb0-b77f-793e785bdf0e) successfully added.
[root@cjy ~]# nmcli connection down "Wired connection 1"
Connection 'Wired connection 1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/17)
[root@cjy ~]# nmcli connection down "Wired connection 2"
Connection 'Wired connection 2' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/16)
检查team0状态
[root@cjy ~]# ping -I team0 192.168.159.250
PING 192.168.159.250 (192.168.159.250) from 192.168.159.250 team0: 56(84) bytes of data.
64 bytes from 192.168.159.250: icmp_seq=1 ttl=64 time=0.096 ms
64 bytes from 192.168.159.250: icmp_seq=2 ttl=64 time=0.122 ms
64 bytes from 192.168.159.250: icmp_seq=3 ttl=64 time=0.198 ms
64 bytes from 192.168.159.250: icmp_seq=4 ttl=64 time=0.256 ms
64 bytes from 192.168.159.250: icmp_seq=5 ttl=64 time=0.087 ms
64 bytes from 192.168.159.250: icmp_seq=6 ttl=64 time=0.245 ms
^C
--- 192.168.159.250 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5154ms
rtt min/avg/max/mdev = 0.087/0.167/0.256/0.068 ms
查看
[root@cjy ~]# teamdctl team0 state
setup:runner: activebackup
ports:ens192link watches:link summary: upinstance[link_watch_0]:name: ethtoollink: updown count: 0ens224link watches:link summary: upinstance[link_watch_0]:name: ethtoollink: updown count: 0
runner:active port: ens192
断掉后检测
[root@cjy ~]# nmcli device disconnect ens224
Device 'ens224' successfully disconnected.
[root@cjy ~]# teamdctl team0 state
setup:runner: activebackup
ports:ens192link watches:link summary: upinstance[link_watch_0]:name: ethtoollink: updown count: 0
runner:active port: ens192
动态修改team模式
[root@cjy ~]# teamdctl team0 config dump > team.conf
[root@cjy ~]# vi team.conf
[root@cjy ~]# cat team.conf
{"device": "team0","mcast_rejoin": {"count": 1},"notify_peers": {"count": 1},"ports": {"ens192": {"link_watch": {"name": "ethtool"}},"ens224": {"link_watch": {"name": "ethtool"}}},"runner": {"name": "loadbalance"}
}
以最新修改的配置选项修改team0属性
[root@cjy ~]# nmcli connection modify team0 team.config team.conf
修改之后需要重启team0
[root@cjy ~]# nmcli connection
NAME UUID TYPE DEVICE
ens160 5be8f7d1-83b5-3896-8dad-4ea38657f2ab ethernet ens160
lo 4590f7d0-9e56-4359-98e8-300780d6cacc loopback lo
team0 6ba01058-a3ff-491a-be20-9c4457571e39 team team0
team0-port1 79f875f8-5740-458b-b406-9525c13f8b09 ethernet ens192
team0-port2 6b6a1dd0-7651-4fb0-b77f-793e785bdf0e ethernet ens224
Wired connection 1 b1db212b-4873-3c5c-a19d-e2163242e0fb ethernet --
Wired connection 2 d0109af2-61dd-3e43-96b9-5ee112e9935a ethernet --
[root@cjy ~]# nmcli connection down team0
Connection 'team0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/22)
[root@cjy ~]# nmcli connection up team0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/24)
查看是否成功
[root@cjy ~]# teamdctl team0 state
setup:runner: loadbalance
ports:ens192link watches:link summary: upinstance[link_watch_0]:name: ethtoollink: updown count: 0ens224link watches:link summary: upinstance[link_watch_0]:name: ethtoollink: updown count: 0
这篇关于bond聚合和team聚合的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!