文章目录
- eNSP实验——链路聚合(静态LACP模式配置)
eNSP实验——链路聚合(静态LACP模式配置)
仅供参考
基础概念
1. 链路聚合简介
1.1 什么是链路聚合
链路聚合,也称为端口聚合或链路捆绑,是一种将多个物理网络链路组合成一个逻辑链路的技术。通过链路聚合,网络管理员可以在不更换硬件的情况下增加带宽、提供冗余并优化流量分配。
链路聚合就是给数据包修了条"智能高速公路",多车道+备用车道+自动调度,又快又稳!
1.2 概念类比
高速公路场景 | 链路聚合技术 | 技术对应关系 |
---|---|---|
单车道公路 | 单条物理链路连接 | 传统网络连接,带宽和可靠性有限 |
双车道高速公路 | 两条物理链路绑定为逻辑聚合链路 | 通过Eth-Trunk/LAG实现带宽叠加 |
应急车道 | 备用链路(非活动端口) | LACP协议自动管理的备用端口(如配置max active-linknumber 2 时,第三条链路为备用) |
车道施工(故障) | 物理链路故障 | LACP协议自动检测故障,流量切换到备用链路(1秒内完成) |
临时开放应急车道 | 备用链路转活动状态 | 当活动链路不足时,自动启用备用端口(需配置least active-linknumber ) |
1.3 关键配置参数映射
高速路管理规则 | 链路聚合配置命令 | 作用说明 |
---|---|---|
最低保持2条车道通行 | least active-linknumber 2 | 确保聚合组最少有2个活动端口 |
最多开放3条车道 | max active-linknumber 3 | 限制活动端口数量,超出端口作为备用 |
应急车道优先级 | lacp port-priority 10 | 数值越小越优先成为活动端口 |
禁止货车占用快车道 | load-balance src-dst-ip | 按IP哈希分配流量,避免大流量独占单条链路 |
1.4 故障场景模拟
-
可以把交换机之间的链路聚合想象成连接两座城市的高速公路:
- 单条链路:就像单车道公路,所有车(数据)只能排队通过,容易拥堵(带宽不足)。
- 链路聚合:相当于把多条车道合并成高速公路,比如双车道(两条网线绑定),通行能力翻倍(带宽叠加)。
- 备用链路:就像应急车道,平时不用,但一旦主车道故障(比如网线断了),能立刻顶替(LACP自动切换,1秒内恢复)。
- 智能调度:数据像车辆一样,按"车牌号"(源IP/目的IP的哈希值)分配到不同车道,避免某条链路过载。
案例:双车道高速+1应急车道
-
正常情况:
→ 车道1+车道2开放,应急车道关闭display eth-trunk 1 # PortName Status # GE0/0/1 Selected # 车道1 # GE0/0/2 Selected # 车道2 # GE0/0/3 Unselect # 应急车道
-
车道1塌方(端口故障):
→ 1秒内应急车道自动启用# PortName Status # GE0/0/1 Down # 故障车道 # GE0/0/2 Selected # 保持活动 # GE0/0/3 Selected # 应急车道转正
1.5 链路聚合的作用
- 增加带宽:通过将多个物理链路合并,链路聚合可以提供更高的总带宽,满足高流量需求。
- 提高可靠性:如果其中一个物理链路失效,流量可以自动切换到其他链路,确保网络不中断。
- 负载均衡:流量可以在多个物理链路上进行负载均衡,避免单个链路过载,优化网络性能。
1.6 链路聚合和堆叠(Stacking)的区别
- 聚合:多链路虚拟为单逻辑链路(二层功能)。
- 堆叠:多设备虚拟为单逻辑设备(全局管理)。
2. 链路聚合的使用场景
场景 | 有什么用? | 特点 |
---|---|---|
数据中心 | 连接服务器和交换机,提升网速和稳定性。 | - 需要高速网络(比如10G/40G) - 不能断网 |
企业网络 | 让核心交换机和分支交换机之间更稳定、更快。 | - 保证业务不中断 - 自动分流 |
高可用网络 | 即使某条网线坏了,网络依然能用。 | - 自动切换备用线路 - 适合重要业务 |
3. 链路聚合的常见类型
类型 | 怎么工作的? | 适合什么情况? |
---|---|---|
手动聚合 | 手动把多条网线绑在一起,没有自动检测。 | - 简单网络 - 临时测试 |
LACP动态聚合 | 自动协商哪些网线能用,坏了自动切换。 | - 企业网络 - 需要高稳定性 |
跨设备聚合 | 把不同交换机的网线绑在一起,防止整台设备挂掉。 | - 数据中心 - 关键业务不能断 |
负载均衡 | 把网络流量分摊到多条线上,避免某条线太忙。 | - 视频会议 - 大文件传输 |
4. 链路聚合的几种模式
分类 | 模式 | 简单说明 | 适合什么情况? |
---|---|---|---|
怎么配? | 手动聚合 | 人工把几条网线绑一起,没有自动检测。 | - 小网络 - 临时测试用 |
LACP自动聚合 | 交换机会自动协商哪些网线能用,坏了自动切换。 | - 大企业网络 - 需要高稳定性 | |
放哪? | 单交换机聚合 | 所有网线插在同一台交换机上。 | - 普通办公室网络 - 省钱方案 |
跨交换机聚合 | 网线插在不同交换机上(像双保险)。 | - 数据中心 - 重要业务不能断 | |
怎么分流量? | 智能分流 | 按IP/电脑自动分配流量,避免某条线太忙。 | - 视频会议 - 多人同时传大文件 |
5. 手动聚合 对比 自动聚合(LACP)
对比项 | 手动聚合 | 自动聚合(LACP) |
---|---|---|
成员端口管理 | 完全手动设置 | 交换机会自动协商 |
反应速度 (端口状态检测) | 只能检测网线断开(慢) | 能快速发现故障(最快1秒切换) |
灵活性 | 增减网线都要手动改 | 自动调整,插上新线直接用 |
常用命令 | mode manual 和lacp-dynamic (华为) | mode lacp-dynamic (华为) |
适用场景 | 老设备 - 测试环境 | 公司核心网络 - 7×24小时不关机 |
LACP 配置(Static)
备注:
lacp-static
是华为特有模式:手动绑定端口+启用LACP检测(半自动)。
真实生产环境推荐使用
lacp-dynamic
而非lacp-static
。
实验环境
拓扑图
设备信息划分
设备类型 | 设备名称 | 所属 VLAN | 连接端口(与交换机) | 备注 |
---|---|---|---|---|
计算机 | PC1 | VLAN 10 | Ethernet 0/0/1 | |
计算机 | PC2 | VLAN 20 | Ethernet 0/0/1 | |
计算机 | PC3 | VLAN 10 | Ethernet 0/0/1 | |
计算机 | PC4 | VLAN 20 | Ethernet 0/0/1 | |
交换机 | SW1 | - | GE 0/0/1 - GE 0/0/3(Eth - Trunk 链路,GE 0/0/3 备份) | |
交换机 | SW2 | - | GE 0/0/1 - GE 0/0/3(Eth - Trunk 链路,GE 0/0/3 备份) |
1. 在SW1 上创建 Eth-Trunk1 并配置为 LACP 模式(静态)
[SW1]
[SW1]interface Eth-Trunk 1 # 创建 Eth-Trunk1 接口
[SW1-Eth-Trunk1]mode lacp-static # 将 Eth-Trunk1 配置为 LACP 静态模式
[SW1-Eth-Trunk1]q
[SW1]
2. 配置 SW1 上的成员接口加入 Eth-Trunk1
[SW1]int
[SW1]interface g0/0/1
[SW1-GigabitEthernet0/0/1]eth-trunk 1 # 将 g0/0/1 加入 Eth-Trunk1
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW1-GigabitEthernet0/0/1]q
[SW1]
[SW1]int g0/0/2
[SW1-GigabitEthernet0/0/2]eth-trunk 1 # 将 g0/0/2 加入 Eth-Trunk1
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW1-GigabitEthernet0/0/2]q
[SW1]
[SW1]int g0/0/3
[SW1-GigabitEthernet0/0/3]eth-trunk 1 # 将 g0/0/3 加入 Eth-Trunk1
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW1-GigabitEthernet0/0/3]q
[SW1]
3. 在SW2 上创建 Eth-Trunk1 并配置为 LACP 模式(静态)
[SW2]
[SW2]interface Eth-Trunk 1 # 创建Eth-Trunk 1 逻辑接口
[SW2-Eth-Trunk1]mode lacp-static # 将 Eth-Trunk1 配置为 LACP 静态模式
[SW2-Eth-Trunk1]q
[SW2]
[SW2]
4. 配置 SW2 上的成员接口加入 Eth-Trunk1
[SW2]int g0/0/1
[SW2-GigabitEthernet0/0/1]eth-trunk 1 # 将 g0/0/1 加入 Eth-Trunk1
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW2-GigabitEthernet0/0/1]q
[SW2]
[SW2]int g0/0/2
[SW2-GigabitEthernet0/0/2]eth-trunk 1 # 将 g0/0/2 加入 Eth-Trunk1
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW2-GigabitEthernet0/0/2]q
[SW2]
[SW2]int g0/0/3
[SW2-GigabitEthernet0/0/3]eth-trunk 1 # 将 g0/0/3 加入 Eth-Trunk1
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW2-GigabitEthernet0/0/3]q
[SW2]
[SW2]
5. 在 SW 1上配置系统优先级为100,使其成为LACP主动端
默认的LACP优先级是32768。在LACP模式下,优先级数值越小越优先。
# 把SW1的优先级设为100,只要SW2的优先级比100大,SW1就能成为主动端,主导链路协商。
[SW1]lacp priority 100
6. 在 SW1 上配置活动接口上限阈值为2
链路聚合组里,默认最多可以有8个活动接口。现在设置上限为2个(可选)。
[SW1]int Eth-Trunk 1
[SW1-Eth-Trunk1]max active-linknumber 2 # 修改活动接口数的上限阈值为2,最多只有2个接口处于活动状态传输数据。
[SW1-Eth-Trunk1]q
7. 在 SW1 上配置接口优先级确定活动链路(可选)
[SW1]int g0/0/1
[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]lacp priority 100 # 修改G0/0/1接口的LACP优先级为100,作为活动接口
[SW1-GigabitEthernet0/0/1]q
[SW1]
[SW1]int g0/0/2
[SW1-GigabitEthernet0/0/2]
[SW1-GigabitEthernet0/0/2]lacp priority 100 # 接修改GE0/0/2接口的LACP优先级为100,作为活动接口
[SW1-GigabitEthernet0/0/2]q
8. 在 SW2 上配置接口优先级确定活动链路(可选)
[SW2]int g0/0/1
[SW2-GigabitEthernet0/0/1]
[SW2-GigabitEthernet0/0/1]lacp priority 100 # 修改G0/0/1接口的LACP优先级为100,作为活动接口
[SW2-GigabitEthernet0/0/1]q
[SW2]
[SW2]
[SW2]int g0/0/2
[SW2-GigabitEthernet0/0/2]
[SW2-GigabitEthernet0/0/2]lacp priority 100 # 接修改GE0/0/2接口的LACP优先级为100,作为活动接口
[SW2-GigabitEthernet0/0/2]q
[SW2]
9. 配置Trunk模式通过VLAN
SW1 配置接口加入VLAN
[SW1]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW1]
[SW1]int g0/0/4
[SW1-GigabitEthernet0/0/4]
[SW1-GigabitEthernet0/0/4]port link-type trunk
[SW1-GigabitEthernet0/0/4]port trunk allow-pass vlan 10
[SW1-GigabitEthernet0/0/4]q
[SW1]
[SW1]
[SW1]int g0/0/5
[SW1-GigabitEthernet0/0/5]
[SW1-GigabitEthernet0/0/5]port link-type trunk
[SW1-GigabitEthernet0/0/5]port trunk allow-pass vlan 20
[SW1-GigabitEthernet0/0/5]q
[SW1]
SW2 配置接口加入VLAN
[SW2]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW2]
[SW2]int g0/0/4
[SW2-GigabitEthernet0/0/4]
[SW2-GigabitEthernet0/0/4]port link-type trunk
[SW2-GigabitEthernet0/0/4]port trunk allow-pass vlan 10
[SW2-GigabitEthernet0/0/4]q
[SW2]
[SW2]
[SW2]int g0/0/5
[SW2-GigabitEthernet0/0/5]
[SW2-GigabitEthernet0/0/5]port link-type trunk
[SW2-GigabitEthernet0/0/5]port trunk allow-pass vlan 20
[SW2-GigabitEthernet0/0/5]q
[SW2]
[SW2]
10 .验证
查看链路聚合组状态
在每台交换机上执行以下命令,查看链路聚合组的状态:
# SW1 交换机
[SW1]dis eth-trunk 1
Eth-Trunk1's state information is:
Local:
LAG ID: 1 WorkingMode: STATIC
Preempt Delay: Disabled Hash arithmetic: According to SIP-XOR-DIP
System Priority: 100 System ID: 4c1f-cc30-6efd
Least Active-linknumber: 1 Max Active-linknumber: 2
Operate status: up Number Of Up Port In Trunk: 2 # 活动链路2条
--------------------------------------------------------------------------------
ActorPortName Status PortType PortPri PortNo PortKey PortState Weight
GigabitEthernet0/0/1 Selected 1GE 100 2 305 10111100 1
GigabitEthernet0/0/2 Selected 1GE 100 3 305 10111100 1
GigabitEthernet0/0/3 Unselect 1GE 32768 4 305 10100000 1
Partner:
--------------------------------------------------------------------------------
ActorPortName SysPri SystemID PortPri PortNo PortKey PortState
GigabitEthernet0/0/1 32768 4c1f-cc7c-730c 100 2 305 10111100
GigabitEthernet0/0/2 32768 4c1f-cc7c-730c 100 3 305 10111100
GigabitEthernet0/0/3 32768 4c1f-cc7c-730c 32768 4 305 10110000
[SW1]
# SW2 交换机
[SW2]dis eth-trunk 1
Eth-Trunk1's state information is:
Local:
LAG ID: 1 WorkingMode: STATIC
Preempt Delay: Disabled Hash arithmetic: According to SIP-XOR-DIP
System Priority: 32768 System ID: 4c1f-cc7c-730c
Least Active-linknumber: 1 Max Active-linknumber: 8
Operate status: up Number Of Up Port In Trunk: 2 # 活动链路2条
--------------------------------------------------------------------------------
ActorPortName Status PortType PortPri PortNo PortKey PortState Weight
GigabitEthernet0/0/1 Selected 1GE 100 2 305 10111100 1
GigabitEthernet0/0/2 Selected 1GE 100 3 305 10111100 1
GigabitEthernet0/0/3 Unselect 1GE 32768 4 305 10110000 1
Partner:
--------------------------------------------------------------------------------
ActorPortName SysPri SystemID PortPri PortNo PortKey PortState
GigabitEthernet0/0/1 100 4c1f-cc30-6efd 100 2 305 10111100
GigabitEthernet0/0/2 100 4c1f-cc30-6efd 100 3 305 10111100
GigabitEthernet0/0/3 100 4c1f-cc30-6efd 32768 4 305 10100000
[SW2]
把某一条链路接口删掉,再测试
这里PC1和PC3都是 192.168.10.0/24
网段的PC,因为不需要跨子网,所以不需要配置网关。
这里可以看到g0/0/2
口已经被删掉了,就把它当作故障处理就好了。
PC3的IP地址:192.168.10.2
依然还可以和PC1的IP地址:192.168.10.1
进行这一个通信,说明这个链路聚合也算是成功了。
虽然 GigabitEthernet0/0/2 端口被删除(状态为 Unselect)
但 GigabitEthernet0/0/1 和 GigabitEthernet0/0/3 端口处于 Selected 状态,且 Operate status 为 up,说明链路聚合(LACP-static 模式)已成功建立。
当前活动的端口数量为 2(Number Of Up Port In Trunk: 2),表明冗余链路正常工作。
故障原因推测
可能原因 | 验证方法 |
---|---|
物理链路故障 | 检查光模块/网线、端口指示灯状态,使用display interface gigabitethernet 0/0/2 |
对端端口未加入Eth-Trunk | 在对端交换机执行display eth-trunk 1 ,确认G0/0/2是否在成员列表中 |
对端LACP协议未启用 | 确认对端Eth-Trunk模式是否为mode lacp-static 或mode lacp-dynamic |
STP/BPDU Guard阻断 | 检查端口是否被STP阻塞:display stp brief |
这里只是简单排查
查看eth-trunk 1组的成员
# 这里可以看到所有的链路都在 eth-trunk 1组里面,所以不是 对端LACP协议未启用 的问题
<SW1>display lacp statistics eth-trunk 1
Eth-Trunk1's PDU statistic is:
------------------------------------------------------------------------------
Port LacpRevPdu LacpSentPdu MarkerRevPdu MarkerSentPdu
GigabitEthernet0/0/1 0 0 0 0
GigabitEthernet0/0/2 0 0 0 0
GigabitEthernet0/0/3 0 0 0 0
<SW1>
查看端口是否被STP阻塞
<SW1>display stp brief
MSTID Port Role STP State Protection
0 GigabitEthernet0/0/4 DESI FORWARDING NONE # FORWARDING:端口正常转发数据,无阻塞问题。
0 GigabitEthernet0/0/5 DESI FORWARDING NONE # FORWARDING:端口正常转发数据,无阻塞问题。
0 Eth-Trunk1 DESI FORWARDING NONE
<SW1>
查看以太网链路聚合接口
显示g0/0/2的接口状态是DOWN,处于故障关闭状态,需要进一步排查物理连接、端口配置及对端设备等方面的问题。
<SW1>dis interface Eth-Trunk 1
Eth-Trunk1 current state : UP
Line protocol current state : UP
Description:
Switch Port, PVID : 1, Hash arithmetic : According to SIP-XOR-DIP,Maximal BW:
3G, Current BW: 2G, The Maximum Frame Length is 9216
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 4c1f-cc30-6efd
Current system time: 2025-03-24 21:16:06-08:00
Input bandwidth utilization : 0%
Output bandwidth utilization : 0%
-----------------------------------------------------
PortName Status Weight
-----------------------------------------------------
GigabitEthernet0/0/1 UP 1
GigabitEthernet0/0/2 DOWN 1 # 这里可以看到g0/0/2的接口状态是DOWN,链路出现了问题
GigabitEthernet0/0/3 UP 1
-----------------------------------------------------
The Number of Ports in Trunk : 3
The Number of UP Ports in Trunk : 2
<SW1>