Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scripts
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
infra
scripts
Commits
0fb1eb59
Commit
0fb1eb59
authored
Nov 21, 2023
by
Joab Bremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rotas
parent
e4f9a7bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
0 deletions
+118
-0
rc.rotas
rotas_failover/rc.rotas
+74
-0
rotas_failover.sh
rotas_failover/rotas_failover.sh
+44
-0
No files found.
rotas_failover/rc.rotas
0 → 100644
View file @
0fb1eb59
#!/usr/bin/bash
### Link 1
IF_LINK1
=
"eth2"
MASK_LINK1
=
"29"
IP_LINK1
=
"177.101.123.202"
GW_LINK1
=
"177.101.123.201"
NT_LINK1
=
"177.101.123.200"
### Link 2
IF_LINK2
=
"eth3"
MASK_LINK2
=
"24"
IP_LINK2
=
"192.168.2.240"
GW_LINK2
=
"192.168.2.2"
NT_LINK2
=
"192.168.2.0"
up_link1_default
(){
logger
"fail-over: Alterando para a rota padrão via
$GW_LINK1
"
ip route del default via
$GW_LINK2
ip route add default via
$GW_LINK1
}
up_link2_default
(){
logger
"fail-over: Alterando para a rota padrão via
$GW_LINK1
"
ip route del default via
$GW_LINK1
ip route add default via
$GW_LINK2
}
check_link
()
{
while
[
"
$1
"
!=
"stop"
]
;
do
#logger "fail-over: validando links"
if
ping
-c
1
-I
$IF_LINK1
9.9.9.9 &> /dev/null
;
then
if
!
ip route show default |
grep
-q
"via
$GW_LINK1
"
;
then
up_link1_default
fi
fi
if
!
ping
-c
1
-I
$IF_LINK1
9.9.9.9 &> /dev/null
;
then
if
ip route show default |
grep
-q
"via
$GW_LINK1
"
;
then
up_link2_default
fi
fi
sleep
15
done
logger
"fail-over: Parando Servico"
}
main
(){
logger
"fail-over: Iniciando Servico"
#Definindo rotas link principal
ip route add
$NT_LINK1
/
$MASK_LINK1
dev
$IF_LINK1
ip route add
$NT_LINK1
/
$MASK_LINK1
dev
$IF_LINK1
table T1
ip route add default via
$GW_LINK1
table T1
#Definindo rotas link Secundario
ip route add
$NT_LINK2
/
$MASK_LINK2
dev
$IF_LINK2
ip route add
$NT_LINK2
/
$MASK_LINK2
dev
$IF_LINK2
table T2
ip route add default via
$GW_LINK2
table T2
#Validando se link dedicado esta ativo e fazendo failover
ip route add 9.9.9.9 via
$GW_LINK1
ip route add 149.112.112.112 via
$GW_LINK2
#Criando novos encaminhamentos das tabelas
ip rule add from
$IP_LINK1
table T1
ip rule add from
$IP_LINK2
table T2
# Marca pacotes para sairem pelo link2
ip rule add fwmark 2 table T2
#verifica o link e definindo rota default
check_link
"
$1
"
}
main
rotas_failover/rotas_failover.sh
0 → 100644
View file @
0fb1eb59
####################################################################################
#Variaveis de instalação
RED
=
'\033[0;31m'
NC
=
'\033[0m'
# No Color
DT
=
$(
date
+%d%m%Y_%H%M%S
)
####################################################################################
disable_selinux
(){
sed
-i
/etc/selinux/config
-r
-e
's/^SELINUX=.*/SELINUX=disabled/g'
}
creating_service_rotas
(){
cat
>
/etc/systemd/system/rotas.service
<<
EOF
[Unit]
Description=Rotas e FailOver
After=network.target
[Service]
Type=simple
ExecStart=bash /etc/rc.d/rc.rotas
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
}
install_rota
(){
cd
/etc/rc.d/
wget http://git.usb.org.br/infra/scripts/raw/master/rc.rotas
-P
/etc/rc.d/
-O
rc.rotas
}
starting_service_rota
(){
systemctl
enable
rotas.service
--quiet
systemctl start rotas.service
--quiet
}
stty echo
echo
-e
"
${
RED
}
Iniciando Instalação
${
NC
}
"
echo
-e
"
${
RED
}
Desabilitando SE Linux
${
NC
}
"
disable_selinux
echo
-e
"
${
RED
}
Criando rotas.service
${
NC
}
"
creating_service_rotas
echo
-e
"
${
RED
}
instalando rc.rotas
${
NC
}
"
install_rota
echo
-e
"
${
RED
}
Iniciando rotas.service
${
NC
}
"
starting_service_rota
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment