如图1所示,HostA和HostC通过Switch双归属到SwitchA和SwitchB。为减轻SwitchA上数据流量的承载压力,HostA以SwitchA为默认网关接入Internet,SwitchB作为备份网关;HostC以SwitchB为默认网关接入Internet,SwitchA作为备份网关,以实现流量的负载均衡。
说明
请确保该场景下互联接口的STP处于未使能状态。同时将互连接口退出VLAN1,避免形成环路。因为在使能STP的环形网络中,如果用交换机的VLANIF接口构建三层网络,会导致某个端口被阻塞,从而导致三层业务不能正常运行。
配置思路
采用VRRP负载分担实现流量的负载均衡,配置思路如下:
操作步骤
# 配置设备各接口的IP地址,以SwitchA为例。SwitchB和SwitchC的配置与SwitchA类似
[zhonwanghzhi]interface GigabitEthernet 0/0/1
[zhonwanghzhi-GigabitEthernet0/0/1]port link-type hybrid
[zhonwanghzhi-GigabitEthernet0/0/1]port hybrid pvid vlan 300
[zhonwanghzhi-GigabitEthernet0/0/1]port hybrid untagged vlan 300
[zhonwanghzhi-GigabitEthernet0/0/1]quit
[zhonwanghzhi]interface GigabitEthernet 0/0/2
[zhonwanghzhi-GigabitEthernet0/0/2]port link-type
[zhonwanghzhi-port-group-link-type]quit
[zhonwanghzhi]interface GigabitEthernet 0/0/2
[zhonwanghzhi-GigabitEthernet0/0/2]port link-type hybrid
[zhonwanghzhi-GigabitEthernet0/0/2]port hybrid pvid vlan 100
[zhonwanghzhi-GigabitEthernet0/0/2]port hybrid untagged vlan 100
[zhonwanghzhi-GigabitEthernet0/0/2]quit
[zhonwanghzhi]
[zhonwanghzhi]interface Vlanif 100
[zhonwanghzhi-Vlanif100]ip address 10.1.1.1 24
[zhonwanghzhi-Vlanif100]quit
[zhonwanghzhi]interface Vlanif 300
[zhonwanghzhi-Vlanif300]ip address 192.168.1.1 24
[zhonwanghzhi-Vlanif300]quit
[zhonwanghzhi]
# 配置Switch的二层转发功能。
[zhongwanzhi]interface GigabitEthernet 0/0/1
[zhongwanzhi-GigabitEthernet0/0/1]port link-type hybrid
[zhongwanzhi-GigabitEthernet0/0/1]port hybrid pvid vlan 100
[zhongwanzhi-GigabitEthernet0/0/1]port hybrid untagged vlan 100
[zhongwanzhi-GigabitEthernet0/0/1]quit
[zhongwanzhi]interface GigabitEthernet 0/0/2
[zhongwanzhi-GigabitEthernet0/0/2]port link-type hybrid
[zhongwanzhi-GigabitEthernet0/0/2]port hybrid pvid vlan 100
[zhongwanzhi-GigabitEthernet0/0/2]port hybrid untagged vlan 100
[zhongwanzhi-GigabitEthernet0/0/2]quit
[zhongwanzhi]
# 配置SwitchA、SwitchB和SwitchC间采用OSPF协议进行互连。以SwitchA为例,SwitchB和SwitchC的配置与SwitchA类似
[zhonwanghzhi]ospf 1
[zhonwanghzhi-ospf-1]area 0
[zhonwanghzhi-ospf-1-area-0.0.0.0]network 10.1.1.0 0.0.0.255
[zhonwanghzhi-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.255
[zhonwanghzhi-ospf-1-area-0.0.0.0]quit
[zhonwanghzhi-ospf-1]quit
配置VRRP备份组
# 在SwitchA和SwitchB上创建VRRP备份组1,配置SwitchA的优先级为120,抢占延时为20秒,作为Master设备;SwitchB的优先级为缺省值,作为Backup设备。
SwitchA
[zhongwanzhi]interface Vlanif 100
[zhongwanzhi-Vlanif100]vrrp vrid 1 virtual-ip 10.1.1.111
[zhongwanzhi-Vlanif100]vrrp vrid 1 priority 120
[zhongwanzhi-Vlanif100]vrrp vrid 1 preempt-mode timer delay 20
[zhongwanzhi-Vlanif100]quit
SwitchB
[zhonwanghzhib]interface Vlanif 100
[zhonwanghzhib-Vlanif100]vrrp vrid 1 virtual-ip 10.1.1.111
[zhonwanghzhib-Vlanif100]quit
# 在SwitchA和SwitchB上创建VRRP备份组2,配置SwitchB的优先级为120,抢占延时为20秒,作为Master设备;SwitchA的优先级为缺省值,作为Backup设备。
SwitchA
[zhonwanghzhi]interface Vlanif 100
[zhonwanghzhi-Vlanif100]vrrp vrid 2 virtual-ip 10.1.1.112
[zhonwanghzhi-Vlanif100]vrrp vrid 2 priority 120
[zhonwanghzhi-Vlanif100]vrrp vrid 2 preempt-mode timer delay 20
[zhonwanghzhi-Vlanif100]quit
SwitchB
[zhonwanghzhib]interface Vlanif 100
[zhonwanghzhib-Vlanif100]vrrp vrid 1 virtual-ip 10.1.2.112
[zhonwanghzhib-Vlanif100]quit
验证配置结果
# 完成上述配置后,在SwitchA上执行display vrrp命令,可以看到SwitchA在备份组1中作为Master设备,在备份组2中作为Backup设备。
<zhonwanghzhi>display vrrp
Vlanif100 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.111
Master IP : 10.1.1.1
PriorityRun : 100
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2023-12-15 16:49:27 UTC-08:00
Last change time : 2023-12-15 16:49:30 UTC-08:00
Vlanif100 | Virtual Router 2
State :
Virtual IP : 10.1.1.112
Master IP : 10.1.1.2
PriorityRun : 110
PriorityConfig : 110
MasterPriority : 110
Preempt : YES Delay Time : 20 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0102
Check TTL : YES
Config type : normal-vrrp
Create time : 2023-12-15 16:56:51 UTC-08:00
Last change time : 2023-12-15 16:56:55 UTC-08:00