LAB project: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(→HA) |
||
Line 28: | Line 28: | ||
#!/bin/bash | #!/bin/bash | ||
#pacheco at infocepo.com | #pacheco at infocepo.com | ||
domainName=$(cat domainName) | |||
portNumber=$(cat portNumber) | |||
publicHost1=$(cat publicHost1) | |||
publicHost2=$(cat publicHost2) | |||
echo "$(date): init" | echo "$(date): init" | ||
#Clean | #Clean | ||
stop${domainName}.sh | |||
#If I was the master sleep a little ! | #If I was the master sleep a little ! | ||
ipPublic="$(dig +short myip.opendns.com @resolver1.opendns.com )" | ipPublic="$(dig +short myip.opendns.com @resolver1.opendns.com )" | ||
ipMasterOld="$(nslookup | ipMasterOld="$(nslookup ${domainName} |sed -rn 's#^Address: (.*)$#\1#p' )" | ||
[ "${ipPublic}" = "${ipMasterOld}" ] &&sleep 240 | [ "${ipPublic}" = "${ipMasterOld}" ] &&sleep 240 | ||
#Wait master down (big loop) | #Wait master down (big loop) | ||
while (nc -zw2 | while (nc -zw2 ${domainName} 443 >/dev/null 2>&1 ||(sleep 10 ;nc -zw4 ${domainName} 443 >/dev/null 2>&1 ) );do | ||
if [ -z "$(find | if [ -z "$(find ha_synced -type f -mmin -60 2>/dev/null )" ] ;then | ||
rsync --numeric-ids --delete --force --modify-window=1 --ignore-errors --block-size=128.00K --inplace --no-whole-file \ | rsync --numeric-ids --delete --force --modify-window=1 --ignore-errors --block-size=128.00K --inplace --no-whole-file \ | ||
-z --compress-level=9 \ | -z --compress-level=9 \ | ||
Line 57: | Line 53: | ||
--exclude=rsync-rollback \ | --exclude=rsync-rollback \ | ||
--exclude=.rsync_* \ | --exclude=.rsync_* \ | ||
--rsh="ssh -i | --rsh="ssh -i ~/.ssh/storage@${domainName}.key -p ${portNumer} -oStrictHostKeyChecking=no" \ | ||
${domainName}:/storage/ /storage/ &&touch ha_synced | |||
fi | fi | ||
sleep 10 | sleep 10 | ||
Line 64: | Line 60: | ||
#Maybe it's me down ! If INTERNET down, reboot | #Maybe it's me down ! If INTERNET down, reboot | ||
! ping -w2 -c1 | ! ping -w2 -c1 ${publicHost} >/dev/null 2>&1 &&systemctl start kexec.target | ||
#Become master | #Become master | ||
#Register DNS | #Register DNS | ||
ipMasterDown="$(nslookup | ipMasterDown="$(nslookup ${domainName} |sed -rn 's#^Address: (.*)$#\1#p' )" | ||
curl 'https://dynamicdns.park-your-domain.com/update?host=@&domain= | curl 'https://dynamicdns.park-your-domain.com/update?host=@&domain=${domainName}&password='"$(cat .namecheap-password )"'&ip='"${ipPublic}" | ||
#Random startup time | #Random startup time | ||
sleep $((RANDOM%10)) | sleep $((RANDOM%10)) | ||
${domainName}Start.sh & | |||
#Wait DNS propagation | #Wait DNS propagation | ||
Line 82: | Line 78: | ||
echo "$(date): up" | echo "$(date): up" | ||
[ "${ipPublic}" = "${ipMasterDown}" ] &&ipMasterDown="" | [ "${ipPublic}" = "${ipMasterDown}" ] &&ipMasterDown="" | ||
while [ "${ipPublic}" = "$(nslookup | while [ "${ipPublic}" = "$(nslookup ${domainName} |sed -rn 's#^Address: (.*)$#\1#p' )" ] \ | ||
&&( ! nc -zw2 "${ipMasterDown}" 443 >/dev/null 2>&1 ) \ | &&( ! nc -zw2 "${ipMasterDown}" 443 >/dev/null 2>&1 ) \ | ||
&&(nc -zw2 "${ipPublic}" 443 >/dev/null 2>&1 ||nc -zw4 "${ipPublic}" 443 >/dev/null 2>&1 ) \ | &&(nc -zw2 "${ipPublic}" 443 >/dev/null 2>&1 ||nc -zw4 "${ipPublic}" 443 >/dev/null 2>&1 ) \ | ||
&&(nc -zw2 "${ipMasterDown}" | &&(nc -zw2 "${ipMasterDown}" ${portNumer} >/dev/null 2>&1 ||ping -w2 -c1 ${publicHost} >/dev/null 2>&1 ||ping -w2 -c1 ${publicHost2} >/dev/null 2>&1 ) ;do | ||
sleep 4 | sleep 4 | ||
done | done | ||
Line 91: | Line 87: | ||
#Stop | #Stop | ||
stop${domainName}.sh | |||
#Reboot | #Reboot |
Revision as of 10:01, 27 February 2022
Resilient, low power and encrypted LAB CLOUD project.
Diagram
DNS provider
My LAB tools
- DEBIAN (Generic OS)
- x86&amd64 CPU (for ARM I will use QEMU emulator)
- Diagram editor
- MEDIAWIKI (sharing editor)
- LXD/SNAP (container&virtual tool)
- tcpdump (Network monitoring)
- nmap (Network scanner)
Tested in this LAB
- NEXTCLOUD
- This site is hosted on it.
- KUBERNETES Cluster
- MARIADB GALERA Cluster
- OPENSTACK
- PROMETHEUS
- GLUSTERFS
- KATA
HA
I love COROSYNC/PACEMAKER, but for this LAB I wanted something from scratch:
#!/bin/bash
#pacheco at infocepo.com
domainName=$(cat domainName)
portNumber=$(cat portNumber)
publicHost1=$(cat publicHost1)
publicHost2=$(cat publicHost2)
echo "$(date): init"
#Clean
stop${domainName}.sh
#If I was the master sleep a little !
ipPublic="$(dig +short myip.opendns.com @resolver1.opendns.com )"
ipMasterOld="$(nslookup ${domainName} |sed -rn 's#^Address: (.*)$#\1#p' )"
[ "${ipPublic}" = "${ipMasterOld}" ] &&sleep 240
#Wait master down (big loop)
while (nc -zw2 ${domainName} 443 >/dev/null 2>&1 ||(sleep 10 ;nc -zw4 ${domainName} 443 >/dev/null 2>&1 ) );do
if [ -z "$(find ha_synced -type f -mmin -60 2>/dev/null )" ] ;then
rsync --numeric-ids --delete --force --modify-window=1 --ignore-errors --block-size=128.00K --inplace --no-whole-file \
-z --compress-level=9 \
-aAXxv \
--backup-dir=rsync-rollback/$(date '+%Y-%m-%d') \
--exclude=rsync-rollback \
--exclude=.rsync_* \
--rsh="ssh -i ~/.ssh/storage@${domainName}.key -p ${portNumer} -oStrictHostKeyChecking=no" \
${domainName}:/storage/ /storage/ &&touch ha_synced
fi
sleep 10
done
#Maybe it's me down ! If INTERNET down, reboot
! ping -w2 -c1 ${publicHost} >/dev/null 2>&1 &&systemctl start kexec.target
#Become master
#Register DNS
ipMasterDown="$(nslookup ${domainName} |sed -rn 's#^Address: (.*)$#\1#p' )"
curl 'https://dynamicdns.park-your-domain.com/update?host=@&domain=${domainName}&password='"$(cat .namecheap-password )"'&ip='"${ipPublic}"
#Random startup time
sleep $((RANDOM%10))
${domainName}Start.sh &
#Wait DNS propagation
sleep $((240-25))
#Monitor
echo "$(date): up"
[ "${ipPublic}" = "${ipMasterDown}" ] &&ipMasterDown=""
while [ "${ipPublic}" = "$(nslookup ${domainName} |sed -rn 's#^Address: (.*)$#\1#p' )" ] \
&&( ! nc -zw2 "${ipMasterDown}" 443 >/dev/null 2>&1 ) \
&&(nc -zw2 "${ipPublic}" 443 >/dev/null 2>&1 ||nc -zw4 "${ipPublic}" 443 >/dev/null 2>&1 ) \
&&(nc -zw2 "${ipMasterDown}" ${portNumer} >/dev/null 2>&1 ||ping -w2 -c1 ${publicHost} >/dev/null 2>&1 ||ping -w2 -c1 ${publicHost2} >/dev/null 2>&1 ) ;do
sleep 4
done
echo "$(date): down"
#Stop
stop${domainName}.sh
#Reboot
systemctl start kexec.target
Other
If you have ideas to improve something, send me an e-mail (pacheco at infocepo.com).