Visite também: Br-Linux ·  VivaOLinux ·  LinuxSecurity ·  Dicas-L ·  NoticiasLinux ·  SoftwareLivre.org ·  [mais]
Voltar   Under-Linux.org > UnderLinux Wiki
Fóruns Wiki Classificados Videos Jogos Grupos Sociais RSS Feeds FAQ Termos de Uso Contato Sobre
Registrar FotosBlogs Calendário Marcar Fóruns Como Lidos

Publicidade

Ferramentas pessoais
Publicidade

From UnderLinux Wiki

Oi amigos


Este é meu primeiro script para Fail-Over com dois Links fazendo Load-Balance e o terceiro link de backup. Você pode dar uma olhada e pensar para que eu preciso disso? ou talvez você possa usa-lo caso necessite.

scheduler:

/ system scheduler 
add name="ping_google_link_A-up" on-event=schedule_A_up start-date=jan/01/1970 \
    start-time=00:00:00 interval=5s comment="" disabled=yes 
add name="ping_google_link_A-down" on-event=schedule_A_down \
    start-date=jan/01/1970 start-time=00:00:00 interval=5s comment="" \
    disabled=no 

scripts go up:

#set variables
:local pingcount  3
:local ipA 211.24.149.42
:local GatewayA 211.24.149.41
:local ipB 211.24.139.114
:local GatewayB 211.24.139.113
:local GatewayC 192.168.0.250

#ping gateways with src
:local pingresultA [/ping www.google.com src-address=$ipA count=$pingcount]
:local pingresultB [/ping www.google.com src-address=$ipB count=$pingcount]


#if link_A is DOWN and link_B is UP then:
:if (($pingresultA=0) && ($pingresultB=3)) do={
/ip route set [find comment="Default Gateway"] gateway=$GatewayB 
}

#if link_A is UP and link_B is DOWN then:
:if (($pingresultA=3) && ($pingresultB=0)) do={
/ip route set [find comment="Default Gateway"] gateway=$GatewayA
}

#if both link DOWN:
:if (($pingresultA=0) && ($pingresultB=0)) do={
/ip route set [find comment="Default Gateway"] gateway=$GatewayC
}

# Link A or Link B both are UP:
:if (($pingresultA=$pingcount) && ($pingresultB=$pingcount)) do={

#send alert email
/tool e-mail send subject=($ipA . "is up now") \
body=("the gateway is backed up at: " . [/system clock get date]) \ to=("zirnevis@gmail.com")

#disable all multi-session balancing mangles
/ip firewall mangle set [find chain=prerouting in-interface=LAN \
connection-mark=even action=mark-routing passthrough=no] disabled=no
/ip firewall mangle set [find chain=prerouting in-interface=LAN \
connection-state=new new-connection-mark=even passthrough=yes \
action=mark-connection nth=1,1,1] disabled=no
/ip firewall mangle set [find chain=prerouting in-interface=LAN \
connection-mark=odd action=mark-routing new-routing-mark=odd \
passthrough=no] disabled=no
/ip firewall mangle set [find chain=prerouting in-interface=LAN nth=1,1,0 \
action=mark-connection new-connection-mark=odd \
passthrough=yes] disabled=no

#disable current scheduler
/system scheduler set [find name=ping_google_link_A-down] disabled=no

#enable -up scheduler
/system scheduler set [find name=ping_google_link_A-up] disabled=yes

#set gateway back to GatewayB
/ip route set [find comment="Default Gateway"] gateway=$GatewayB
}


script go down:

#set variables
:local pingcount  3
:local ipA 211.24.149.42
:local GatewayA 211.24.149.41
:local ipB 211.24.139.114
:local GatewayB 211.24.139.113
:global state no

#ping gateways with src
:local pingresultA [/ping www.google.com src-address=$ipA count=$pingcount]
:local pingresultB [/ping www.google.com src-address=$ipB count=$pingcount]

# Link A or Link B is down then>
:if (($pingresultA=0) || ($pingresultB=0)) do={
#send email
/tool e-mail send subject=($ipA . " is down") \
body=("the gateway is down now at: " . [/system clock get date]) \ to=("zirnevis@gmail.com")

#disable all multi-session balancing mangles
/ip firewall mangle set [find chain=prerouting in-interface=LAN \
connection-mark=even action=mark-routing passthrough=no] disabled=yes
/ip firewall mangle set [find chain=prerouting in-interface=LAN \
connection-state=new new-connection-mark=even passthrough=yes \
action=mark-connection nth=1,1,1] disabled=yes
/ip firewall mangle set [find chain=prerouting in-interface=LAN \
connection-mark=odd action=mark-routing new-routing-mark=odd \
passthrough=no] disabled=yes
/ip firewall mangle set [find chain=prerouting in-interface=LAN nth=1,1,0 \
action=mark-connection new-connection-mark=odd \
passthrough=yes] disabled=yes

#disable current scheduler
/system scheduler set [find name=ping_google_link_A-down] disabled=yes

#enable -up scheduler
/system scheduler set [find name=ping_google_link_A-up] disabled=no

#set gateway to secondary or tertiary

#if link_A is DOWN and link_B is UP then:
:if (($pingresultA=0) && ($pingresultB>0)) do={
/ip route set [find comment="Default Gateway"] gateway=211.24.139.113 
}

#if link_A is UP and link_B is DOWN then:
:if (($pingresultA>0) && ($pingresultB=0)) do={
/ip route set [find comment="Default Gateway"] gateway=211.24.149.41
}

#if link_A and link_B both were DOWN then:
:if (($pingresultA=0) && ($pingresultB=0)) do={
/ip route set [find comment="Default Gateway"] gateway=192.168.0.250
}
}

Horários baseados na GMT -3. Agora são 09:06.


Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Powered by vbWiki Pro 1.3 RC5. Copyright ©2006-2007, NuHit, LLC