「实战」解决网络中单点故障实现流量负载均衡,一分钟了解下

2023-07-20 03:44:38

一、实战目的

1、 理解 GLBP 的工作原理

2、掌握 GLBP 的配置

二、 拓扑

三、步骤

(1) 步骤 1:配置 IP 地址、路由协议等

R1(config)# interface GigabitEthernet0/0

R1(config-if)# ip address 192.168.1.1 255.255.255.0

R1(config)# interface GigabitEthernet0/1

R1(config-if)# ip address 192.168.2.1 255.255.255.0

R1(config)# router rip

R1(config-router)# network 192.168.1.0

R1(config-router)# network 192.168.2.0

R1(config-router)# passive-interface GigabitEthernet0/0

R2(config)# interface GigabitEthernet0/0

R2(config-if)# ip address 192.168.1.2 255.255.255.0

R2(config)# interface GigabitEthernet0/1

R2(config-if)# ip address 192.168.2.2 255.255.255.0

R2(config)# router rip

R2(config-router)# network 192.168.1.0

R2(config-router)# network 192.168.2.0

R2(config-router)# passive-interface GigabitEthernet0/0

R3(config)# interface GigabitEthernet0/0

R3(config-if)# ip address 192.168.1.3 255.255.255.0

R3(config)# interface GigabitEthernet0/1

R3(config-if)# ip address 192.168.2.3 255.255.255.0

R3(config)# router rip

R3(config-router)# network 192.168.1.0

R3(config-router)# network 192.168.2.0

R3(config-router)# passive-interface GigabitEthernet0/0

R4(config)# interface Loopback0

R4(config-if)# ip address 4.4.4.4 255.0.0.0

R4(config)# interface GigabitEthernet0/1

R4(config-if)# ip address 192.168.2.4 255.255.255.0

R4(config)# router rip

R4(config-router)# network 4.0.0.0

R4(config-router)# network 192.168.2.0

(2) 步骤 2:配置 GLBP

R1(config)# interface GigabitEthernet0/0

R1(config-if)# glbp 1 ip 192.168.1.254

//和 HSRP 类似,创建 GLBP 组,虚拟网关的 IP 为 192.168.1.254

R1(config-if)# glbp 1 priority 200

//配置优先级,优先级高的路由器成为 AVG,默认为 100

R1(config-if)# glbp 1 preempt

//配置 AVG 抢占,否则即使优先级再高,也不会成为 AVG

R1(config-if)# glbp 1 authentication md5 key-string cisco

//以上是配置认证,防止非法设备接入

R2(config)# interface GigabitEthernet0/0

R2(config-if)# glbp 1 ip 192.168.1.254

R2(config-if)# glbp 1 priority 180

R2(config-if)# glbp 1 preempt

R2(config-if)# glbp 1 authentication md5 key-string cisco

R3(config)# interface GigabitEthernet0/0

R3(config-if)# glbp 1 ip 192.168.1.254

R3(config-if)# glbp 1 priority 160

R3(config-if)# glbp 1 preempt

R3(config-if)# glbp 1 authentication md5 key-string cisco

(3) 步骤 3:查看 GLBP 信息

R1# show glbp

GigabitEthernet0/0 - Group 1

State is Active

4 state changes, last state change 00:18:16

Virtual IP address is 192.168.1.254

//以上是虚拟的网关 IP 地址

HELLO time 3 sec, hold time 10 sec

Next HELLO sent in 1.896 secs

Redirect time 600 sec, forwarder time-out 14400 sec

Authentication MD5, key-string "cisco"

Preemption enabled, min delay 0 sec

Active is local

//以上说明 R1 是活动 AVG

Standby is 192.168.1.2, priority 180 (expires in 9.892 sec)

//以上说明 R2 是备份 AVG

Priority 200 (configured)

Weighting 100 (default 100), thresholds: lower 1, upper 100

Load balancing: round-robin

Group members:

0019.5535.b548 (192.168.1.3) authenticated

0019.5535.b828 (192.168.1.1) local

0019.5566.6320 (192.168.1.2) authenticated

0019.5535.b548 (192.168.1.3) authenticated

0019.5535.b828 (192.168.1.1) local

0019.5566.6320 (192.168.1.2) authenticated

//以上显示 GLBP 组中的成员

There are 3 forwarders (1 active)

Forwarder 1

State is Listen

4 state changes, last state change 00:17:08

MAC address is 0007.b400.0101 (learnt)

//这是虚拟网关的其中一个 MAC

Owner ID is 0019.5535.b548

Redirection enabled, 599.984 sec remaining (maximum 600 sec)

Time to live: 14399.984 sec (maximum 14400 sec)

Preemption enabled, min delay 30 sec

Active is 192.168.1.3 (primary), weighting 100 (expires in 9.984 sec)

Client selection count: 1

Forwarder 2

State is Active

3 state changes, last state change 00:18:28

MAC address is 0007.b400.0102 (default)

//以上说明 R1 是 0007.b400.0102 的活动路由器,也就是说如果计算机把数据发往

0007.b400.0102,将由 R1 接收数据,再进行转发。

Owner ID is 0019.5535.b828

Redirection enabled

Preemption enabled, min delay 30 sec

Active is local, weighting 100

Client selection count: 1

Forwarder 3

State is Listen

2 state changes, last state change 00:18:06

MAC address is 0007.b400.0103 (learnt)

Owner ID is 0019.5566.6320

Redirection enabled, 597.980 sec remaining (maximum 600 sec)

Time to live: 14397.980 sec (maximum 14400 sec)

Preemption enabled, min delay 30 sec

Active is 192.168.1.2 (primary), weighting 100 (expires in 7.980 sec

通过查看,可以知道:

R1:0007.b400.0102 的活动路由器

R2:0007.b400.0103 的活动路由器

R3:0007.b400.0101 的活动路由器

(4) 步骤 4:检查 GLBP 的负载平衡功能

在 PC1 上配置 IP 地址,网关指向 192.168.1.254。并进行如下操作:

C:\> ping 4.4.4.4

C:\> arp -a

Interface: 192.168.1.100 --- 0x10006

Internet Address Physical Address Type

192.168.1.254 00-07-b4-00-01-01 dynamic

以上表明 PC1 的 ARP 请求获得网关(192.168.1.254)的 MAC 为 00-07-b4-00-01-01。

C:\> arp -d

//以上是删除 ARP 缓冲表

C:\> ping 4.4.4.4

C:\> arp -a

Interface: 192.168.1.100 --- 0x10006

Internet Address Physical Address Type

192.168.1.254 00-07-b4-00-01-02 dynamic

以上表明 PC1 的再次 ARP 请求获得网关(192.168.1.254)的 MAC 为 2 00-07-b4-00-01-02 了,

也就是说 GLBP 响应 ARP 请求时,每次会用不同的 MAC 响应,从而实现负载平衡。

【提示】默认时 GLBP 的负载平衡策略是轮询方式,可以在接口下使用“ glbp 1

load-balancing”命令修改,有以下选项:

host-dependent:根据不同主机的源 MAC 地址进行平衡

round-robin:轮询方式,即每响应一次 ARP 请求,轮换一个地址

weighted:根据路由器的权重分配,权重高的被分配的可能性越大。

(5) 步骤 5:检查 GLBP 的冗余功能

首先在 PC1 上用“ arp -a”命令确认 192.168.1.254 的 MAC 地址是什么,从而确定出当

前究竟是哪个路由器在实际转发数据。我们这里 192.168.1.254 的 MAC 地址为

00-07-b4-00-01-02,从步骤 3 得知是 R1 在转发数据。

在 PC1 上连续 ping 4.4.4.4,并在 R1 上关闭 g0/0 接口,观察 PC1 的通信情况:

C:\ > ping -t 4.4.4.4

Reply from 4.4.4.4: bytes=32 time<1ms TTL=254

Reply from 4.4.4.4: bytes=32 time<1ms TTL=254

Request timed out.

Request timed out.

Reply from 4.4.4.4: bytes=32 time<1ms TTL=254

Reply from 4.4.4.4: bytes=32 time<1ms TTL=254

//可以看到在 R1 故障后,其它路由器很快接替了它的工作,计算机的通信只受到短暂的影

响。因此 GLBP 不仅有负载平衡的能力,也有冗余的能力。可以使用“ show glbp”命令查看

一下谁是 00-07-b4-00-01-02 这个 MAC 的新的活动路由器。

以下是华为数通路由交换方向完整技术分享,欢迎对华为网络技术感兴趣的小伙伴们订阅。

【可在专栏中进行查看订阅】


华为新版HCIP数通路由交换

华为新版HCIE数通路由交换