juniper實現負載平衡

來源:互聯網
上載者:User

拓撲圖如上所示,本案例之用到了r1,r2,r3,r4四台路由器,都是在olive裡通過logical-system來實現的。r1,r2,r3,r4通過rip實現互連,然後我們再r1到r4的10.0.0.4/32的路由實現負載平衡。下面是配置指令碼:

[edit]   olive# show    ## Last changed: 2012-07-26 07:46:36 CST   version 12.1R1.9;   system {       time-zone Asia/Shanghai;       root-authentication {           encrypted-password "$1$eb9tNUWo$gYal5nxLO7VdL4n6MrNDY1"; ## SECRET-DATA       }       login {           user olive {               uid 1000;               class super-user;               authentication {                   encrypted-password "$1$T5KQ/SxD$i12MFkx8PNZTgoxJ5CS5G0"; ## SECRET-DATA               }           }       }       services {           ssh;           telnet;           web-management {               http;           }       }   }   logical-systems {       r1 {           interfaces {               em1 {                   unit 12 {                       vlan-id 12;                       family inet {                           address 10.0.4.5/30;                       }                   }                   unit 13 {                       vlan-id 13;                       family inet {                           address 10.0.4.14/30;                       }                   }                   inactive: unit 15 {                       vlan-id 15;                                family inet {                           address 172.30.25.2/30;                       }                   }               }               lo0 {                   unit 1 {                       family inet {                           address 10.0.0.1/32;                       }                   }               }           }           protocols {               rip {                   group rip1 {                       export direct-to-rip;                       neighbor em1.12;//介面上啟用rip                       neighbor em1.13;                   }               }           }           policy-options {               policy-statement direct-to-rip {                   term 1 {                       from protocol [ direct rip ];//direct只向rip鄰居通告本地路由器直連的路由,rip可以通告從其他鄰居學習來的rip路由,也就是本路由器rip路由表裡存在的路由,兩者是不一樣的,所以都要加上去,中括弧‘[]’代表他們是邏輯or                       then accept;                   }               }               policy-statement load-balance {                   term 1 {                       from {                           route-filter 10.0.0.4/32 exact;//指定到路由10.0.0.4/32的路由才做負載平衡,且本策略要通告到forwarding-table裡                       }                       then {                           load-balance per-packet;//執行動作每包負載平衡                       }                   }               }           }           routing-options {                              forwarding-table {                   export load-balance;               }//將策略通告到轉寄表           }       }       r2 {           interfaces {               em2 {                   unit 21 {                       vlan-id 12;                       family inet {                           address 10.0.4.6/30;                       }                   }                   inactive: unit 23 {                       vlan-id 23;                       family inet {                           address 10.0.4.2/30;                       }                   }                   unit 24 {                       vlan-id 24;                       family inet {                           address 10.0.4.10/30;                       }                   }               }               lo0 {                   unit 2 {                       family inet {                           address 10.0.0.2/32;                       }                   }               }           }           protocols {               rip {                   group rip2 {                       export direct-to-rip;                       neighbor em2.21;                       neighbor em2.24;                       }               }           }           policy-options {               policy-statement direct-to-rip {                   term 1 {                       from protocol [ direct rip ];                       then accept;                   }               }           }       }       r3 {           interfaces {               em3 {                   unit 31 {                       vlan-id 13;                       family inet {                           address 10.0.4.13/30;                       }                   }                   inactive: unit 32 {                       vlan-id 23;                       family inet {                           address 10.0.4.1/30;                       }                   }                   unit 34 {                       vlan-id 34;                       family inet {                           address 10.0.2.5/30;                       }                   }                   inactive: unit 35 {                       vlan-id 35;                       family inet {                           address 10.0.2.2/30;                       }                   }               }               lo0 {                                          unit 3 {                       family inet {                           address 10.0.0.3/32;                       }                   }               }           }           protocols {               rip {                   group rip3 {                       export direct-to-rip;                       neighbor em3.31;                       neighbor em3.34;                   }               }           }           policy-options {               policy-statement direct-to-rip {                   term 1 {                       from protocol [ direct rip ];                       then accept;                   }               }           }       }       r4 {           interfaces {               em4 {                   unit 42 {                       vlan-id 24;                       family inet {                           address 10.0.4.9/30;                       }                   }                   unit 43 {                       vlan-id 34;                       family inet {                           address 10.0.2.6/30;                       }                   }               }                                          lo0 {                   unit 4 {                       family inet {                           address 10.0.0.4/32;                       }                   }               }           }           protocols {               rip {                   group rip4 {                       export direct-to-rip;                       neighbor em4.42;                       neighbor em4.43;                       neighbor lo0.4;                   }               }           }           policy-options {               policy-statement direct-to-rip {                   term 1 {                       from protocol [ direct rip ];                       then accept;                   }               }           }       }   }   interfaces {       em0 {           unit 0 {               family inet {                   address 192.168.1.254/24;               }           }       }       em1 {           vlan-tagging;       }       em2 {           vlan-tagging;                          }       em3 {           vlan-tagging;       }       em4 {           vlan-tagging;       }       em5 {           vlan-tagging;       }       em6 {           vlan-tagging;       }       em7 {           vlan-tagging;       }   }   下面我們 run show route logical-system r1 protocol rip            inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)   + = Active Route, - = Last Active, * = Both           10.0.0.2/32        *[RIP/100] 00:19:39, metric 2, tag 0                       > to 10.0.4.6 via em1.12   10.0.0.3/32        *[RIP/100] 00:19:39, metric 2, tag 0                       > to 10.0.4.13 via em1.13   10.0.0.4/32        *[RIP/100] 00:19:35, metric 3, tag 0                         to 10.0.4.6 via em1.12                       > to 10.0.4.13 via em1.13//可以看到路由表顯示最佳路徑是10.0.4.13 via em1.13,從這裡我們看不出來路由器已經實現了負載平衡,可以通過show route forwarding-table來查看   10.0.2.4/30        *[RIP/100] 00:19:39, metric 2, tag 0                       > to 10.0.4.13 via em1.13   10.0.4.8/30        *[RIP/100] 00:19:39, metric 2, tag 0                       > to 10.0.4.6 via em1.12   224.0.0.9/32       *[RIP/100] 00:19:39, metric 1                         MultiRecv   查看轉寄表 run show route forwarding-table | find r1//find命令就像此刻裡面的begin,指從r1開始顯示       Logical system: r1   Routing table: default.inet   Internet:   Destination        Type RtRef Next hop           Type Index NhRef Netif   default            perm     0                    rjct   555     1   0.0.0.0/32         perm     0                    dscd   553     1   10.0.0.1/32        intf     0 10.0.0.1           locl   780     1   10.0.0.2/32        user     0 10.0.4.6           ucst   781     5 em1.12   10.0.0.3/32        user     0 10.0.4.13          ucst   782     5 em1.13   10.0.0.4/32        user     0                    ulst 131070     2                                 10.0.4.6           ucst   781     5 em1.12                                 10.0.4.13          ucst   782     5 em1.13   在這裡我們可以看到去10.0.0.4/32的路徑由兩條了他們是10.0.4.6和10。0.4.13   10.0.2.4/30        user     0 10.0.4.13          ucst   782     5 em1.13   10.0.4.4/30        intf     0                    rslv   717     1 em1.12   10.0.4.4/32        dest     0 10.0.4.4           recv   714     1 em1.12   10.0.4.5/32        intf     0 10.0.4.5           locl   715     2   10.0.4.5/32        dest     0 10.0.4.5           locl   715     2   10.0.4.6/32        dest     0 0:c:29:ef:61:93    ucst   781     5 em1.12   10.0.4.7/32        dest     0 10.0.4.7           bcst   516     1 em1.12   10.0.4.8/30        user     0 10.0.4.6           ucst   781     5 em1.12   10.0.4.12/30       intf     0                    rslv   721     1 em1.13   10.0.4.12/32       dest     0 10.0.4.12          recv   719     1 em1.13   10.0.4.13/32       dest     0 0:c:29:ef:61:9d    ucst   782     5 em1.13   10.0.4.14/32       intf     0 10.0.4.14          locl   720     2   10.0.4.14/32       dest     0 10.0.4.14          locl   720     2   10.0.4.15/32       dest     0 10.0.4.15          bcst   718     1 em1.13   224.0.0.0/4        perm     0                    mdsc   554     1   224.0.0.1/32       perm     0 224.0.0.1          mcst   550     3   224.0.0.9/32       user     1 224.0.0.9          mcst   550     3   255.255.255.255/32 perm     0                    bcst   551     1   再看一下應用負載平衡之前的轉寄表 run show route forwarding-table | find r1    Logical system: r1   Routing table: default.inet   Internet:   Destination        Type RtRef Next hop           Type Index NhRef Netif   default            perm     0                    rjct   555     1   0.0.0.0/32         perm     0                    dscd   553     1   10.0.0.1/32        intf     0 10.0.0.1           locl   780     1   10.0.0.2/32        user     0 10.0.4.6           ucst   775     4 em1.12   10.0.0.3/32        user     0 10.0.4.13          ucst   784     5 em1.13   10.0.0.4/32        user     0 10.0.4.13          ucst   784     5 em1.13   //可以看到負載平衡之前轉寄表裡r1到10.0.0.4/32的路徑只有一條   10.0.2.4/30        user     0 10.0.4.13          ucst   784     5 em1.13   10.0.4.4/30        intf     0                    rslv   717     1 em1.12   10.0.4.4/32        dest     0 10.0.4.4           recv   714     1 em1.12   10.0.4.5/32        intf     0 10.0.4.5           locl   715     2   10.0.4.5/32        dest     0 10.0.4.5           locl   715     2   10.0.4.6/32        dest     0 0:c:29:ef:61:93    ucst   775     4 em1.12   10.0.4.7/32        dest     0 10.0.4.7           bcst   516     1 em1.12   10.0.4.8/30        user     0 10.0.4.6           ucst   775     4 em1.12   10.0.4.12/30       intf     0                    rslv   722     1 em1.13   10.0.4.12/32       dest     0 10.0.4.12          recv   720     1 em1.13   10.0.4.13/32       dest     0 0:c:29:ef:61:9d    ucst   784     5 em1.13   10.0.4.14/32       intf     0 10.0.4.14          locl   721     2   10.0.4.14/32       dest     0 10.0.4.14          locl   721     2   10.0.4.15/32       dest     0 10.0.4.15          bcst   719     1 em1.13   224.0.0.0/4        perm     0                    mdsc   554     1   224.0.0.1/32       perm     0 224.0.0.1          mcst   550     3   224.0.0.9/32       user     1 224.0.0.9          mcst   550     3   255.255.255.255/32 perm     0                    bcst   551     1    下面我們通過traceroute來看一下從r1的迴環口到r4的迴環口的路徑是怎麼走的?   olive> traceroute 10.0.0.4 logical-system r1 source 10.0.0.1       traceroute to 10.0.0.4 (10.0.0.4) from 10.0.0.1, 30 hops max, 40 byte packets    1  10.0.4.13 (10.0.4.13)  1.617 ms  0.916 ms 10.0.4.6 (10.0.4.6)  1.007 ms    2  10.0.0.4 (10.0.0.4)  2.263 ms  1.925 ms  2.547 ms           olive> traceroute 10.0.0.4 logical-system r1 source 10.0.0.1       traceroute to 10.0.0.4 (10.0.0.4) from 10.0.0.1, 30 hops max, 40 byte packets    1  10.0.4.6 (10.0.4.6)  1.761 ms 10.0.4.13 (10.0.4.13)  1.355 ms  0.914 ms    2  10.0.0.4 (10.0.0.4)  6.277 ms  2.619 ms  1.937 ms           olive> traceroute 10.0.0.4 logical-system r1 source 10.0.0.1       traceroute to 10.0.0.4 (10.0.0.4) from 10.0.0.1, 30 hops max, 40 byte packets    1  10.0.4.13 (10.0.4.13)  1.579 ms 10.0.4.6 (10.0.4.6)  1.706 ms  1.265 ms    2  10.0.0.4 (10.0.0.4)  2.574 ms  2.916 ms  1.993 ms           olive> traceroute 10.0.0.4 logical-system r1 source 10.0.0.1       traceroute to 10.0.0.4 (10.0.0.4) from 10.0.0.1, 30 hops max, 40 byte packets    1  10.0.4.6 (10.0.4.6)  1.517 ms 10.0.4.13 (10.0.4.13)  0.785 ms  1.212 ms    2  10.0.0.4 (10.0.0.4)  2.068 ms  1.941 ms  2.237 ms           olive> traceroute 10.0.0.4 logical-system r1 source 10.0.0.1       traceroute to 10.0.0.4 (10.0.0.4) from 10.0.0.1, 30 hops max, 40 byte packets    1  10.0.4.6 (10.0.4.6)  1.588 ms  0.769 ms 10.0.4.13 (10.0.4.13)  1.039 ms    2  10.0.0.4 (10.0.0.4)  0.847 ms  0.806 ms  0.781 ms           olive> traceroute 10.0.0.4 logical-system r1 source 10.0.0.1       traceroute to 10.0.0.4 (10.0.0.4) from 10.0.0.1, 30 hops max, 40 byte packets    1  10.0.4.13 (10.0.4.13)  1.179 ms  1.592 ms 10.0.4.6 (10.0.4.6)  1.108 ms    2  10.0.0.4 (10.0.0.4)  2.302 ms  1.959 ms  1.946 ms   從上面結果我們可以看到r1到r4的每個包都是交替通過10.0.4.13和10.0.4.6兩個路徑轉寄的。

本文出自 “Rista” 部落格,請務必保留此出處http://rista.blog.51cto.com/2526140/942681

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.