完全手册之ADSL负载均衡配置
创始人
2024-06-30 03:00:59
0次

说了很多关于数据库,服务器等负载均衡问题。现在,我们来讨论一下ADSL的负载均衡设置。主要我们需要对脚本进行“改造”,也就是NTH负载均衡的设置问题,文中包括很多脚本代码,希望大家能仔细的浏览,帮大家解决问题。

建立PPP拨号,把其中一条拨号名命名为ADSL1,另一个命明为ADSL2,并把内网网卡命名为LAN,然后等待拨号成功,设置参考下图

完全手册之ADSL负载均衡配置

拨号成功后,PPPOE会自动添加IP地址和网关,找到地址和网关,复制下来,替换到下面脚本中,把A1IP替换成ADSL1的IP,A1网关替换成ADSL1的网关,把A2IP替换成ADSL2的IP,A2网关替换成ADSL2的网关.之后慢慢添脚本,添完成功后,把拨号的Add Default Route的勾去掉,看负载均衡是否可以正常工作!#p#

1.普通脚本设置

  1. / ip firewall nat  
  2. add chain=srcnat action=masquerade comment="3" disabled=yes  
  3. / ip address  
  4. add address=A1IP interface=ADSL1 comment="1" disabled=no  
  5. add address=A2IP interface=ADSL2 comment="2" disabled=no  
  6. / ip route  
  7. add dst-address=0.0.0.0/0 gateway=A1网关 routing-mark=1 comment="1" 
  8. add dst-address=0.0.0.0/0 gateway=A2网关 routing-mark=2 comment="2" 
  9. add dst-address=0.0.0.0/0 gateway=A1网关 comment="3" 

2.添加NAT,NTH脚本

  1. / ip firewall mangle  
  2. add chain=prerouting in-interface=LAN protocol=tcp connection-state=new nth=1,1,0 action=mark-connection \  
  3.     new-connection-mark=1 passthrough=yes comment="A1 NTH" disabled=no  
  4. add chain=prerouting in-interface=LAN protocol=tcp connection-mark=1 action=mark-routing new-routing-mark=1 \  
  5.     passthrough=no comment="A1 NTH" disabled=no  
  6. add chain=prerouting in-interface=LAN protocol=tcp connection-state=new nth=1,1,1 action=mark-connection \  
  7.     new-connection-mark=2 passthrough=yes comment="A2 NTH" disabled=no  
  8. add chain=prerouting in-interface=LAN protocol=tcp connection-mark=2 action=mark-routing new-routing-mark=2 \  
  9.     passthrough=no comment="A2 NTH" disabled=no  
  10. / ip firewall nat  
  11. add chain=srcnat connection-mark=1 action=src-nat to-addresses=A1IP to-ports=0-65535 comment="1" disabled=no  
  12. add chain=srcnat connection-mark=2 action=src-nat to-addresses=A2IP to-ports=0-65535 comment="2" disabled=no 

#p#3.同步NAT,ADSL动态IP,网关脚本:位置winbox-system-script 点“+ ”号,改name为sync,然后复制下面的脚本到source里

  1. :local assign-address  
  2. :local new-address  
  3. :local status  
  4. :local x  
  5. :set x 2  
  6. :for i from=1 to=$x do={  
  7.     :set status [/interface get [/interface find name=("ADSL" . $i)] running]  
  8.     :if ($status=true) do={  
  9.      :set new-address [/ip address get [/ip address find dynamic=yes interface=("ADSL" . $i)] address]  
  10.      :set new-address [:pick $new-address 0 ([:len $new-address] -3)]  
  11.      :set assign-address [/ip address get [/ip address find dynamic=no interface=("ADSL" . $i)] address]  
  12.      :set assign-address [:pick $assign-address 0 ([:len $assign-address] -3)]  
  13. :set new-gateway [/ip address get [/ip address find dynamic=yes interface=("ADSL" . $i)] network]  
  14. :set adckip [/tool netwatch get [/tool netwatch find comment=$i] host]  
  15.         :if ($assign-address != $new-address) do={ /ip address set [/ip address find comment=$i] address=$new-address network=$new-address broadcast=$new-address  
  16.         /ip route set [/ip route find comment=$i] gateway=$new-gateway]  
  17.         /ip firewall nat set [/ip firewall nat find comment=$i] to-addresses=$new-address  
  18.         /ip route set [/ip route find comment=$i] gateway=$new-gateway]  
  19.        }  
  20.     :if ($new-gateway != $adckip) do={/tool netwatch set [/tool netwatch find comment=$i] host=$new-gateway]  
  21. }  
  22.    }  
  23. } 

4.添加ADSL1当线脚本A1Down,自动停用NTH负载均衡所需的参数,并将标记3的网关设为ADSL2的网关,位置winbox-system-script 点“+ ”号,改name为A1Down,然后复制下面的脚本到source里

  1. :local new-gateway  
  2. :set new-gateway [/ ip address get [/ip address find dynamic=yes interface=ADSL2] network]  
  3. /ip route set [/ip route find comment=3] gateway=$new-gateway  
  4. /ip route enable [/ip route find comment=3]  
  5. /ip route disabled [/ip route find comment=1]  
  6. /ip route disabled [/ip route find comment=2]  
  7. /ip firewall nat enable [/ip firewall nat find comment=3]  
  8. /ip firewall nat disabled [/ip firewall nat find comment=1]  
  9. /ip firewall nat disabled [/ip firewall nat find comment=2] 

5.添加ADSL2当线脚本A2Down,自动停用NTH负载均衡所需的参数,并将标记3的网关设为ADSL1的网关,位置winbox-system-script 点“+ ”号,改name为A2Down,然后复制下面的脚本到source里

  1. :local new-gateway  
  2. :set new-gateway [/ ip address get [/ip address find dynamic=yes interface=ADSL1] network]  
  3. /ip route set [/ip route find comment=3] gateway=$new-gateway  
  4. /ip route enable [/ip route find comment=3]  
  5. /ip route disabled [/ip route find comment=1]  
  6. /ip route disabled [/ip route find comment=2]  
  7. /ip firewall nat enable [/ip firewall nat find comment=3]  
  8. /ip firewall nat disabled [/ip firewall nat find comment=1]  
  9. /ip firewall nat disabled[/ip firewall nat find comment=2] 

#p#6.添加ADSL掉线判断NETWATCH

  1. / tool netwatch  
  2. add host=A1网关 timeout=1s interval=1m up-script="" down-script="A1Down" comment="1" 
  3. add host=A2网关 timeout=1s interval=1m up-script="" down-script="A2Down" comment="2" 

7.添加双线判断正常脚本allup。即两条线路UP的时候开启NTH负载均衡。位置winbox-system-script 点“+ ”号,改name为allup,然后复制下面的脚本到source里

  1. :global a  
  2. :global b  
  3. :set a [/tool netwatch get [/tool netwatch find comment=1] status]  
  4. :set b [/tool netwatch get [/tool netwatch find comment=2] status]  
  5. :if (($a="up") && ($b="up")) do={  
  6. /ip route disabled [/ip route find comment=3]  
  7. /ip route enable [/ip route find comment=1]  
  8. /ip route enable [/ip route find comment=2]  
  9. /ip firewall nat disabled [/ip firewall nat find comment=3]  
  10. /ip firewall nat enable [/ip firewall nat find comment=1]  
  11. /ip firewall nat enable [/ip firewall nat find comment=2]} 

8.添加脚本计划任务

  1. / system scheduler  
  2. add name="tasksync" on-event=sync start-date=jan/01/1970 start-time=00:00:00 interval=10s comment="" 
  3. add name="taskup" on-event=allup start-date=jan/01/1970 start-time=00:00:00 interval=10s comment="" 

 

相关内容

热门资讯

PHP新手之PHP入门 PHP是一种易于学习和使用的服务器端脚本语言。只需要很少的编程知识你就能使用PHP建立一个真正交互的...
网络中立的未来 网络中立性是什... 《牛津词典》中对“网络中立”的解释是“电信运营商应秉持的一种原则,即不考虑来源地提供所有内容和应用的...
各种千兆交换机的数据接口类型详... 千兆交换机有很多值得学习的地方,这里我们主要介绍各种千兆交换机的数据接口类型,作为局域网的主要连接设...
粉嫩如何诠释霸道 东芝M805... “霸道粉”是个什么玩意东芝M805拿过来的时候,笔者扑哧笑了,不是笑这款笔记本,而是笑这款产品的颜色...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
什么是大数据安全 什么是大数据... 在《为什么需要大数据安全分析》一文中,我们已经阐述了一个重要观点,即:安全要素信息呈现出大数据的特征...
只需三步,让你掌握阿尔法路由器... 请参照以下阿尔法路由器设置方法,通过浏览器进入及设置宽带路由器。经过这三个步骤的设置,基本上能够熟悉...
如何更省钱? 近期特价热门硒鼓... 如今激光打印设备已经成为商务或企业的绝对主力办公设备,但采购者往往忽视了激光打印设备所用的耗材,相对...
全面诠释网络负载均衡 负载均衡的出现大大缓解了服务器的压力,更是有效的利用了资源,提高了效率。那么我们现在来说一下网络负载...
如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...