交换机链路聚合配置指南
概述
本文档详细说明如何配置交换机链路聚合(LAG - Link Aggregation Group),将多条宽带线路通过交换机汇聚到单台服务器,实现带宽叠加和链路冗余。
网络拓扑
互联网
│
├─── 宽带1 (WAN1)
├─── 宽带2 (WAN2)
├─── 宽带3 (WAN3)
└─── 宽带4 (WAN4)
│
↓
┌─────────────┐
│ 交换机 │
│ (核心层) │
└─────────────┘
│
LAG1 (聚合)
(4条链路)
│
↓
┌─────────────┐
│ 服务器 │
└─────────────┘硬件准备
所需设备
- 企业级可网管交换机(支持LACP协议)
- 服务器(支持网卡绑定)
- 网线若干(建议Cat6或以上)
端口规划
- 交换机端口 1-4:连接宽带路由器
- 交换机端口 21-24:连接服务器(LAG1)
第一部分:交换机配置
1. 登录交换机
通过Console线或SSH登录交换机管理界面:
bash
# SSH登录示例
ssh admin@192.168.1.2542. 进入配置模式
bash
# 进入特权模式
enable
# 进入全局配置模式
configure terminal3. 配置VLAN(可选但推荐)
bash
# 创建管理VLAN
vlan 10
name Management
exit
# 创建服务器VLAN
vlan 20
name Server
exit
# 创建WAN VLAN
vlan 100
name WAN
exit4. 配置WAN端口(端口1-4)
bash
# 配置端口1(宽带1)
interface GigabitEthernet 0/1
description WAN1-Broadband1
switchport mode access
switchport access vlan 100
spanning-tree portfast
no shutdown
exit
# 配置端口2(宽带2)
interface GigabitEthernet 0/2
description WAN2-Broadband2
switchport mode access
switchport access vlan 100
spanning-tree portfast
no shutdown
exit
# 配置端口3(宽带3)
interface GigabitEthernet 0/3
description WAN3-Broadband3
switchport mode access
switchport access vlan 100
spanning-tree portfast
no shutdown
exit
# 配置端口4(宽带4)
interface GigabitEthernet 0/4
description WAN4-Broadband4
switchport mode access
switchport access vlan 100
spanning-tree portfast
no shutdown
exit5. 创建链路聚合组LAG1
bash
# 创建Port-Channel接口(LAG1)
interface Port-channel 1
description LAG1-to-Server
switchport mode trunk
switchport trunk allowed vlan 10,20,100
switchport trunk native vlan 20
no shutdown
exit6. 将物理端口加入LAG1
bash
# 配置端口21加入LAG1
interface GigabitEthernet 0/21
description Server-Link1
channel-group 1 mode active
channel-protocol lacp
no shutdown
exit
# 配置端口22加入LAG1
interface GigabitEthernet 0/22
description Server-Link2
channel-group 1 mode active
channel-protocol lacp
no shutdown
exit
# 配置端口23加入LAG1
interface GigabitEthernet 0/23
description Server-Link3
channel-group 1 mode active
channel-protocol lacp
no shutdown
exit
# 配置端口24加入LAG1
interface GigabitEthernet 0/24
description Server-Link4
channel-group 1 mode active
channel-protocol lacp
no shutdown
exit7. 配置LACP参数
bash
# 配置LACP系统优先级(数值越小优先级越高)
lacp system-priority 32768
# 进入Port-Channel接口配置LACP
interface Port-channel 1
lacp max-bundle 4
lacp min-links 2
exit8. 配置负载均衡算法
bash
# 配置基于源目标IP和端口的负载均衡
port-channel load-balance src-dst-ip-port
# 或者使用其他算法:
# port-channel load-balance src-dst-ip # 基于源目标IP
# port-channel load-balance src-dst-mac # 基于源目标MAC9. 保存配置
bash
# 退出配置模式
end
# 保存配置
write memory
# 或
copy running-config startup-config10. 验证配置
bash
# 查看Port-Channel状态
show etherchannel summary
show etherchannel 1 detail
# 查看LACP状态
show lacp neighbor
show lacp internal
# 查看端口状态
show interface Port-channel 1
show interface status
# 查看VLAN配置
show vlan brief第二部分:服务器端配置
Linux服务器配置(使用bonding)
1. 安装必要软件包
bash
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install ifenslave
# CentOS/RHEL
sudo yum install -y net-tools2. 加载bonding模块
bash
# 加载模块
sudo modprobe bonding
# 设置开机自动加载
echo "bonding" | sudo tee -a /etc/modules3. 配置网络接口
Ubuntu/Debian (使用netplan):
编辑 /etc/netplan/01-netcfg.yaml:
yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
eth1:
dhcp4: no
dhcp6: no
eth2:
dhcp4: no
dhcp6: no
eth3:
dhcp4: no
dhcp6: no
bonds:
bond0:
interfaces:
- eth0
- eth1
- eth2
- eth3
addresses:
- 192.168.20.100/24
routes:
- to: default
via: 192.168.20.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
parameters:
mode: 802.3ad # LACP模式
lacp-rate: fast # LACP快速模式
mii-monitor-interval: 100
transmit-hash-policy: layer3+4
min-links: 2应用配置:
bash
sudo netplan applyCentOS/RHEL (传统网络配置):
创建 /etc/sysconfig/network-scripts/ifcfg-bond0:
bash
DEVICE=bond0
TYPE=Bond
BONDING_MASTER=yes
BOOTPROTO=static
IPADDR=192.168.20.100
NETMASK=255.255.255.0
GATEWAY=192.168.20.1
DNS1=8.8.8.8
DNS2=8.8.4.4
ONBOOT=yes
BONDING_OPTS="mode=4 miimon=100 lacp_rate=fast xmit_hash_policy=layer3+4"配置物理接口 /etc/sysconfig/network-scripts/ifcfg-eth0:
bash
DEVICE=eth0
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes重复配置 eth1、eth2、eth3(修改DEVICE名称)。
重启网络服务:
bash
sudo systemctl restart network4. 验证bonding状态
bash
# 查看bonding状态
cat /proc/net/bonding/bond0
# 查看网络接口
ip addr show bond0
# 测试连通性
ping -c 4 192.168.20.1Windows服务器配置(使用NIC Teaming)
1. 打开服务器管理器
- 打开"服务器管理器"
- 点击"本地服务器"
- 找到"NIC组合",点击"已禁用"
2. 创建NIC组
- 在"NIC组合"窗口,点击"任务" → "新建组"
- 组名:
LAG1 - 选择要组合的网络适配器(4个网卡)
- 组合模式:选择"LACP"
- 负载均衡模式:选择"动态"
- 点击"确定"
3. 配置IP地址
- 右键点击新创建的组接口
- 选择"属性"
- 配置IPv4地址:
- IP地址:192.168.20.100
- 子网掩码:255.255.255.0
- 默认网关:192.168.20.1
- DNS服务器:8.8.8.8
4. 验证配置
powershell
# 查看NIC组状态
Get-NetLbfoTeam
# 查看组成员
Get-NetLbfoTeamMember
# 测试连通性
Test-Connection 192.168.20.1第三部分:高级配置
1. 配置流量监控
bash
# 在交换机上配置端口镜像
monitor session 1 source interface Port-channel 1
monitor session 1 destination interface GigabitEthernet 0/48
# 配置SNMP监控
snmp-server community public RO
snmp-server enable traps2. 配置QoS(服务质量)
bash
# 创建类映射
class-map match-all CRITICAL-TRAFFIC
match ip dscp ef
exit
# 创建策略映射
policy-map QOS-POLICY
class CRITICAL-TRAFFIC
priority percent 30
exit
# 应用到Port-Channel
interface Port-channel 1
service-policy output QOS-POLICY
exit3. 配置端口安全
bash
interface range GigabitEthernet 0/21-24
switchport port-security
switchport port-security maximum 2
switchport port-security violation restrict
switchport port-security mac-address sticky
exit故障排查
常见问题
1. LAG未建立
检查项:
bash
# 检查物理连接
show interface status
# 检查LACP协商
show lacp neighbor
# 检查配置
show running-config interface Port-channel 1解决方案:
- 确认所有物理端口都已启用(no shutdown)
- 确认服务器端也配置了LACP模式
- 检查网线连接是否正常
2. 部分链路未激活
检查项:
bash
# 查看哪些端口处于活动状态
show etherchannel summary解决方案:
- 检查未激活端口的物理连接
- 确认端口配置一致
- 检查LACP参数是否匹配
3. 带宽未叠加
检查项:
bash
# 查看负载均衡配置
show etherchannel load-balance
# 查看流量分布
show interface Port-channel 1 counters解决方案:
- 调整负载均衡算法
- 确认流量模式适合当前算法
- 考虑使用基于IP+端口的算法
4. 频繁断线
检查项:
bash
# 查看错误统计
show interface Port-channel 1 counters errors
# 查看日志
show logging | include Port-channel解决方案:
- 检查网线质量
- 更换有问题的端口
- 调整LACP超时参数
性能优化建议
1. 负载均衡算法选择
| 算法 | 适用场景 | 优点 | 缺点 |
|---|---|---|---|
| src-dst-ip | 多客户端访问 | 分布均匀 | 单客户端无法利用多链路 |
| src-dst-mac | 二层网络 | 简单高效 | 分布可能不均 |
| src-dst-ip-port | 多连接场景 | 最均衡 | 计算开销稍大 |
2. LACP参数调优
bash
# 快速LACP(1秒超时)
interface Port-channel 1
lacp rate fast
exit
# 慢速LACP(30秒超时,默认)
interface Port-channel 1
lacp rate normal
exit3. 最小链路数设置
bash
# 设置最少2条链路才激活LAG
interface Port-channel 1
lacp min-links 2
exit监控和维护
日常检查命令
bash
# 每日检查
show etherchannel summary
show interface Port-channel 1 | include rate
# 每周检查
show interface Port-channel 1 counters errors
show logging | include Port-channel
# 每月检查
show interface Port-channel 1 counters
show lacp statistics性能测试
bash
# 在服务器上使用iperf3测试
# 服务器端
iperf3 -s
# 客户端
iperf3 -c 192.168.20.100 -P 4 -t 60配置模板总结
交换机快速配置模板
bash
# 基础配置
enable
configure terminal
# 创建LAG
interface Port-channel 1
description LAG1-to-Server
no shutdown
exit
# 添加成员端口
interface range GigabitEthernet 0/21-24
channel-group 1 mode active
channel-protocol lacp
no shutdown
exit
# 配置负载均衡
port-channel load-balance src-dst-ip-port
# 保存配置
end
write memory服务器快速配置模板(Ubuntu)
yaml
# /etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
eth0: {dhcp4: no}
eth1: {dhcp4: no}
eth2: {dhcp4: no}
eth3: {dhcp4: no}
bonds:
bond0:
interfaces: [eth0, eth1, eth2, eth3]
addresses: [192.168.20.100/24]
routes:
- to: default
via: 192.168.20.1
parameters:
mode: 802.3ad
lacp-rate: fast
mii-monitor-interval: 100
transmit-hash-policy: layer3+4安全注意事项
- 访问控制:限制交换机管理接口访问
- 端口安全:启用MAC地址绑定
- VLAN隔离:使用VLAN隔离不同网络
- 日志审计:启用详细日志记录
- 定期备份:定期备份交换机配置
参考资料
- IEEE 802.3ad - Link Aggregation标准
- IEEE 802.1AX - Link Aggregation Control Protocol
- Linux Bonding驱动文档
- 交换机厂商配置指南
文档版本: 1.0
最后更新: 2026-04-26
维护者: 网络运维团队
