网关冗余与负载均衡VRRP/HSRP协议
有时候我们为了达到让公司企业内部网络的HA高可用性和可靠性,常常会使用VRRP(Virtual Router Redundancy Protocol)虚拟路由冗余协议,HSRP(hot standby router protocol)热备份路由协议。这种网关冗余而又使流量能够进行负载均衡的进行传输,提高整个网络的综合性能,解决单点故障。VRRP与HSRP一个很大的区别就是HSRP为CISCO公司私有的一种网关冗余协议,相反,VRRP则是一种公有协议。说到它们两的优点,VRRP与HSRP各有千秋。
评点:
1、HSRP不支持将真实的接口地址,设置为虚拟的网关地址,而VRRP支持
2、HSRP将报文承载在UDP的报文上,而VRRP承载在TCP报文上
3、HSRP有三种报文,而且有三种状态可以发送报文
使用组播地址224.0.0.2来发送组播报文。
呼叫(Hello) 报文,告辞(Resign)报文,突变(Coup)报文
VRRP有一种报文
VRRP广播报文:由主路由器定时发出来通告它的存在,使用这些报文可以检测虚拟路由器各种参数,还可以用于主路由器的选举,组播报文的地址224.0.0.18。
4、HSRP有六种状态机
初始(Initial)状态,学习(Learn)状态,监听(Listen)状态,
对话(Speak)状态,备份(Standby)状态,活动 (Active)状态
VRRP三种状态机
三种状态模型:
初始状态(Initialize)、主状态(Master)、备份状态 (Backup)
其中两种协议为了协议的安全性,也加入了一些协议安全认证措施,有明文与MD5之分。下面是有关于HSRP与VRRP的一些基本实验:
一, VRRP(多VLAN情况下)
Top:
配置如下:
GW-1:
ip cef
no ip domain lookup
key chain cisco/配置一串密钥链
key 1第一个密钥
key-string cisco 密钥字符串
track 1 interface FastEthernet2/0 line-protocol VRRPtrack
delay down 4当被监视的接口DOWN掉四秒后切换组主备角色
interface FastEthernet0/0.1
encapsulation dot1Q 20
ip address 192.168.1.1 255.255.255.0
vrrp 1 ip 192.168.1.100
vrrp 1 priority 120
vrrp 1 authentication md5 key-chain cisco/对组1进行MD5加密验证,防止切换到另外的恶意网关上去
vrrp 1 track 1 decrement 40当被监测的接口DOWN掉后此接口组优秀级降40,
interface FastEthernet0/0.2
encapsulation dot1Q 30
ip address 192.168.2.1 255.255.255.0
vrrp 2 ip 192.168.2.100
interface FastEthernet2/0
ip address 192.168.3.1 255.255.255.0
duplex auto
speed auto
GW-2:
Building configuration...
hostname R2
ip cef
key chain cisco
key 1
key-string cisco
track 2 interface FastEthernet2/0 line-protocol
delay down 3
interface FastEthernet0/0.1
encapsulation dot1Q 20
ip address 192.168.1.2 255.255.255.0
vrrp 1 ip 192.168.1.100
vrrp 1 authentication md5 key-chain cisco
interface FastEthernet0/0.2
encapsulation dot1Q 30
ip address 192.168.2.2 255.255.255.0
vrrp 2 ip 192.168.2.100
vrrp 2 priority 120
vrrp 2 track 2 decrement 40
interface FastEthernet2/0
ip address 192.168.4.1 255.255.255.0
其它设备的设置我就不去一一贴上来了,
现象:
GW-1(config)#do show vrrp brief
Interface Grp Pri Time Own Pre State Master addr Group addr
Fa0/0.1 1 120 3531 Y Master 192.168.1.1 192.168.1.100
Fa0/0.2 2 100 3609 Y Backup 192.168.2.2 192.168.2.100
GW-1(config)#
GW-2(config)#do show vrrp brief
Interface Grp Pri Time Own Pre State Master addr Group addr
Fa0/0.1 1 100 3609 Y Backup 192.168.1.1 192.168.1.100
Fa0/0.2 2 120 3531 Y Master 192.168.2.2 192.168.2.100
GW-2(config)#
GW-2#show vrrp all
FastEthernet0/0.1 - Group 1
State is Backup
Virtual IP address is 192.168.1.100
Virtual MAC address is 0000.5e00.0101
Advertisement interval is 1.000 sec
Preemption enabled
Priority is 100
Authentication MD5, key-chain "cisco"
Master Router is 192.168.1.1, priority is 120
Master Advertisement interval is 1.000 sec
Master Down interval is 3.609 sec (expires in 3.117 sec)
FastEthernet0/0.2 - Group 2
State is Master
Virtual IP address is 192.168.2.100
Virtual MAC address is 0000.5e00.0102
Advertisement interval is 1.000 sec
Preemption enabled
Priority is 120
Track object 2 state Up decrement 40
Master Router is 192.168.2.2 (local), priority is 120
Master Advertisement interval is 1.000 sec
Master Down interval is 3.531 sec
其实HSRP的配置都差不多,只有一些地方稍有差异,如,把VRRP改为standby,然后配置track有一些不同,HSRP为:
standby 1 track fa0/0 20
如果上行链路有多个接口的话,也可以在HSRP/VRRP组里面配置多个track或track组。检测多个上行接口连通情况,以便更合理快速地切换通信,把企业的损失降到最底。如:
GW-1(config)#interface fa2/0
GW-1(config-if)#sh
GW-1(config-if)#
*Mar 1 02:01:17.591: %LINK-5-CHANGED: Interface FastEthernet2/0, changed state to administratively down
*Mar 1 02:01:18.591: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet2/0, changed state to down
GW-1(config-if)#
*Mar 1 02:01:19.595: %TRACKING-5-STATE: 1 interface Fa2/0 line-protocol Up->Down
GW-1(config-if)#
*Mar 1 02:01:22.795: %VRRP-6-STATECHANGE: Fa0/0.1 Grp 1 state Master -> Backup
GW-2#show vrrp brief
Interface Grp Pri Time Own Pre State Master addr Group addr
Fa0/0.1 1 100 3609 Y Master 192.168.1.2 192.168.1.100
Fa0/0.2 2 120 3531 Y Master 192.168.2.2 192.168.2.100
GW-2#
这时vlan1,vlan 2都走gw-2网关了,可以路由跟踪看下:
R4#traceroute 6.6.6.6
Type escape sequence to abort.
Tracing the route to 6.6.6.6
1 192.168.1.2 124 msec 32 msec 24 msec
2 192.168.1.2 !H * !H
R4#,虽然过不去,是因为我没配去往R6的loopback 0口6.6.6.6的路由,但可以看出来,VLAN20的PC流量因为fa2/0 down掉后走gw-2了。
2,VRRP(单个网段的局域网,如果还要网关冗余与负载均衡呢)
只需要设置一个网段里面有两个或多个不同的VRRP组,而VRRP可以把虚拟IP网关设为真实网关IP,而HSRP不可,只要两组的虚拟IP不同,客户端可以在指向网关的时候用DHCP就没有那么灵活了,因为同一个网段要控制自动分配不同的网关还是不灵活的应该。
配置:
GW-1#show run
hostname GW-1
ip cef
no ip domain lookup
key chain cisco
key 1
key-string cisco
interface FastEthernet0/0
ip address 192.168.1.1 255.255.255.0
duplex auto
speed auto
standby 1 ip 192.168.1.100
standby 1 authentication md5 key-chain cisco
standby 2 ip 192.168.1.101
standby 2 priority 120
standby 2 preempt
standby 2 track FastEthernet2/0 40
interface FastEthernet2/0
ip address 192.168.3.1 255.255.255.0
duplex auto
speed auto
router ospf 1
log-adjacency-changes
network 192.168.1.0 0.0.0.255 area 0
network 192.168.3.0 0.0.0.255 area 0
GW-2(config)# do show run
hostname GW-2
key chain cisco
key 1
key-string cisco
interface FastEthernet0/0
ip address 192.168.1.2 255.255.255.0
duplex auto
speed auto
standby 1 ip 192.168.1.100
standby 1 priority 120
standby 1 preempt
standby 1 authentication md5 key-chain cisco
standby 1 track FastEthernet2/0 40
standby 2 ip 192.168.1.101
interface FastEthernet2/0
ip address 192.168.4.1 255.255.255.0
router ospf 1
log-adjacency-changes
network 192.168.1.0 0.0.0.255 area 0
network 192.168.4.0 0.0.0.255 area 0
default-information originate always
客户端的话,只要把网关分别指向不同的虚拟IP即可。
PC2:ip default-gateway 192.168.1.100
PC1:ip default-gateway 192.168.1.101
效果:
R4#traceroute 6.6.6.6
Type escape sequence to abort.
Tracing the route to 6.6.6.6
1 192.168.1.2 60 msec 56 msec 32 msec
2 192.168.4.2 80 msec * 136 msec
R4#
R5#traceroute 6.6.6.6
Type escape sequence to abort.
Tracing the route to 6.6.6.6
1 192.168.1.1 84 msec 40 msec 40 msec
2 192.168.3.2 48 msec * 140 msec
R5#
在这里我要说一下OSPF的默认路由进程宣告命令的不同之处:
default-information originate与default-information orifinate always
default-information originate宣告之后,必须要在本ASBR路由器路由表里有一条静态默认路由存在,然后才能自动给OSPF区域内通告一条默认路由出去。而default-information orifinate always
则不需要在此ASBR路由器里面有这要的一条静态默认就可以自动向域内路由器自动生成一条指向外部网络的路由如下:
两条命令都会发布下面一条路由给OSPF域内的路由器:
O*E2 0.0.0.0/0 [110/1] via 192.168.1.2, 00:07:59, FastEthernet0/0
但要知道静态路由:
S* 0.0.0.0/0 [1/0] via 192.168.4.2
也可以在default-information orifinate always后加metric/metric-type 1/2来改变metric类型,默认为2,
O*E2 0.0.0.0/0 [110/1] via 192.168.1.2, 00:07:59, FastEthernet0/0
如果为1时,
O*E1 0.0.0.0/0 [110/2] via 192.168.1.2, 00:00:06, FastEthernet0/0
如果在always自动发布默认路由时,还在路由器下加入一条默认路由时且类型为1时:
O*E1 0.0.0.0/0 [110/3] via 192.168.1.2, 00:00:02, FastEthernet0/0
而在default-information originate 后metric-type 1/2 时,默认为2:
O*E2 0.0.0.0/0 [110/1] via 192.168.1.2, 00:00:02, FastEthernet0/0
为1时:
O*E1 0.0.0.0/0 [110/3] via 192.168.1.2, 00:00:02, FastEthernet0/0(默认它路由表里面还有一条静态默认路由缘故吧)