1. 程式人生 > >閘道器負載平衡協議——GLBP

閘道器負載平衡協議——GLBP

15.3.1 實驗目的

1)理解GLBP的工作原理

2)掌握GLBP的配置和測試

15.3.2 實驗原理

1.GLBP簡介

GLBP(閘道器負載平衡協議)是cisco私有協議,他彌補了現有的冗餘路由器協議的侷限性, 設計GLBP的目的是自動選擇和同時使用多個可用的閘道器。和HSRP、VRRP不同的是,GLBP可充分利用資源,同時無需配置多個組和管理多個預設閘道器配置。

GLBP組中最多可以有4臺路由器作為IP預設閘道器。這些閘道器被稱為AVF(Active Virtual Forwarder,活躍虛擬轉發器)。GLBP自動管理虛擬MAC地址的分配、決定誰負責處理轉發工作(這是區別於HSRP和VRRP的關鍵,

GLBP中有一個虛擬IP,但對應多個虛擬MAC)。

GLBP的負載均衡可以通過三種方式來實現:

加權負載均衡演算法:前往AVF的流量取決於包含該AVF閘道器通告的權重值。

主機相關負載均衡:確保主機始終使用同一個虛擬MAC地址。

迴圈負載均衡演算法:在解析虛擬IP地址的應答中,將包含各個虛擬轉發器的MAC地址,以此讓主機將資料傳送到不同的路由器上,從而實現了閘道器負載均衡。

預設情況下,GLBP以迴圈方式根據源主機來均衡負載。

2.GLBP配置命令

HSSPVRRP能實現閘道器冗餘,然而,如果要實現負載平衡,需要建立多個組,並讓客戶端指向不同的閘道器。GLBPGateway Load Balance Protocol

)也是Cisco的專有協議,不僅提供冗餘閘道器功能,還在各閘道器之間提供負載均衡。GLBP也是由多個路由器組成一個組,虛擬一個網關出來。GLBP選舉出一個AVG(Avtive Virtual Gateway)AVG不是負責轉發資料的。AVG分配最多4MAC地址給一個虛擬閘道器,並在計算機進行ARP請求時,用不同的MAC進行響應,這樣計算機實際就把資料傳送給不同的路由器了,從而實現負載平衡。在GLBP中,真正負責轉發資料的是AVFAvtive Virtual Forawarder),GLBP會控制GLBP組中哪個路由器是哪個MAC地址的活動路由器。

AVG的選舉和HRSP中活動路由器的選舉非常類似,優先順序最高的路由器成為

AVG,次之的為Abckup AVG,其餘的為監聽狀態。一個GLBP組只能有一個AVG和一個Backup AVG,主AVG失敗,備份AVG頂上。一臺路由器可以同時是AVGAVFAVF是某些MAC的活動路由器,也就是說,如果計算機把資料發往這個MAC,它將接收。當某一MAC的活動路由器有故障時,其他AVF將成為這一MAC的新的活動路由器,從而實現冗餘功能GLBP的負載平衡策略可以根據不同主機、簡單地輪詢,或者根據路由器的權重平衡,預設是輪詢方式。

命令 

Router(config-if)# glbpgroup_number ip ip_address

設定GLBP組號和虛擬IP地址

Router(config-if)#glbpgroup_number  prioritypriority_value

配置GLBP的優先順序,如果不設定該項,預設優先順序為100 ,該值越大,搶佔為活動路由器的優先權越

Router(config-if)glbpgroup_number preempt

該設定允許該路由器在優先順序是最高時成為活動路由器。

Router(config-if)glbpgroup_number timer hello_time  hold_Time

設定該路由器的hello_timehold_time

Router(config-if)#glbpgroup_number

Authentication  md5   key-string   password

配置認證密碼,防止非法裝置加入到GLBP組中,同一個組的密碼必須一致

3.GLBP配置例項


15-6 GLBP的配置

IP地址表

裝置

介面

IP地址

子網掩碼

R1

Fa 0/0

192.168.12.1

255.255.255.0

Fa 0/1

192.168.123.1

255.255.255.0

R2

Fa 0/0

192.168.12.2

255.255.255.0

Fa 0/1

192.168.123.2

255.255.255.0

R3

Fa 0/1

192.168.123.3

255.255.255.0

Fa 0/0

172.16.1.1

255.255.255.0

PC1

NIC

192.168.12.100

255.255.255.0

PC2

NIC

172.16.1.100

255.255.255.0

15-5 IP地址表

(1)步驟1: 配置ip 地址和路由協議等。
R1(config)# interface fa 0/0
R1(config-if)# ip add 192.168.12.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#exit
R1(config)# inter fa 0/1
R1(config-if)# ip add 192.168.123.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#exit
R1(config)# router rip
R1(config-router)# network 192.168.12.0
R1(config-router)# network 192.168.123.0
R1(config-router)# passive-interface fa 0/0
R2(config)# int fa 0/0
R2(config-if)# ip add 192.168.12.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#exit
R2(config)# int fa 0/1
R2(config-if)# ip add 192.168.123.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#exit
R2(config)# router rip
R2(config-router)# network 192.168.12.0
R2(config-router)# network 192.168.123.0
R2(config-router)# passive-interface fa 0/0
R3(config)# int fa 0/1
R3 (config-if)# ip add 172.16.1.1 255.255.255.0
R3(config-if)#no shut
R3(config-if)#exit
R3 (config)# int fa 0/0
R3 (config-if)# ip add 192.168.123.3 255.255.255.0
R3(config-if)#no shut
R3(config-if)#exit
R3 (config)# router rip
R3 (config-router)# network 192.168.123.0
R3 (config-router)# network 172.16.0.0
(2)步驟2:配置glbp
R1(config)# interface fa 0/0
R1(config-if)# glbp 1 ip 192.168.12.254
//和hsrp類似,建立glbp組,虛擬閘道器的ip 為192.168.12.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)# int fa 0/0
R2(config-if)# glbp 1 ip 192.168.12.254
           //和hsrp類似,建立glbp組,虛擬閘道器的ip 為192.168.12.254
R2(config-if)# glbp 1 priority 180
//配置優先順序,優先順序高的路由器成為avg,預設為100。
R2(config-if)# glbp 1 preempt
//配置avg搶佔,否則即使優先順序再高,也不會成為avg.
R2(config-if)# glbp 1 authentication md5 key-string cisco
//以上是配置認證,防止非法裝置接入
(3)步驟3 :檢視glbp資訊。
R1#show glbp
FastEthernet0/0 - Group 1
  State is Active
    1 state change, last state change 00:00:47
  Virtual IP address is 192.168.12.254  //虛擬的閘道器ip地址
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 0.736 secs
  Redirect time 600 sec, forwarder timeout 14400 sec
  Authentication MD5, key-string
  Preemption enabled, min delay 0 sec
  Active is local   //說明R1是活動avg
  Standby is 192.168.12.2, priority 180 (expires in 8.352 sec)  //說明R2是備份avg


  Priority 200 (configured)
  Weighting 100 (default 100), thresholds: lower 1, upper 100
  Load balancing: round-robin
  Group members:    //以下顯示glbp組中的成員
    04c5.a43f.e4e0 (192.168.12.2) authenticated
    04c5.a4b3.bba0 (192.168.12.1) local
  There are 2 forwarders (1 active)
  Forwarder 1
    State is Active
      1 state change, last state change 00:00:36
    MAC address is 0007.b400.0101 (default)   //虛擬閘道器的其中一個Mac,說明R1是0007.b400.0101的活動路由器,也就是說,如果計算機把資料發往0007.b400.0101,將由R1接收資料,再進行轉發
    Owner ID is 04c5.a4b3.bba0
    Redirection enabled
    Preemption enabled, min delay 30 sec
    Active is local, weighting 100
  Forwarder 2
    State is Listen
    MAC address is 0007.b400.0102 (learnt)    //虛擬閘道器的另外一個Mac,
    Owner ID is 04c5.a43f.e4e0
    Redirection enabled, 599.744 sec remaining (maximum 600 sec)
    Time to live: 14399.744 sec (maximum 14400 sec)
    Preemption enabled, min delay 30 sec
Active is 192.168.12.2 (primary), weighting 100 (expires in 10.656 sec)


R2#show glbp
FastEthernet0/0 - Group 1
  State is Standby
    1 state change, last state change 00:26:41
  Virtual IP address is 192.168.12.254  //虛擬的閘道器ip地址
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 1.056 secs
  Redirect time 600 sec, forwarder timeout 14400 sec
  Authentication MD5, key-string
  Preemption enabled, min delay 0 sec
  Active is 192.168.12.1, priority 200 (expires in 8.896 sec)  //說明R1是活動avg
  Standby is local  //說明R2是備份avg
  Priority 180 (configured)
  Weighting 100 (default 100), thresholds: lower 1, upper 100
  Load balancing: round-robin
  Group members: //以下顯示glbp組中的成員
    04c5.a43f.e4e0 (192.168.12.2) local
    04c5.a4b3.bba0 (192.168.12.1) authenticated
  There are 2 forwarders (1 active)
  Forwarder 1
    State is Listen
    MAC address is 0007.b400.0101 (learnt) //虛擬閘道器的另外一個Mac,
    Owner ID is 04c5.a4b3.bba0
    Time to live: 14397.664 sec (maximum 14400 sec)
    Preemption enabled, min delay 30 sec
    Active is 192.168.12.1 (primary), weighting 100 (expires in 10.368 sec)
  Forwarder 2
    State is Active
      1 state change, last state change 00:26:46
    MAC address is 0007.b400.0102 (default)  //虛擬閘道器的其中一個Mac,說明R2是0007.b400.0102的活動路由器,也就是說,如果計算機把資料發往0007.b400.0102,將由R2接收資料,再進行轉發
    Owner ID is 04c5.a43f.e4e0
    Preemption enabled, min delay 30 sec
    Active is local, weighting 100


 (4)步驟4:檢查glbp的負載平衡功能
在PC1上配置IP地址,閘道器指向192.168.12.254 ,並進行以下操作:
①在PC1上ping 172.16.1.100,然後使用arp –a命令檢視到閘道器192.168.12.254的mac地址
C:\>arp –a
Interface:192.168.12.100---0x03
   Internet Address      Physical Address    Type
   192.168.12.254      00-07-b4-00-01-01   dynamic
//以上表明PC1的ARP請求獲得閘道器(192.168.1.254)的MAC為00-07-b4-00-01-01
②然後在PC1上再使用arp -d 命令,刪除arp緩衝表
③接著在PC1上ping 172.16.1.100,然後使用arp –a命令檢視到閘道器192.168.12.254的mac地址
C:\>arp –a
Interface;192.168.1.100---0x03 
   Internet Address      Physical Address     Type
   192.168.12.254      00-07-b4-00-01-02   dynamic
//以上表明PC1的再次ARP請求獲得閘道器(192.168.1.254)的MAC為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-01,是R1在轉發資料。
②然後在PC1上連續ping PC2,並在R1上關閉fa 0/0介面,觀察PC1的通訊情況:
C:\>ping –t 172.16.1.100
Reply from 172.16.1.100; bytes=32 time<1ms TTL=254
Reply from 172.16.1.100; bytes=32 time<1ms TTL=254
Reply from 172.16.1.100; bytes=32 time<1ms TTL=254
Request timed out.
Request timed out.
Reply from 172.16.1.100; bytes=32 time<1ms TTL=254
Reply from 172.16.1.100; bytes=32 time<1ms TTL=254
Reply from 172.16.1.100; bytes=32 time<1ms TTL=254

//可以看到R1出故障後,其他路由器很快接替了它的工作,計算機的通訊只受到短暫的影響。因此GLBP不僅有負載平衡的能力,也有冗餘的能力。

為了保障網路的穩定性,減少因網路裝置故障而導致網路癱瘓,在OSI/RM的二層,交換機廠商開發出了STP以及PVST等技術,實現交換機的冗餘備份和負載均衡。那在OSI/RM第三層那就有HSRP(思科私有協議)和VRRPIEEE標準)。不過HSRPVRRP正常情況下,只有冗餘備份的功能,而要實現負載均衡的功能,只有建立多個備份組,兩個或多個虛擬閘道器,讓局域內的PC機配置不同的閘道器,從而實現負載均衡的功能,這樣在操作上就顯得比較麻煩。

思科公司開發的GLBP技術(Gateway Load Balance Protocol,由多個路由器組成一個備份組,將每臺路由器的MAC地址(最多四個)加入備份組,成為虛擬閘道器的MAC地址組。當局域網內的PC機請求閘道器ARP響應時,虛擬閘道器的MAC地址組中MAC地址輪流響應,從而實現流量根據二層的閘道器MAC地址走不同的真實路由器,從而實現負載均衡。