Created
February 14, 2020 08:47
-
-
Save arashkaffamanesh/43e6dacf8aba04d73d39580e7f7cec8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# by casey siens | |
#RUN THIS AS ROOT. YOU MUST BE ABLE TO SSH TO EACH NODE AS ROOT! IGNORE THE RED WARNINGS WHEN THE SERVICES START DURING THE INSTALL!!! ALLOW THE SCRIPT TO FINISH!!! | |
#List of master node ips. | |
ha_master_ip_list="10.9.8.21 10.9.8.22 10.9.8.23" | |
#VIP for ha. | |
ha_vip="10.9.8.20" | |
#Create heartbeat preshared key. | |
heartbeat_pw="heartbeatpa55word" | |
#Create ha folder. | |
mkdir /root/ha | |
#Create ha.authkeys file | |
authkey=$(echo -n ${heartbeat_pw} | md5sum | awk '{print $1}') | |
echo "auth 1" > /root/ha/ha.authkeys | |
echo "1 md5 "${authkey} >> /root/ha/ha.authkeys | |
#Create haresources file | |
ha_master_1st_ip=$(echo ${ha_master_ip_list} | awk '{print $1}') | |
ha_master_1st_hostname=$(ssh -l root ${ha_master_1st_ip} hostname) | |
echo ${ha_master_1st_hostname}" "${ha_vip} > /root/ha/haresources | |
#Create haproxy.cfg | |
cat << EOF >> /root/ha/haproxy.cfg | |
global | |
user haproxy | |
group haproxy | |
defaults | |
mode http | |
log global | |
retries 2 | |
timeout connect 3000ms | |
timeout server 5000ms | |
timeout client 5000ms | |
frontend kubernetes | |
bind ${ha_vip}:6443 | |
option tcplog | |
mode tcp | |
default_backend kubernetes-master-nodes | |
backend kubernetes-master-nodes | |
mode tcp | |
balance roundrobin | |
option tcp-check | |
EOF | |
for host in ${ha_master_ip_list}; do | |
hostname=$(ssh -l root ${host} hostname) | |
echo "server "${hostname}" "${host}":6443 check fall 3 rise 2" >> /root/ha/haproxy.cfg | |
done | |
#Create heartbeat.cf files | |
for host in ${ha_master_ip_list}; do | |
hostname=$(ssh -l root ${host} hostname) | |
interface=$(ssh -l root ${host} ip -o -4 route show to default | awk '{print $5}') | |
cat << EOF >> /root/ha/heartbeat.${hostname}.cf | |
keepalive 2 | |
deadtime 10 | |
udpport 694 | |
bcast ${interface} | |
mcast ${interface} 225.0.0.1 694 1 0 | |
ucast ${interface} ${host} | |
udp ${interface} | |
logfacility local0 | |
EOF | |
for ha_host in ${ha_master_ip_list}; do | |
ha_name=$(ssh -l root ${ha_host} hostname) | |
echo "node "${ha_name} >> /root/ha/heartbeat.${hostname}.cf | |
done | |
#Scp the ha.cf file to each master node | |
ssh -l root ${host} mkdir -p /etc/ha.d | |
scp /root/ha/heartbeat.${hostname}.cf root@${host}:/etc/ha.d/ha.cf | |
done | |
#Scp the other config files to each master node | |
for host in ${ha_master_ip_list}; do | |
ssh -l root ${host} mkdir -p /etc/haproxy | |
ssh -l root ${host} apt-get install -y haproxy heartbeat | |
scp /root/ha/haproxy.cfg root@${host}:/etc/haproxy/haproxy.cfg | |
scp /root/ha/ha.authkeys root@${host}:/etc/ha.d/authkeys | |
scp /root/ha/haresources root@${host}:/etc/ha.d/haresources | |
ssh -l root ${host} chmod 600 /etc/ha.d/authkeys | |
ssh -l root ${host} systemctl enable haproxy | |
ssh -l root ${host} systemctl start haproxy | |
ssh -l root ${host} systemctl enable heartbeat | |
ssh -l root ${host} systemctl start heartbeat | |
done | |
systemctl status haproxy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment