網關冗餘與負載均衡VRRP/HSRP協議
有時候咱們爲了達到讓公司企業內部網絡的
HA高可用性和可靠性,經常會使用VRRP(Virtual Router Redundancy Protocol)虛擬路由冗餘協議,HSRP(hot standby router protocol)熱備份路由協議。這種網關冗餘而又使流量可以進行負載均衡的進行傳輸,提升整個網絡的綜合性能,解決單點故障。VRRP與HSRP一個很大的區別就是HSRP爲CISCO公司私有的一種網關冗餘協議,相反,VRRP則是一種公有協議。說到它們兩的優勢,VRRP與HSRP各有千秋。
評點:
一、HSRP不支持將真實的接口地址,設置爲虛擬的網關地址,而VRRP支持
二、HSRP將報文承載在UDP的報文上,而VRRP承載在TCP報文上
三、HSRP有三種報文,並且有三種狀態能夠發送報文
使用組播地址
224.0.0.2來發送組播報文。
呼叫(Hello) 報文,告辭(Resign)報文,突變(Coup)報文
VRRP有一種報文
VRRP廣播報文:由主路由器定時發出來通告它的存在,使用這些報文能夠檢測虛擬路由器各類參數,還能夠用於主路由器的選舉,組播報文的地址224.0.0.18。
四、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(默認它路由表裏面還有一條靜態默認路由緣故吧)
註明:在
E1 和E2都存在的狀況下,首先選擇的是E1的路由,不比較E1和E2的metric值。