内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。
本文档详细介绍网卡绑定(Bonding)
风哥提示:
和链路聚合的配置方法,实现网络高可用和负载均衡。
Part01-网卡绑定模式
1.1 绑定模式说明
# mode=0 (balance-rr): 轮询模式,提供负载均衡和容错
# mode=1 (active-backup): 主备模式,只有一个网卡活动
# mode=2 (balance-xor): 基于MAC地址的负载均衡
# mode=3 (broadcast): 广播模式,所有网卡都发送数据
# mode=4 (802.3ad): LACP动态链路聚合
# mode=5 (balance-tlb): 发送负载均衡
# mode=6 (balance-alb): 发送和接收负载均衡
# 常用模式
# mode=1: 主备模式,适合高可用场景
# mode=4: LACP模式,需要交换机支持
# mode=6: 负载均衡模式,无需交换机配置
Part02-配置网卡绑定
2.1 创建绑定接口
$ nmcli device status
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected eth0
eth1 ethernet connected eth1
eth2 ethernet disconnected —
eth3 ethernet disconnected —
lo loopback unmanaged —
# 创建绑定接口
$ sudo nmcli connection add type bond \
con-name bond0 \
ifname bond0 \
mode active-backup
Connection ‘bond0’ (abc12345-1234-5678-90ab-cdef12345678) successfully added.
# 添加从属接口
$ sudo nmcli connection add type bond-slave \
con-name bond0-port1 \
ifname eth2 \
master bond0
Connection ‘bond0-port1’ (def23456-2345-6789-01bc-defg23456789) successfully added.
$ sudo nmcli connection add type bond-slave \
con-name bond0-port2 \
ifname eth3 \
master bond0
Connection ‘bond0-port2’ (efg34567-3456-7890-12cd-efgh34567890) successfully added.
# 配置绑定接口IP地址
$ sudo nmcli connection modify bond0 \
ip学习交流加群风哥QQ113257174v4.addresses 192.168.1.200/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns “8.8.8.8” \
ipv4.method manual
# 激活绑定接口
$ sudo nmcli connection up bond0-port1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
$ sudo nmcli connection up bond0-port2
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)
$ sudo nmcli connection up bond0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)
Part03-验证绑定配置
3.1 查看绑定状态
$ ip addr show bond0
4: bond0:
link/ether 08:00:27:ab:cd:ef brd ff:ff:ff:ff:ff:ff
inet 192.168.1.200/24 brd 192.168.1.255 scope global noprefixroute bond0
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:feab:cdef/64 scope link
valid_lft forever preferred_lft forever
# 查看绑定详细信息
$ cat /proc/net/bonding/bond0
Ethernet更多学习教程公众号风哥教程itpux_com Channel Bonding Driver: v5.14.0-284.11.1.el9_2.x86_64
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:12:34:56
Slave queue ID: 0
Slave Interface: eth3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:ab:cd:ef
Slave queue ID: 0
# 查看连接状态
$ nmcli device status
DEVICE TYPE STATE CONNECTION
bond0 bond connected bond0
eth0 ethernet connected eth0
eth1 ethernet connected eth1
eth2 ethernet connected bond0-port1
eth3 ethernet connected bond0-port2
lo loopback unmanaged —
Part04-LACP链路聚合
4.1 配置LACP模式
$ sudo nmcli connection add type bond \
con-name bond1 \
ifname bond1 \
mode 802.3ad
Connection ‘bond1’ (fgh45678-4567-8901-23de-fghi45678901) successfully added.
# 配置LACP参数
$ sudo nmcli connection modify bond1 \
bond.options “mode=802.3ad,miimon=100,lacp_rate=fast,xmit_hash_policy=layer2+3”
# 添加从属接口
$ sudo nmcli connection add type bond-slave \
con-name bond1-port1 \
ifname eth4 \
master bond1
$ sudo nmcli connection add type bond-slave \
con-name bond1-port2 \
ifname eth5 \
master bond1
# 配置IP地址
$ sudo nmcli connection modify bond1 \
ipv4.addresses 192.168.2.100/24 \
ipv4.method manual
# 激活连接
$ sudo nmcli connection up bond1-port1
$ sudo nmcli connection up bond1-port2
$ sudo nmcli connection up bond1
# 验证LACP配置
$ cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-284.11.1.el9_2.x86_64
Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2+3 (2)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
802.3ad info
LACP rate: fast
Min links: 0
Aggregator selection policy (ad_select): stable
System priority: 65535
System MAC address: 08:00:27:ab:cd:ef
Active Aggregator Info:
Aggregator ID: 1
Number of ports: 2
Actor Key: 9
Partner Key: 1
Partner Mac Address: 00:11:22:33:44:55
Slave Interface: eth4
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:12:34:56
Slave queue ID: 0
Aggregator ID: 1
Actor Churn State: none
Partner Churn State: none
Actor Churned Count: 0
Partner Churned Count: 0
Slave Interface: eth5
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:ab:cd:ef
Slave queue ID: 0
Aggregator ID: 1
Actor Churn State: none
Partner Churn State: none
Actor Churned Count: 0
Partner Churned Count: 0
Part05-故障切换测试
5.1 测试主备切换
$ cat /proc/net/bonding/bond0 | grep “Currently Active Slave”
Currently Active Slave: eth2
# 模拟接口故障
$ sudo ip link set eth2 down
# 查看切换后的活动接口
$ cat /proc/net/bonding/bond0 | grep “Currently Active Slave”
Currently Active Slave: eth3
# 查看故障计数
$ cat /proc/net/bonding/bond0 | grep “Link Failure Count”
Link Failure Count: 1
Link Failure Count: 0
from PG视频:www.itpux.com
# 恢复接口
$ sudo ip link set eth2 up
# 验证网络连通性
$ ping -c 3 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.更多视频教程www.fgedu.net.cn
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.521 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.489 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.512 ms
— 192.168.1.1 ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2049ms
rtt min/avg/max/mdev = 0.489/0.507/0.521/0.013 ms
1. 生产环境推荐使用mode=1主备模式
2. LACP模式需要交换机支持802.3ad
3. 定期测试故障切换功能
4. 监控绑定接口状态
5. 配置合适的miimon参数检测链路状态
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
