找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 12323|回复: 30

[其它] Load Balancing

[复制链接]
发表于 2007-3-24 15:16:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
Load Balancing
From MikroTik Wiki
Spanish version of this article: Balanceo de carga mejorado atravéz de multiples gateway (wan)

With NAT and policy routing, with working HTTPS, IM and large downloads

Consider the following network layout:



Contents
1 Quick Start for Impatient
2 Explanation
2.1 Mangle
2.2 NAT
2.3 Routing



[edit]Quick Start for Impatient
Configuration export from the gateway router:

/ ip address
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=Local comment="" \
    disabled=no
add address=10.111.0.2/24 network=10.111.0.0 broadcast=10.111.0.255 interface=wlan2 \
    comment="" disabled=no
add address=10.112.0.2/24 network=10.112.0.0 broadcast=10.112.0.255 interface=wlan1 \
    comment="" disabled=no
/ ip firewall mangle
add chain=prerouting in-interface=Local connection-state=new nth=1,1,0 \
    action=mark-connection new-connection-mark=odd passthrough=yes comment="" \
    disabled=no
add chain=prerouting in-interface=Local connection-mark=odd action=mark-routing \
    new-routing-mark=odd passthrough=no comment="" disabled=no
add chain=prerouting in-interface=Local connection-state=new nth=1,1,1 \
    action=mark-connection new-connection-mark=even passthrough=yes comment="" \
    disabled=no
add chain=prerouting in-interface=Local connection-mark=even action=mark-routing \
    new-routing-mark=even passthrough=no comment="" disabled=no
/ ip firewall nat
add chain=srcnat connection-mark=odd action=src-nat to-addresses=10.111.0.2 \
    to-ports=0-65535 comment="" disabled=no
add chain=srcnat connection-mark=even action=src-nat to-addresses=10.112.0.2 \
    to-ports=0-65535 comment="" disabled=no
/ ip route
add dst-address=0.0.0.0/0 gateway=10.111.0.1 scope=255 target-scope=10 routing-mark=odd \
    comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=10.112.0.1 scope=255 target-scope=10 routing-mark=even \
    comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=10.112.0.1 scope=255 target-scope=10 comment="" \
    disabled=no
[edit]Explanation
First we give a code snippet and then explain what it actually does.

[edit]Mangle
/ ip address
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=Local comment="" \
    disabled=no
add address=10.111.0.2/24 network=10.111.0.0 broadcast=10.111.0.255 interface=wlan2 \
    comment="" disabled=no
add address=10.112.0.2/24 network=10.112.0.0 broadcast=10.112.0.255 interface=wlan1 \
    comment="" disabled=no
The router has two upstream (WAN) interfaces with the addresses of 10.111.0.2/24 and 10.112.0.2/24. The LAN interface has the name "Local" and IP address of 192.168.0.1/24.

/ ip firewall mangle

add chain=prerouting in-interface=Local connection-state=new nth=1,1,0 \
    action=mark-connection new-connection-mark=odd passthrough=yes comment="" \
    disabled=no

First we take every second packet that establishes new session (note connection-state=new), and mark it with connection mark "odd". Consequently all successive packets belonging to the same session will carry the connection mark "odd". Note that we are passing these packets to the second rule (passthrough=yes) to place a routing mark on these packets in addition to the connection mark.

add chain=prerouting in-interface=Local connection-mark=odd action=mark-routing \
    new-routing-mark=odd passthrough=no comment="" disabled=no
The rule above places the routing mark "odd" on all packets that belong to the "odd" connection and stops processing all other mangle in prerouting chain rules for these packets.

add chain=prerouting in-interface=Local connection-state=new nth=1,1,1 \
    action=mark-connection new-connection-mark=even passthrough=yes comment="" \
    disabled=no
add chain=prerouting in-interface=Local connection-mark=even action=mark-routing \
    new-routing-mark=even passthrough=no comment="" disabled=no
These rules do the same for the remaining half of the traffic as the first two rules for the first half of the traffic.

The code above effectively means that each new connection initiated through the router from the local network will be marked as either "odd" or "even" with both routing and connection marks.

[edit]NAT
/ ip firewall nat
add chain=srcnat connection-mark=odd action=src-nat to-addresses=10.111.0.2 \
    to-ports=0-65535 comment="" disabled=no
add chain=srcnat connection-mark=even action=src-nat to-addresses=10.112.0.2 \
    to-ports=0-65535 comment="" disabled=no
All traffic marked "odd" is being NATted to source IP address of 10.111.0.2, while traffic marked "even" gets "10.112.0.2" source IP address.

[edit]Routing
/ ip route
add dst-address=0.0.0.0/0 gateway=10.111.0.1 scope=255 target-scope=10 routing-mark=odd \
    comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=10.112.0.1 scope=255 target-scope=10 routing-mark=even \
    comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=10.112.0.1 scope=255 target-scope=10 comment="" \
    disabled=no comment="gateway for the router itself"
For all traffic marked "odd" (consequently having 10.111.0.2 translated source address) we use 10.111.0.1 gateway. In the same manner all traffic marked "even" is routed through the 10.112.0.1 gateway. Finally, we have one additional entry specifying that traffic from the router itself (the traffic without any routing marks) should go to 10.112.0.1 gateway.

Retrieved from "http://wiki.mikrotik.com/wiki/Load_Balancing"
routeros
发表于 2007-3-24 17:05:11 | 显示全部楼层
好贴....
没人顶???
lz继续放出如此好东西
routeros
回复

使用道具 举报

发表于 2007-3-24 19:12:23 | 显示全部楼层
有没有中文版的。。。。。
routeros
回复

使用道具 举报

发表于 2007-3-24 21:38:34 | 显示全部楼层
还用中文??
重点看mangle
routeros
回复

使用道具 举报

发表于 2007-3-24 22:41:03 | 显示全部楼层
啥?传说中的负载均衡?
routeros
回复

使用道具 举报

发表于 2007-3-24 22:45:31 | 显示全部楼层
顶了。。。多ADSL接入有福了
routeros
回复

使用道具 举报

 楼主| 发表于 2007-3-24 22:58:43 | 显示全部楼层
这只是简单从官方网站复制过来的。希望有条件的朋友做下测试。
routeros
回复

使用道具 举报

 楼主| 发表于 2007-3-25 07:30:54 | 显示全部楼层


官方例子是两条外线的,至于3----N线,改一下NTH就可以了。
Every=N-1 多少数据包为一计数组 (以外线总数为对应计数)
Counter 计数器 (共有15个计数器,可随意指定一个)
Packet 数据包的顺序 (0----N-1)
routeros
回复

使用道具 举报

发表于 2007-3-25 12:27:51 | 显示全部楼层
因为这里的人不大看E文

就算你告诉他们官网的原地址他们也不看的

更不要指望他们能理解了
routeros
回复

使用道具 举报

 楼主| 发表于 2007-3-25 12:53:36 | 显示全部楼层
只要有人路过总会有痕迹。
routeros
回复

使用道具 举报

发表于 2007-3-25 13:00:04 | 显示全部楼层
好贴。
routeros
回复

使用道具 举报

发表于 2007-3-25 13:26:29 | 显示全部楼层
个,有人贴出来没人翻译?翻译一下啊
routeros
回复

使用道具 举报

发表于 2007-3-25 15:37:11 | 显示全部楼层
还有没有别的方法???
routeros
回复

使用道具 举报

发表于 2007-3-25 15:49:37 | 显示全部楼层
楼主太感谢了啊...
routeros
回复

使用道具 举报

发表于 2007-3-25 15:51:58 | 显示全部楼层
绝对精贴
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-11-5 20:37 , Processed in 0.148701 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表