HSRP(热备份路由器协议)的详细介绍

有句话叫富贵险中求,这话很有道理。虽然我们不赞同盲目地冒险,但我们的的确确需要一种冒险精神。因为安于现状、不思进取是永远不会前进的,因为成功的机遇往往最青睐敢于冒险的人。
Part I: Fundamental
HSRP(Hot Standby Router Protocol):Cisco私有的第3层协议。
HSRP为IP网络提供网络冗余,确保用户流量能立即并透明地恢复网络边界设备或接入电路中的第一跳故障。
在LAN中,多个router组成一个HSRP组,其中一个router代表这个HSRP转发这个LAN中的数据流,其它所有router只发送HSRP hello来维持这种HSRP组关系。
一个HSRP组共享一个IP和一个MAC地址。每个router可以加入多个组。
一个HSRP组由一台active router,一台standby router及other routers。
1>active router转发指向VIP的数据流,并发送HSRP hello包给所有其它HSRP组成员。(最终处于active state)
2>standby router不转发指向VIP的数据流,发送HSRP hello包给所有其它HSRP组成员,并监控active router的状态。(最终处于standby state)
3>other routers不转发指向VIP的数据流,只监控HSRP hello包,不发送。它们执行普通router的工作,只转发目标为他们自己的分组,不转发目标为VIP的地址。(最终处于listen state)

Part II: HSRP Operation
当standby router在一定时间内没有收到active router的hello包时,它就认为active router出现故障了,并取代它的active router的角色。因为host设备使用VIP及VMAC来标识它们的网关设备,所有它们不会发现这种变更,也不会感觉到服务的中断。

active router的选择:
1>优选priority大的HSRP router,默认的priority值为100
2>优选lowest mac地址

为了方便进行负载均衡,一个router可以属于多个HSRP组的成员,每个HSRP组有一个VIP及VMAC。
一个LAN最多支持255个HSRP组。

如果host设备发送数据分组给VIP的VMAC地址,由active router来进行相应的数据流转发。
如果host设备发送一个对VIP的ARP请求,由active router用相应的VMAC来应答。


Part III: VMAC Format
VMAC地址由3部分组成:
1>Vendor ID:MAC地址的前3个字节
2>HSRP code:2个字节,一般为07.ac,指示此地址为HSRP router。
3>Group ID:MAC地址的最后一个字节,为HSRP的组号。
\ \   Part Ⅶ:HSRP Command Reference
1> standby {group-number} ip {virtual-ip-address}
group-number:缺省为0,可配置范围0-255
注:使用HSRP时,host设备不能发现HSRP router的真实MAC地址,所以在配置了HSRP时,cisco设备自动禁用了ICMP重定向:no ip redirects

2> standby {group-number} priority {priority-value}
priority:缺省为100,可配置范围0-255
priority最高的router成为active router,priority相同,则最高ip地址的router为active router

3> standby {group-number} preempt
允许一台router只要有高的priority就可以立即强占成为active router

4> standby {group-number} {hellotime} {holdtime}
group-number:缺省为0,可配置范围0-255
hellotime:缺省为3,可配置范围1-255
holdtime:缺省为10,可配置范围1-255

5> standby {group-number} track {type number} {interface-priority}
type number:使HSRP监控此接口,如果此接口down掉,则接口的HSRP priority值减去interface-priority
interface-priority:接口down掉的惩罚值。

6> show standby {type number} {group} {brief}
Switch#show standby Vlan11 11
Vlan11 - Group 11
Local state is Active, priority 110
Hellotime 3 holdtime 10
Next hello sent in 00:00:02.944
Hot standby IP address is 172.16.11.115 configured
Active router is local
Standby router is 172.16.11.114 expires in 00:00:08
Standby virtual mac address is 0000.0c07.ac01

7> debug standby [errors] [events] [packets]
监控HSRP所有的状态改变及hello包的发送。

8> debug standby terse
监控HSRP所有的errors,events和packets信息(不包括hello及advertisement packets)



Part Ⅷ: HSRP Configuration
RouterA:
!
interface Vlan10
ip address 172.16.10.32 255.255.255.0
no ip redirects
standby 1 priority 150
standby 1 ip 172.16.10.110
standby 2 priority 50
standby 2 ip 172.16.10.120
RouterB:
!
interface Vlan10
ip address 172.16.10.33 255.255.255.0
no ip redirects
standby 1 priority 50
standby 1 ip 172.16.10.110
standby 2 priority 150
standby 2 ip 172.16.10.120
RouterA#show standby brief
P indicates configured to preempt.
Interface Grp Prio P State Active Standby Virtual IP
Vl10 1 150 Active local 172.16.10.33 172.16.10.110
Vl10 2 50 Standby 172.16.10.33 local 172.16.10.120


Part Ⅸ: Tuning HSRP Operations
Subsecond Failover:
HSRP hellotime及holdtime可以配置为millisecond级别,进而将HSRP故障检测时间减少到1秒内。
switch(config-if)#standby 1 timers msec 200 msec 750

Preempt Time Aligned with Router Boot Time:
preempt是HSRP很重要的一个特性,它允许主router在经历failover后再次成为active router。
当主router重启后,HSRP应该等待此router与其它相连的设备建立好相应的通信连接后再preempt HSRP。否则有可能会导致packets不可达。
这时就需要在preempt之前有一个延迟,以等待router完成它的通信连接或路由信息收集。这个延迟要根据不同设备不同的启动时间来设定,一般这个延迟应该比启动时间大一倍,以确保主router有能力成为active router。
switch(config-if)#standby 1 preempt
switch(config-if)#standby 1 preempt delay minimum 180

以上就是HSRP(热备份路由器协议)的详细介绍。生命太过短暂,今天抛却了明天不一定能得到。更多关于HSRP(热备份路由器协议)的详细介绍请关注haodaima.com其它相关文章!

标签: HSRP