第21篇:链路聚合 Eth-Trunk:手工模式与 LACP 模式

关键词:链路聚合、Eth-Trunk、LACP、手工负载分担、链路备份、802.3ad


一、引言

在第20篇中,我们看到某企业网因双链路形成环路导致全网瘫痪,最终靠 STP 才恢复。但 STP 阻塞冗余链路后会产生一个新问题:被 STP 阻塞的链路完全不承载流量,造成带宽浪费。

为彻底解决带宽浪费问题,网络工程师通常会把多条物理链路捆绑成一条逻辑链路——这就是链路聚合(Link Aggregation)。链路聚合让多条链路同时转发数据,既成倍提升带宽,也提供链路级冗余。更重要的是,对 STP 而言 Eth-Trunk 只是一条逻辑链路,不会形成第20篇中那种因双链路产生的根桥抢占问题。

华为设备使用 Eth-Trunk 实现链路聚合,支持手工负载分担和 LACP(Link Aggregation Control Protocol)两种模式。本文将详细讲解链路聚合的工作原理、两种模式的配置方式及适用场景。

二、核心概念

2.1 链路聚合的基本术语

术语 说明
Eth-Trunk 华为设备链路聚合的逻辑接口
成员接口(Member Interface) 加入聚合组的物理接口
活跃成员接口 当前实际参与转发的成员接口
非活跃成员接口 备份状态,活跃接口故障时接替
最大成员数 取决于设备型号,通常为 8/16/64 个

2.2 两种模式对比

维度 手工负载分担模式 LACP 模式
协议协商 无 LACP(802.3ad)
链路状态检测 仅依赖 UP/DOWN LACP 报文协议
对端设备要求 不强制(手工模式两端需一致) 支持(多设备聚合)
配置复杂度 低 中
自动协商 对端必须手工模式 对端也支持 LACP
推荐场景 简单场景、对端不支持 LACP 双设备聚合(推荐)

2.3 链路聚合的好处

好处 说明
增加带宽 多条链路叠加(2 条 1G = 2 Gbps)
负载分担 数据流分散到不同链路,避免单条链路过载
链路备份 某条链路故障时,自动迁移到其他链路
对 STP 友好 聚合组对 STP 只是一条逻辑链路,不会形成环路

三、技术细节

3.1 手工负载分担模式

手工负载分担模式 - 图示

工作原理: 1. 多个成员接口加入同一个 Eth-Trunk 2. 所有成员接口同时处于活跃状态 3. 根据数据散列算法分配流量到不同成员接口 4. 某成员接口故障时,自动迁移到其他成员接口

3.2 LACP 模式

LACP(802.3ad)通过 LACPDU(LACP 数据单元)在两台设备之间协商聚合链路。

LACP 模式 - 图示

LACP 关键概念:

概念 说明 默认值
系统优先级 影响对端选择聚合链路 32768
系统 ID 系统优先级 + MAC 地址 自动生成
端口优先级 影响本端选举哪些端口为活跃 32768
端口号 端口优先级 + 端口编号 自动生成
LACP 模式 Active(主动发送)/ Passive(被动响应) Active

3.3 LACP 活跃成员选择

LACP 根据两端协商结果选择活跃成员接口:

选择顺序 比较项 规则
1 对端端口优先级 数值小者优先
2 对端端口号 数值小者优先
3 本端端口优先级 数值小者优先
4 本端端口号 数值小者优先

可通过 max active-linknumber X 设置最大活跃成员数量,超出部分作为备份。

3.4 负载分担算法

算法 命令 说明
源 IP 散列 load-balance src-ip 按源 IP 哈希
目的 IP 散列 load-balance dst-ip 按目的 IP 哈希
源+目的 IP 散列 load-balance src-dst-ip 综合哈希(默认)
源+目的 MAC 散列 load-balance src-dst-mac 按 MAC 哈希
二层散列 load-balance packet-type 按报文类型(含 MAC + VLAN)

注意:华为 VRP 中标准的负载分担命令格式是 load-balance { src-ip | dst-ip | src-dst-ip | src-mac | dst-mac | src-dst-mac | packet-type },不是 load-sharing。

四、实战配置/案例分析

4.1 案例一:手工负载分担模式配置

需求:两台交换机之间使用两条 GE 链路聚合。

# 交换机 A
[SW-A] interface Eth-Trunk 1
[SW-A-Eth-Trunk1] trunkport GigabitEthernet 0/0/1
[SW-A-Eth-Trunk1] trunkport GigabitEthernet 0/0/2
[SW-A-Eth-Trunk1] mode manual load-balance  // 缺省情况下,Eth-Trunk的工作模式为手工模式。
[SW-A-Eth-Trunk1] quit

# 交换机 B(对端也手工模式)
[SW-B] interface Eth-Trunk 1
[SW-B-Eth-Trunk1] trunkport GigabitEthernet 0/0/1
[SW-B-Eth-Trunk1] trunkport GigabitEthernet 0/0/2
[SW-B-Eth-Trunk1] mode manual load-balance
[SW-B-Eth-Trunk1] quit

# 验证,全部为活跃端口
<SW-A> display eth-trunk 1
Eth-Trunk1's state information is:
WorkingMode: NORMAL         Hash arithmetic: According to SIP-XOR-DIP
Least Active-linknumber: 1  Max Bandwidth-affected-linknumber: 8
Operate status: up          Number Of Up Port In Trunk: 2
--------------------------------------------------------------------------------
PortName                                 Status      Weight
GigabitEthernet0/0/1                     Up          1
GigabitEthernet0/0/2                     Up          1

4.2 案例二:LACP 模式配置(推荐)

# 交换机 A
[SW-A] interface Eth-Trunk 1
[SW-A-Eth-Trunk1] mode lacp-static
[SW-A-Eth-Trunk1] trunkport GigabitEthernet 0/0/1
[SW-A-Eth-Trunk1] trunkport GigabitEthernet 0/0/2
[SW-A-Eth-Trunk1] trunkport GigabitEthernet 0/0/3

# 设置最大活跃成员为 2(1 条备份)
[SW-A-Eth-Trunk1] max active-linknumber 2

# (可选)配置负载分担算法
[SW-A-Eth-Trunk1] load-balance src-dst-ip
[SW-A-Eth-Trunk1] quit

# 交换机 B(对端)
[SW-B] interface Eth-Trunk 1
[SW-B-Eth-Trunk1] mode lacp-static
[SW-B-Eth-Trunk1] trunkport GigabitEthernet 0/0/1
[SW-B-Eth-Trunk1] trunkport GigabitEthernet 0/0/2
[SW-B-Eth-Trunk1] trunkport GigabitEthernet 0/0/3
[SW-B-Eth-Trunk1] link-aggregation max-active-link 2
[SW-B-Eth-Trunk1] quit

# 验证,2个活跃端口状态为Selected,1个备份端口状态为Unselect
<SW-A> display eth-trunk 1
Eth-Trunk1's state information is:
Local:
LAG ID: 1                  WorkingMode: LACP
Preempt Delay Time: 10      Hash arithmetic: According to SIP-XOR-DIP
System Priority: 120        System ID: 00e0-fcd4-04c3
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          32768   264    2609    10111100  1
GigabitEthernet0/0/2              Selected 1GE          32768   264    2609    10111100  1
GigabitEthernet0/0/3              Unselect 1GE          32768   264    2609    10100000  1

Partner:
--------------------------------------------------------------------------------
ActorPortName                     SysPri    SystemID  PortPri PortNo  PortKey   PortState
GigabitEthernet0/0/1              32768  00e0-fc6e-bb11  32768  262   2609      10111100
GigabitEthernet0/0/2              32768  00e0-fc6e-bb11  32768  263   2609      10111100
GigabitEthernet0/0/3              32768  00e0-fc6e-bb11  32768  264   2609      10110000

4.3 案例三:Eth-Trunk 配置不一致故障

故障现象:配置 Eth-Trunk 后,端口状态为 Down。

排查:

<SW-A> display eth-trunk 1
 Eth-Trunk1 is down
 Error: LACP negotiation failed

# 查看对端配置
<SW-B> display current-configuration interface Eth-Trunk 1
 mode manual load-balance    ← 对端是手工模式

# 结论:本端 LACP 模式与对端手工模式不匹配
# 修复:将两端配置为同一模式
[SW-B] interface Eth-Trunk 1
[SW-B-Eth-Trunk1] mode lacp-static
[SW-B-Eth-Trunk1] quit

其他常见不一致项: | 不一致项 | 症状 | |---------|------| | 模式不一致 | LACP 协议失败 | | VLAN 配置不一致 | 跨 VLAN 通信失败 | | 端口速率/双工不一致 | 端口无法加入聚合组 | | STP 配置不一致 | STP 端口角色异常 |

五、总结

模式 适用场景 配置复杂度 可靠性
手工负载分担 对端不支持 LACP、单设备聚合 低 中(无协议检测)
LACP 模式 双设备聚合、对端支持 LACP 中 高(协议协商检测)
配置检查清单 命令
Eth-Trunk 状态 display eth-trunk X
成员接口列表 display eth-trunk X
活跃/非活跃成员 display eth-trunk X
LACP 状态 display link-aggregation verbose
模式一致性 对比两端配置

思考

  1. 如果 Eth-Trunk 配置了 4 个成员链路,最大活跃成员数设置为 2,当 2 条活跃链路全部故障时,备份链路会自动切换吗?
  2. 链路聚合后,STP 把 Eth-Trunk 当作一条链路处理,那么对 STP 而言会少了一个阻塞点,这有什么影响?
  3. LACP Active 模式与 Passive 模式有什么区别?两端都是 Passive 模式能协商成功吗?

下篇预告:第22篇:LACP 协商过程及优先级机制