TencentOS Server 网卡 Bond 绑定配置

如何在 TencentOS Server 4 上配置网卡 Bond(链路聚合),通过将多块物理网卡绑定为一个逻辑接口,实现网络带宽叠加或链路冗余。

相关产品
TencentOS Server 产品页,含版本规格、价格与购买入口。

一、概述

Bond 常用模式:

模式 名称 特点 适用场景
mode 0 balance-rr 轮询,负载均衡(需交换机支持聚合) 吞吐量最大化
mode 1 active-backup 主备,高可用 链路冗余
mode 2 balance-xor 基于哈希的负载均衡 负载均衡
mode 4 802.3ad (LACP) 动态链路聚合(需交换机支持 LACP) 高吞吐+冗余
mode 5 balance-tlb 自适应传输负载均衡 出口带宽均衡
mode 6 balance-alb 自适应负载均衡 双向带宽均衡

二、前提条件

·权限要求:root 权限

·多块网卡:至少 2 块物理网卡(本示例使用 eth0、eth1)

·若使用 mode 4(LACP),需要交换机端同步配置端口聚合组

注意:配置 Bond 过程中会修改网卡状态,若你正通过其中一块网卡以 SSH 方式连接服务器,存在连接中断的风险。建议你通过带外管理通道(如 BMC/IPMI 或云平台控制台)执行操作;若只能使用 SSH,请先保持多条独立连接,并避免断开正在使用的会话。

三、方法一:使用 NetworkManager(推荐)

TencentOS Server 4 默认使用 NetworkManager 管理网络,推荐使用 nmcli 命令配置。

四、步骤 1:创建 Bond 接口

# 创建名为 bond0 的 Bond 连接(mode 1: 主备模式)nmcli connection add type bond \\ con-name bond0 \\ ifname bond0 \\ bond.options "mode=active-backup,miimon=100"# LACP 模式(mode 4,需要交换机配置)nmcli connection add type bond \\ con-name bond0 \\ ifname bond0 \\ bond.options "mode=802.3ad,miimon=100,lacp_rate=fast"

五、步骤 2:添加成员网卡(Slave)

# 将 eth0 添加为 bond0 的 slavenmcli connection add type ethernet \\ con-name bond0-slave-eth0 \\ ifname eth0 \\ master bond0# 将 eth1 添加为 bond0 的 slavenmcli connection add type ethernet \\ con-name bond0-slave-eth1 \\ ifname eth1 \\ master bond0

六、步骤 3:配置 Bond 接口的 IP 地址

# 配置静态 IPnmcli connection modify bond0 \\ ipv4.addresses "192.168.1.100/24" \\ ipv4.gateway "192.168.1.1" \\ ipv4.dns "8.8.8.8,114.114.114.114" \\ ipv4.method manual# 或配置 DHCPnmcli connection modify bond0 ipv4.method auto

七、步骤 4:启用连接

# 启用 slave 连接nmcli connection up bond0-slave-eth0nmcli connection up bond0-slave-eth1# 启用 Bond 连接nmcli connection up bond0

八、步骤 5:关闭原网卡的独立 IP 连接(可选)

# 禁用 eth0、eth1 的独立连接(防止 IP 冲突)nmcli connection modify eth0 connection.autoconnect nonmcli connection modify eth1 connection.autoconnect no

九、Bond 主接口配置

编辑修改 vim /etc/NetworkManager/system-connections/bond0.nmconnection 文件,修改 type = bond。

[connection]id=bond0type=bondinterface-name=bond0autoconnect=yes[bond]mode=active-backupmiimon=100[ipv4]method=manualaddress1=192.168.1.100/24,192.168.1.1dns=8.8.8.8;114.114.114.114;[ipv6]method=ignore

Slave 网卡配置(eth0):

[connection]id=bond0-slave-eth0type=ethernetinterface-name=eth0master=bond0slave-type=bondautoconnect=yes

重新加载配置:

nmcli connection reloadnmcli connection up bond0

验证

# 查看 Bond 接口状态cat /proc/net/bonding/bond0# 查看网络连接状态nmcli connection show# 验证 IP 地址ip addr show bond0# 查看 Bond 成员状态ip link show

/proc/net/bonding/bond0 输出示例(active-backup 模式):

Ethernet Channel Bonding Driver: v5.15.0Bonding Mode: fault-tolerance (active-backup)Primary Slave: eth0 (primary_reselect failure)Currently Active Slave: eth0MII Status: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: eth0MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: xx:xx:xx:xx:xx:xxSlave queue ID: 0Slave Interface: eth1MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: xx:xx:xx:xx:xx:xxSlave queue ID: 0

十、常见问题

问题:mode 4(LACP)配置后流量仍集中在一块网卡

mode 4 的流量分配基于哈希算法(默认 layer2,即基于 MAC 地址),同一 TCP 会话的所有报文会通过同一成员链路传输。若需实现更细粒度的负载均衡,可调整哈希策略:

nmcli connection modify bond0 bond.options "mode=802.3ad,miimon=100,xmit_hash_policy=layer3+4"

layer3+4 基于 IP 和端口进行哈希,能更均匀地分配不同连接的流量。

问题:Bond 接口获取不到 DHCP 地址

检查成员网卡(eth0/eth1)的连接是否未启用独立 IP 配置:

nmcli connection show eth0 | grep autoconnect

问题:重启后 Bond 配置丢失

确认 NetworkManager 配置文件存在且正确:

ls /etc/NetworkManager/system-connections/nmcli connection reloadnmcli connection show

赞 (0)
上一篇 4天前
下一篇 4天前