[GTER] Failover de link ADSL
Artur Renato Araujo da Silva
artur at css.com.br
Tue Mar 24 12:18:23 -03 2009
Segue o arquivo baixado do link.
Artur
#!/bin/sh
# Script de Balanceamento de Carga - LoadBalance Script
# Created by Silvio Cesar L. dos Santos - gulbf.com.br
#
# This file is free software you can redistribute it and/or modify
# it under the terms of the GNU General Public License (GPL) as
# published by the Free Software Foundation, in version 2
#
# @(#)balanceamento.sh v1.0 Sat Mar 14 12:45:56 PDT 2009
#
# Sintaxe: ./balanceamento.sh [add|del]
##################### VARI<C1>VEIS AJUST<C1>VEIS #####################
#
# DEBUG valor = "echo" o stdout vai pro monitor e n<E3>o aplica o comando
loadbalance
# serve apenas para voc<EA> visualizar os comandos que ser<E3>o aplicados
debug=""
# Link[n]Ativo =[0|1] desativa ou ativa link no loadbalance
############## LINK0 ##############
LinkAtivo[0]="1"
IPLink[0]="11.11.11.101"
NetLink[0]="11.11.11.0/24"
GWLink[0]="11.11.11.100"
EthLink[0]="eth7"
LINK[0]="rederio"
############## LINK1 ##############
LinkAtivo[1]="1"
IPLink[1]="10.10.10.2"
NetLink[1]="10.10.10.0/30"
GWLink[1]="10.10.10.1"
EthLink[1]="eth3"
LINK[1]="adsl1"
############## LINK2 ##############
LinkAtivo[2]="1"
IPLink[2]="10.10.10.249"
NetLink[2]="10.10.10.248/30"
GWLink[2]="10.10.10.250"
EthLink[2]="eth4"
LINK[2]="adsl2"
############## LINK3 ##############
LinkAtivo[3]="1"
IPLink[3]="10.10.10.253"
NetLink[3]="10.10.10.252/30"
GWLink[3]="10.10.10.254"
EthLink[3]="eth2"
LINK[3]="adsl3"
############## LINK4 ##############
LinkAtivo[4]="1"
IPLink[4]="10.10.10.245"
NetLink[4]="10.10.10.244/30"
GWLink[4]="10.10.10.246"
EthLink[4]="eth5"
LINK[4]="adsl4"
############## LINK5 ##############
LinkAtivo[5]="1"
IPLink[5]="10.10.10.241"
NetLink[5]=10.10.10.240/30""
GWLink[5]="10.10.10.242"
EthLink[5]="eth6"
LINK[5]="adsl5"
############# Qual link sair<E1> os pacotes marcados com 0x4 via IPTABLES na
tabela MANGLE ################
tabela_rules=${LINK[0]}
############# Total de Links informados ativos ou n<E3>o
total_links=6
##################### N<C3>O MUDE NADA DAQUI PARA BAIXO
#####################
# Desabilitando o filtro de pacotes do martian source
for eee in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo 0 > $eee
done
# add ou del = tipo de comando na tabela
# Exemplo ./balanceamento.sh add ou ./balanceamento.sh del
cmd=${1}
if [ "${debug}" = "echo" ]; then
echo""
echo "
######################################################################################"
echo ""
echo ""
echo " Modo DEBUG ativo !! Regras n<E3>o ser<E3>o
aplicadas, apenas visualiza<E7><E3>o."
echo ""
echo ""
echo "
######################################################################################"
echo""
fi
${debug} ip rule flush
${debug} ip rule add from all lookup main pref 32766
${debug} ip rule add from all lookup default pref 32767
echo "#" > /etc/iproute2/rt_tables
echo "# reserved values" >> /etc/iproute2/rt_tables
echo "#" >> /etc/iproute2/rt_tables
echo "255 local" >> /etc/iproute2/rt_tables
echo "254 main" >> /etc/iproute2/rt_tables
echo "253 default" >> /etc/iproute2/rt_tables
if [ "${1}" == "add" -o "${1}" == "del" ] ; then
# Pacotes marcados saem por uma interface apenas
${debug} ip route del default
fi
# Carrega Tabelas dos links
if [ "${cmd}" = "del" ]; then
$debug ip route add default via ${GWLink[0]}
fi
if [ "${cmd}" = "add" ]; then
routecmd="ip route add default scope global "
i=0
while [ $i -lt $total_links ];
do
echo "`expr ${i} + 31` ${LINK[$i]}" >> /etc/iproute2/rt_tables
${debug} ip route flush table ${LINK[$i]} >> /dev/null
if [ ${LinkAtivo[$i]} = "1" ]; then
routecmd="${routecmd} nexthop via ${GWLink[$i]} dev
${EthLink[$i]} weight 1 "
fi
if [ ${LinkAtivo[$i]} = "1" ]; then
${debug} ip rule ${cmd} from ${IPLink[$i]} table ${LINK[$i]} pref
`expr ${i} + 31` >> /dev/null
${debug} ip route ${cmd} ${NetLink[$i]} dev ${EthLink[$i]} proto
kernel scope link src ${IPLink[$i]} table ${
LINK[$i]} >> /dev/null
${debug} ip route add default via ${GWLink[$i]} table ${LINK[$i]}
>> /dev/null
fi
i=$(($i+1))
done
# Roda comando de manuten<E7><E3>o das rotas default
${debug} ip rule ${cmd} fwmark 4 lookup ${tabela_rules} prio 3 >>
/dev/null
${debug} ${routecmd}
${debug} ip route flush cache
fi
if [ ! "${1}" == "add" -a ! "${1}" == "del" ] ; then
#clear
echo "
######################################################################################"
echo ""
echo ""
echo " Informe a Sintaxe correta:
balancemento.sh add ou del"
echo ""
echo ""
echo "
######################################################################################"
fi
echo "0 unspec" >> /etc/iproute2/rt_tables
echo "# local" >> /etc/iproute2/rt_tables
echo "#" >> /etc/iproute2/rt_tables
echo "#1 inr.ruhep" >> /etc/iproute2/rt_tables
2009/3/24 Christian Lyra <lyra at pop-pr.rnp.br>
> 2009/3/24 silvio.cesar at unigranrio.edu.br <silvio.cesar at unigranrio.edu.br>:
> > Bom dia,
> >
> > Criei um script chamado balanceamento.sh que serve para manipular o
> > balanceamento de carga para N links.
> >
> > Dêem uma olhada pois vai facilitar a vida um bocado.
> >
> > http://gulbf.com.br/?q=node/145
>
> Gostaria de dar uma olhada... vc poderia colocar o script em algum
> lugar em que vc NAO precise se cadastrar para poder baixar?
>
>
> > Att,
> >
> > Silvio Cesar L. dos Santos
> > DTI - Divisão de Tecnologia da Informação/Analista de Redes Pleno
> > UNIGRANRIO - Universidade do Grande Rio
> > +55 21 2672-7720
> > silvio.cesar at unigranrio.edu.br
> > http://www.unigranrio.br
> >
> >
> > Marcus Andree escreveu:
> >> Tenho minhas duvidas quanto ao dhclient, mas o dhcpcd eu sei que faz
> isso.
> >>
> >> Nao ha necessidade de "micro-daemon". Tirei as linhas abaixo de um man
> page
> >> do dhcpcd disponivel na internet.
> >>
> >> Basta criar um script que tenha a inteligencia para ler o arquivo
> >> <HostInfoFilePath>
> >> e aceite as opcoes <up|down|new>, passadas via linha de comando.
> >>
> >> Opcionalmente, pode-se utilizar a chave "-d" para ativar linhas
> >> (printf ou echo) de
> >> depuracao.
> >>
> >>
> >> -c <ExecFilePath>
> >> dhcpcd will try to execute <ExecFilePath> script instead of
> >> default <ConfigDir>/dhcpcd.exe script every time it configures or
> >> brings down the interface. See the description of dhcpcd.exe script in
> >> FILES section below.
> >>
> >> /etc/dhcpc
> >> Default <ConfigDir> directory used for storing files created by
> >> dhcpcd. See option -L <ConfigDir> above.
> >> <ConfigDir>/dhcpcd-<interface>.info
> >> file in which dhcpcd saves the host information. The word
> >> <interface> is actually replaced with the network interface name like
> >> eth0 to which dhcpcd is attached.
> >> <ConfigDir>/dhcpcd.exe
> >> file, which dhcpcd will try to execute whenever it configures or
> >> brings down the interface. The path to this executable script can be
> >> changed with -c <ExecFilePath> option. Dhcpcd passes 3 parameters to
> >> dhcpcd.exe script:
> >> dhcpcd.exe <HostInfoFilePath> <up|down|new> [-d]
> >> The first parameter <HostInfoFilePath> is path to
> >> dhcpcd-<interface>.info file. The word <interface> is actually
> >> replaced with interface name dhcpcd is attached to, e.g. "eth0". The
> >> second parameter values <up|down|new> mean the interface has been
> >> brought up with the same IP address as before ("up"), or with the new
> >> IP address ("new"), or the interface has been brought down ("down").
> >> Parameter -d is passed in a case dhcpcd has been started with -d debug
> >> flag.
> >>
> >> 2009/3/23 Leonardo Amaral <leleobhz at leleobhz.org>:
> >>> Estou convicto de que, já que o dhcpd/dhclient podem receber scripts de
> fora
> >>> quando mudam de estado. Posso escrever um micro-daemon pra detectar
> quando a
> >>> rede caiu e quando cair dou ifup e ifdown nas interfaces e nisso o
> dhclient
> >>> puxa automaticamente as novas rotas e adiciona como next-hop. O que
> gostaria
> >>> de perguntar é se tem alguma documentação sobre a forma de
> funcionamento
> >>> desses scripts do DHClient/dhcpd.
> >>>
> >>> Marcus Andree escreveu:
> >>>> Leonardo,
> >>>>
> >>>> Em vez de utilizar o dhclient, use o dhcpcd. Ele pode ser configurado
> >>>> para executar um shell script quando
> starta/stopa/configura/reconfigura o
> >>>> IP da
> >>>> placa de rede.
> >>>>
> >>>>
> >>>> 2009/3/20 Leonardo Amaral <leleobhz at leleobhz.org>:
> >>>>
> >>>>> Certo. Outro problema: O IP dos 2 são dinamicos (nem dinamicamente
> >>>>> fixados
> >>>>> eles são). Ou seja, provavelmente no timeout do lease do DHCP eu vou
> >>>>> levar
> >>>>> outro IP diferente. Como eu posso tratar isso?
> >>>>>
> >>>>> Bruno at openline.com.br escreveu:
> >>>>>
> >>>>>> --- Leonardo Amaral <leleobhz at leleobhz.org> escreveu:
> >>>>>>
> >>>>>>
> >>>>>>> O problema é adivinhar a rota que a empresa deu. Cada vez vem uma
> >>>>>>> diferente....
> >>>>>>>
> >>>>>>>
> >>>>>> #!/bin/bash
> >>>>>> set ` netstat -rn|egrep ^0.0.0.0|grep ethX `
> >>>>>> echo Rota default = $2
> >>>>>>
> >>>>>> []s, !3runo
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>> Alexandro Corrêa - SulSoft escreveu:
> >>>>>>>
> >>>>>>>
> >>>>>>>> Sobre essa questão de rotas criadas pelo DHCLIENT, depois de
> adquirir
> >>>>>>>> o IP eu costumo rodar um script que remove todas as rotas e cria
> >>>>>>>> novamente conforme minhas necessidades.
> >>>>>>>> Tem funcionado bem até o momento...
> >>>>>>>>
> >>>>>>>> Atenciosamente,
> >>>>>>>>
> >>>>>>>> Alexandro Corrêa
> >>>>>>>>
> >>>>> --
> >>>>> gter list https://eng.registro.br/mailman/listinfo/gter
> >>>>>
> >>>>>
> >>>> --
> >>>> gter list https://eng.registro.br/mailman/listinfo/gter
> >>>>
> >>>
> >>> --
> >>> gter list https://eng.registro.br/mailman/listinfo/gter
> >>>
> >> --
> >> gter list https://eng.registro.br/mailman/listinfo/gter
> > --
> > gter list https://eng.registro.br/mailman/listinfo/gter
> >
>
>
>
> --
> Christian Lyra
> PoP-PR/RNP
> --
> gter list https://eng.registro.br/mailman/listinfo/gter
>
More information about the gter
mailing list