链路聚合(Link Aggregation):把多条物理链路捆绑成一条逻辑链路,带宽倍增、可靠性提升、负载分担。
一、为什么需要链路聚合
- 增加带宽:N 条聚合后逻辑带宽接近 N 倍(略小于各成员之和)
- 提高可靠性:任一接口故障,其余自动接替,流量不中断
- 负载分担:数据在多条链路上传输,避免单条拥塞
二、链路聚合基本概念
2.1 核心术语
| 概念 | 说明 |
|---|---|
| 聚合组(LAG) | Link Aggregation Group,华为称为 Eth-Trunk |
| 成员接口 | 加入聚合组的物理接口 |
| 聚合模式 | 手工模式 / LACP 模式 |
| 活跃接口 | 被选中参与数据转发的成员接口 |
| 非活跃接口 | 处于备份状态、不参与数据转发的成员接口 |
2.2 链路聚合的前提条件
| 条件 | 说明 |
|---|---|
| 接口数量一致 | 两端物理接口数量完全相同 |
| 双工模式一致 | 同为全双工或同为半双工 |
| 速率一致 | 所有成员接口速率相同 |
| 流控配置一致 | 两端流控配置相同 |
| 聚合模式一致 | 两端同为手工模式或同为 LACP 模式 |
| 接口无配置 | 加入聚合组前,成员接口不能有独立配置 |
聚合接口不能嵌套:一个 Eth-Trunk 不能再加入另一个 Eth-Trunk。
三、手工模式
3.1 工作原理
- 成员接口加入后立即成为活跃接口
- 默认按源目 IP 异或做负载分担
- 无需协议协商,配置简单,但没有链路状态检测
3.2 配置步骤
# 方式一:在 Eth-Trunk 接口下添加成员
[SW1] interface Eth-Trunk 0
[SW1-Eth-Trunk0] trunkport GigabitEthernet 0/0/1 to 0/0/2
# 方式二:在物理接口下加入 Eth-Trunk
[SW2] interface GigabitEthernet 0/0/1
[SW2-GigabitEthernet0/0/1] eth-trunk 0
[SW2-GigabitEthernet0/0/1] quit
[SW2] interface GigabitEthernet 0/0/2
[SW2-GigabitEthernet0/0/2] eth-trunk 0
3.3 完整配置示例
拓扑:
SW1 ════ Eth-Trunk 1(GE0/0/1 + GE0/0/2)════ SW2
# ============ SW1 配置 ============
[SW1] interface Eth-Trunk 0
[SW1-Eth-Trunk0] trunkport GigabitEthernet 0/0/1 to 0/0/2
[SW1-Eth-Trunk0] port link-type trunk
[SW1-Eth-Trunk0] port trunk allow-pass vlan 10 to 20
[SW1-Eth-Trunk0] quit
[SW1] vlan batch 10 to 20
# ============ SW2 配置 ============
[SW2] vlan batch 10 to 20
[SW2] interface Eth-Trunk 0
[SW2-Eth-Trunk0] trunkport GigabitEthernet 0/0/1 to 0/0/2
[SW2-Eth-Trunk0] port link-type trunk
[SW2-Eth-Trunk0] port trunk allow-pass vlan 10 to 20
# ============ 验证 ============
display eth-trunk 0
display interface Eth-Trunk 0
display trunkmembership eth-trunk 0
加入后配置都在 Eth-Trunk 接口下做(trunk、access、IP 等);成员接口加入前不能有独立配置,否则报错
The port has other configurations. Please clear them first.
四、LACP 模式(802.3ad)
4.1 协议概述
LACP:IEEE 802.3ad 链路聚合控制协议,相比手工模式多出:
- 链路状态检测:靠 LACPDU 报文维护状态
- 自动协商:两端自动协商聚合参数
- 活跃接口选举:支持最大活跃接口数限制
- 故障切换:活跃接口故障后自动从备选激活
4.2 系统优先级与接口优先级
系统 LACP 优先级(越小越优)
↓ 决定主动端
接口 LACP 优先级(越小越优)
↓ 决定活跃接口选举
接口编号(越小越优)
4.3 LACP 聚合建立过程
1. 成员接口加入 Eth-Trunk → 两端相互发送 LACPDU 报文
2. 比较系统优先级 → 优先级高(数值小)的一端成为主动端
(若优先级相同,比较 MAC 地址,MAC 小的成为主动端)
3. 选出主动端后,两端均按主动端的接口优先级选择活跃接口
(若优先级相同,接口编号较小的优先)
两端所选的活跃接口必须一致。
4.4 LACP 静态模式 vs 动态模式
| 模式 | Eth-Trunk 建立 | 成员加入 | 活跃接口选举 | 管理员参与 |
|---|---|---|---|---|
| 静态 LACP | 手动配置 | 手动配置 | LACP 协议 | 允许 |
| 动态 LACP | LACP 协议自动 | LACP 协议自动 | LACP 协议 | 不允许 |
华为设备常用静态 LACP 模式(
mode lacp-static)。
五、LACP 模式配置
5.1 基础 LACP 配置
场景:SW1、SW2 之间 4 条链路聚合,只允许 2 条活跃。
# ============ SW1 配置 ============
# 创建 Eth-Trunk 并设置模式
[SW1] interface Eth-Trunk 0
[SW1-Eth-Trunk0] mode lacp-static
[SW1-Eth-Trunk0] trunkport GigabitEthernet 0/0/1 to 0/0/4
[SW1-Eth-Trunk0] max active-linknumber 2 # 最大活跃接口数
[SW1-Eth-Trunk0] quit
# 设置系统优先级(使 SW1 成为主动端)
[SW1] lacp priority 100
# 设置接口优先级(GE0/0/1、GE0/0/2 优先成为活跃接口)
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] lacp priority 100
[SW1-GigabitEthernet0/0/1] quit
[SW1] interface GigabitEthernet 0/0/2
[SW1-GigabitEthernet0/0/2] lacp priority 100
[SW1-GigabitEthernet0/0/2] quit
# ============ SW2 配置 ============
[SW2] interface Eth-Trunk 0
[SW2-Eth-Trunk0] mode lacp-static
[SW2-Eth-Trunk0] trunkport GigabitEthernet 0/0/1 to 0/0/4
[SW2-Eth-Trunk0] quit
# ============ 验证 ============
display eth-trunk 0
验证输出:
[SW1] display eth-trunk 0
Eth-Trunk0's state information is:
Local:
LAG ID: 0 WorkingMode: STATIC
Preempt Delay Time: 10 Hash arithmetic: According to SIP-XOR-DIP
System Priority: 100 System ID: 4c1f-ccc8-7da9
Least Active-linknumber: 1 Max Active-linknumber: 2
Operate status: up Number Of Up Port In Trunk: 2
--------------------------------------------------------------------------------
ActorPortName Status PortType PortPri PortNo PortKey PortState Weight
GigabitEthernet0/0/1 Selected 1GE 100 2 49 10111100 1
GigabitEthernet0/0/2 Selected 1GE 100 3 49 10111100 1
GigabitEthernet0/0/3 Unselect 1GE 32768 4 49 10100000 1
GigabitEthernet0/0/4 Unselect 1GE 32768 5 49 10100000 1
GE0/0/1、GE0/0/2 优先级高(100 < 32768)被选为活跃(Selected),GE0/0/3、GE0/0/4 为备选(Unselect)。
5.2 LACP 抢占配置
活跃接口故障恢复后可抢占回活跃:
# 在 Eth-Trunk 接口下启用抢占
[SW1] interface Eth-Trunk 0
[SW1-Eth-Trunk0] lacp preempt enable
# 设置抢占延迟(秒)
[SW1-Eth-Trunk0] lacp preempt delay 10
抢占延迟避免链路抖动导致频繁切换。
5.3 配置流程最佳实践
第 1 步:创建 Eth-Trunk 接口并设置模式
第 2 步:设置 LACP 系统优先级(确定主动端)
第 3 步:将物理接口加入 Eth-Trunk
第 4 步:设置最大活跃接口数
第 5 步:设置接口优先级(确定哪些接口优先活跃)
第 6 步:配置 Eth-Trunk 的业务属性(Trunk/Access/IP 等)
第 7 步:启用抢占和设置抢占延迟
六、负载分担
6.1 基于流的负载分担
链路聚合按**流(Flow)**分担,而非逐包——逐包会导致数据包乱序。
五元组(源/目的 IP、源/目的端口、协议号)相同即同一条流,走同一条链路。
6.2 华为设备默认方式
华为默认按源目 IP 异或(SIP-XOR-DIP)区分流。
6.3 修改负载分担方式
[SW2-Eth-Trunk1] load-balance ?
dst-ip 根据目的 IP 哈希
dst-mac 根据目的 MAC 哈希
src-dst-ip 根据源/目的 IP 哈希
src-dst-mac 根据源/目的 MAC 哈希
src-ip 根据源 IP 哈希
src-mac 根据源 MAC 哈希
# 例如:修改为根据源目 IP 哈希
[SW2-Eth-Trunk1] load-balance src-dst-ip
七、三层链路聚合
Eth-Trunk 同样能用在三层路由器上。
7.1 切换为三层接口
# 将 Eth-Trunk 切换为三层接口
[Router] interface Eth-Trunk 0
[Router-Eth-Trunk0] undo portswitch
# 配置 IP 地址
[Router-Eth-Trunk0] ip address 10.0.0.1 24
# 添加成员接口
[Router-Eth-Trunk0] trunkport GigabitEthernet 0/0/1 to 0/0/2
7.2 三层链路聚合场景
[R1] ════ Eth-Trunk(IP: 10.0.0.0/30)════ [R2]
│
GE0/0/1 + GE0/0/2 捆绑
# R1 配置
[R1] interface Eth-Trunk 1
[R1-Eth-Trunk1] undo portswitch
[R1-Eth-Trunk1] ip address 10.0.0.1 30
[R1-Eth-Trunk1] mode lacp-static
[R1-Eth-Trunk1] trunkport GigabitEthernet 0/0/1 to 0/0/2
# R2 配置
[R2] interface Eth-Trunk 1
[R2-Eth-Trunk1] undo portswitch
[R2-Eth-Trunk1] ip address 10.0.0.2 30
[R2-Eth-Trunk1] mode lacp-static
[R2-Eth-Trunk1] trunkport GigabitEthernet 0/0/1 to 0/0/2
八、查看与排错命令
8.1 常用查看命令
# 查看 Eth-Trunk 详细信息
display eth-trunk [编号]
# 查看 Eth-Trunk 接口状态
display interface Eth-Trunk [编号]
# 查看 Eth-Trunk 成员信息
display trunkmembership eth-trunk [编号]
# 查看 LACP 统计信息
display lacp statistics eth-trunk [编号]
8.2 常见问题排查
| 现象 | 可能原因 | 排查方法 |
|---|---|---|
| 聚合口无法 Up | 两端物理接口数量不一致 | display eth-trunk 查看成员状态 |
| 成员接口加入失败 | 接口有残留配置 | 先 clear configuration this 清空接口配置 |
| 部分接口未激活 | 最大活跃接口数限制 | display eth-trunk 查看 Selected/Unselect |
| 两端活跃接口不一致 | LACP 主动端选举问题 | 检查系统优先级和 MAC 地址 |
| 流量不均衡 | 哈希算法不适合业务 | 调整 load-balance 模式 |
| LACPDU 不通 | VLAN/Trunk 配置问题 | 确保两端接口的 L2 连通性 |
九、手工模式 vs LACP 模式对比
| 特性 | 手工模式 | LACP 模式 |
|---|---|---|
| 协议开销 | 无 | LACPDU 报文交互 |
| 链路检测 | 仅物理层 | 物理层 + 协议层 |
| 活跃接口控制 | 全部活跃 | 支持最大活跃接口数限制 |
| 故障切换 | 物理 up/down 感知 | 协议快速感知 + 自动切换 |
| 配置复杂度 | 低 | 中 |
| 推荐场景 | 简单环境 | 企业生产环境 |
十、设计最佳实践
- 优先 LACP 静态模式(有协议级链路检测)
- 活跃数规划:
max active-linknumber限制活跃链路,其余作备份 - 优先级:系统优先级定主动端,接口优先级定活跃链路
- 统一入口:所有配置在 Eth-Trunk 接口下执行
- 负载分担:按业务流量选
load-balance模式 - 三层聚合:先
undo portswitch