您的位置:首页 > 其它

juniper负载均衡实例讲解

2012-07-26 00:15 316 查看


拓扑图如上所示,本案例之用到了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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: