-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
154 lines (140 loc) · 5.04 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# SIF Installation Script
if [ $EUID != 0 ]; then
sudo "$0" "$@"
exit $?
fi
# -----------------------
# Pull working directory
# -----------------------
wd=$(dirname `dirname "$0"`)
echo "****************************************************"
echo "***************** SIF INSTALLER ********************"
echo "****************************************************"
echo
if [ -f /lib/systemd/system/sif.service ]; then
echo -e "\n* SIF Service already installed. Exiting."
exit
fi
echo "Please ensure your system meets all requirements listed in README file before installing!"
echo "STEP 1) SIF Service Install"
while true; do
read -p "Are you ready to install SIF? (y/n)" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo "Exiting installer..."; exit;;
* ) echo "Please answer y or n.";;
esac
done
echo
echo "STEP 2) CHOOSE SIF HOST ID"
echo "SIF used a unique 1 or 0 identifier for each host in the cluster."
echo "Each host MUST have a unique ID or SIF will not function correctly."
while true; do
read -p "Which ID should this host use? (0 or 1?): " hostid
case $hostid in
[0]* ) pairid=1; echo "This host will use a HOSTID of 0. Ensure the other host uses 1."; break;;
[1]* ) pairid=0; echo "This host will use a HOSTID of 1. Ensure the other host uses 0."; break;;
* ) echo "Please answer 0 or 1.";;
esac
done
echo "*Creating SIF Directory"
mkdir /opt/sif
echo "*Copying SIF Scripts"
cp $wd/* /opt/sif/ > /dev/null
echo "*Setting execute bit for SIF scripts"
chmod +x /opt/sif/sif*
echo "*Copying service file"
cp $wd/sif.service /lib/systemd/system/
echo "*Registering service"
echo
echo "STEP 3) SHARED STORAGE CONFIGURATION"
echo "SIF requires a shared KVM storage directory for operation."
echo "Please enter path to shared directory ommiting trailing /"
echo "EX: /mnt/share"
read -p "Please enter shared directory: " sharedir
echo "*SIF will now attempt to write to specified shared directory..."
touch $sharedir/siftest
if [ ! -w "$sharedir/siftest" ] ; then
echo "*Cannot write to Shared Directory. Please correct permissions and rerun SIF Setup."
exit 1
fi
echo "*Creating SIF Directories in Shared Storage..."
mkdir $sharedir/sifxml
mkdir $sharedir/sifxml/$hostid
mkdir $sharedir/siflog
if [ ! -w "$sharedir/sifxml" ] ; then
echo "*Cannot create directories. Please correct permissions and rerun SIF Setup."
exit 1
fi
echo "*Operation Successful."
rm $sharedir/siftest
while true; do
echo
echo "STEP 4) KVM PAIR SETUP"
echo "SIF is designed for two KVM hosts."
read -p "Please enter the IP address of your pair host: " pairip
echo
echo "SIF uses backup IP addresses to ensure availibility."
echo "Best practice is set your failsafe IP as a VM running on the pair host."
read -p "Please enter a failsafe IP address: " failip
echo
echo "SIF will also try to contact an avaiable gateway during failover to ensure network connectivity."
echo "This could be your local gateway or a public one."
read -p "Please enter a gateway IP address: " failgw
echo
echo "You entered:"
echo "------------------------------"
echo "PAIR HOST: $pairip"
echo "FAIL HOST: $failip"
echo "FAIL GATEWAY: $failgw"
echo "------------------------------"
read -p "Are these values correct? (y/n)" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo "Please enter the correct values.";;
* ) echo "Please answer y or n.";;
esac
done
# -------------------------------------
# INPUT USER VALUES INTO SIF CONF FILE
# -------------------------------------
sudo sed -i "s/EXAMPLEHOSTID/$hostid/g" /opt/sif/sif.conf
sudo sed -i "s/EXAMPLEPAIRID/$pairid/g" /opt/sif/sif.conf
sudo sed -i "s+EXAMPLEDIR+$sharedir+g" /opt/sif/sif.conf
sudo sed -i "s/EXAMPLEIP/$pairip/g" /opt/sif/sif.conf
sudo sed -i "s/EXAMPLEFAIL/$failip/g" /opt/sif/sif.conf
sudo sed -i "s/EXAMPLEGW/$failgw/g" /opt/sif/sif.conf
echo
echo "STEP 5) SSH KEY SETUP"
echo "For automatic VM migrations to work, SIF uses SSH and key authentication."
echo "Please follow the prompts to setup SSH Key authentication."
ssh-keygen -t rsa
ssh-copy-id root@$pairip
echo "STEP 6) FIREWALL SETUP"
echo "*Creating Firewall Exceptions for live migration"
if [ -f /etc/redhat-release ]; then
firewall-cmd --add-port=49152-49216/tcp --zone=public --permanent
firewall-cmd --reload
fi
if [ -f /etc/lsb-release ]; then
iptables -I INPUT -p tcp -m tcp --dport 49152:49216 -j ACCEPT
fi
echo "STEP 7) VM METADATA EXPORT"
echo "*Exporting existing VM metadata"
for x in $(virsh list --persistent --name);
do
echo "Exporting - $x" && virsh dumpxml $x > $sharedir/sifxml/$hostid/$x
done
echo "*Exporting Complete"
echo "*Setting nightly cron task"
crontab -l | { cat; echo "0 0 * * * /opt/sif/sif-xml.sh"; } | crontab -
echo
echo "*Starting SIF service"
systemctl daemon-reload
systemctl enable sif
systemctl start sif
echo "------------------------------------------------------------"
echo "*SIF Service is now installed and running!"
echo "*Please complete SIF setup on other host, if not already done."
exit 0