king

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

king 运维技术 2022-11-15 424浏览 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.普通脚本设置

/ipfirewallnat 
addchain=srcnataction=masqueradecomment="3"disabled=yes 
/ipaddress 
addaddress=A1IPinterface=ADSL1comment="1"disabled=no 
addaddress=A2IPinterface=ADSL2comment="2"disabled=no 
/iproute 
adddst-address=0.0.0.0/0gateway=A1网关routing-mark=1comment="1"
adddst-address=0.0.0.0/0gateway=A2网关routing-mark=2comment="2"
adddst-address=0.0.0.0/0gateway=A1网关comment="3"

2.添加NAT,NTH脚本

/ipfirewallmangle 
addchain=preroutingin-interface=LANprotocol=tcpconnection-state=newnth=1,1,0action=mark-connection\ 
new-connection-mark=1passthrough=yescomment="A1NTH"disabled=no 
addchain=preroutingin-interface=LANprotocol=tcpconnection-mark=1action=mark-routingnew-routing-mark=1\ 
passthrough=nocomment="A1NTH"disabled=no 
addchain=preroutingin-interface=LANprotocol=tcpconnection-state=newnth=1,1,1action=mark-connection\ 
new-connection-mark=2passthrough=yescomment="A2NTH"disabled=no 
addchain=preroutingin-interface=LANprotocol=tcpconnection-mark=2action=mark-routingnew-routing-mark=2\ 
passthrough=nocomment="A2NTH"disabled=no 
/ipfirewallnat 
addchain=srcnatconnection-mark=1action=src-natto-addresses=A1IPto-ports=0-65535comment="1"disabled=no 
addchain=srcnatconnection-mark=2action=src-natto-addresses=A2IPto-ports=0-65535comment="2"disabled=no

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

:localassign-address 
:localnew-address 
:localstatus 
:localx 
:setx2 
:forifrom=1to=$xdo={ 
:setstatus[/interfaceget[/interfacefindname=("ADSL".$i)]running] 
:if($status=true)do={ 
:setnew-address[/ipaddressget[/ipaddressfinddynamic=yesinterface=("ADSL".$i)]address] 
:setnew-address[:pick$new-address0([:len$new-address]-3)] 
:setassign-address[/ipaddressget[/ipaddressfinddynamic=nointerface=("ADSL".$i)]address] 
:setassign-address[:pick$assign-address0([:len$assign-address]-3)] 
:setnew-gateway[/ipaddressget[/ipaddressfinddynamic=yesinterface=("ADSL".$i)]network] 
:setadckip[/toolnetwatchget[/toolnetwatchfindcomment=$i]host] 
:if($assign-address!=$new-address)do={/ipaddressset[/ipaddressfindcomment=$i]address=$new-addressnetwork=$new-addressbroadcast=$new-address 
/iprouteset[/iproutefindcomment=$i]gateway=$new-gateway] 
/ipfirewallnatset[/ipfirewallnatfindcomment=$i]to-addresses=$new-address 
/iprouteset[/iproutefindcomment=$i]gateway=$new-gateway] 
} 
:if($new-gateway!=$adckip)do={/toolnetwatchset[/toolnetwatchfindcomment=$i]host=$new-gateway] 
} 
} 
}

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

:localnew-gateway 
:setnew-gateway[/ipaddressget[/ipaddressfinddynamic=yesinterface=ADSL2]network] 
/iprouteset[/iproutefindcomment=3]gateway=$new-gateway 
/iprouteenable[/iproutefindcomment=3] 
/iproutedisabled[/iproutefindcomment=1] 
/iproutedisabled[/iproutefindcomment=2] 
/ipfirewallnatenable[/ipfirewallnatfindcomment=3] 
/ipfirewallnatdisabled[/ipfirewallnatfindcomment=1] 
/ipfirewallnatdisabled[/ipfirewallnatfindcomment=2]

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

:localnew-gateway 
:setnew-gateway[/ipaddressget[/ipaddressfinddynamic=yesinterface=ADSL1]network] 
/iprouteset[/iproutefindcomment=3]gateway=$new-gateway 
/iprouteenable[/iproutefindcomment=3] 
/iproutedisabled[/iproutefindcomment=1] 
/iproutedisabled[/iproutefindcomment=2] 
/ipfirewallnatenable[/ipfirewallnatfindcomment=3] 
/ipfirewallnatdisabled[/ipfirewallnatfindcomment=1] 
/ipfirewallnatdisabled[/ipfirewallnatfindcomment=2]

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

/toolnetwatch 
addhost=A1网关timeout=1sinterval=1mup-script=""down-script="A1Down"comment="1"
addhost=A2网关timeout=1sinterval=1mup-script=""down-script="A2Down"comment="2"

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

:globala 
:globalb 
:seta[/toolnetwatchget[/toolnetwatchfindcomment=1]status] 
:setb[/toolnetwatchget[/toolnetwatchfindcomment=2]status] 
:if(($a="up")&&($b="up"))do={ 
/iproutedisabled[/iproutefindcomment=3] 
/iprouteenable[/iproutefindcomment=1] 
/iprouteenable[/iproutefindcomment=2] 
/ipfirewallnatdisabled[/ipfirewallnatfindcomment=3] 
/ipfirewallnatenable[/ipfirewallnatfindcomment=1] 
/ipfirewallnatenable[/ipfirewallnatfindcomment=2]}

8.添加脚本计划任务

/systemscheduler 
addname="tasksync"on-event=syncstart-date=jan/01/1970start-time=00:00:00interval=10scomment=""
addname="taskup"on-event=allupstart-date=jan/01/1970start-time=00:00:00interval=10scomment=""

继续浏览有关 网络 的文章
发表评论