-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-install_load_balancer
executable file
·55 lines (44 loc) · 1.21 KB
/
1-install_load_balancer
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
#!/usr/bin/env bash
# install load balancer
echo -e "Updating and doing some minor checks...\n"
function install() {
command -v "$1" &> /dev/null
#shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo -e " Installing: $1\n"
sudo apt-get update -y -qq && \
sudo apt-get install -y "$1" -qq
echo -e "\n"
else
echo -e " ${1} is already installed.\n"
fi
}
install haproxy #install haproxy
echo -e "\nSetting up some minor stuff.\n"
# backup default server config file
sudo cp /etc/haproxy/haproxy.cfg haproxy_default.backup
server_config=\
"
defaults
mode http
timeout client 15s
timeout connect 10s
timeout server 15s
timeout http-request 10s
frontend clickviral-tech-frontend
bind *:80
default_backend clickviral-tech-backend
backend clickviral-tech-backend
balance roundrobin
server 263954-web-01 54.197.207.40:80 check
server 263954-web-02 34.227.92.157:80 check
"
# shellcheck disable=SC2154
echo "$server_config" | sudo dd status=none of=/etc/haproxy/haproxy.cfg
# enable haproxy to be started by init script
echo "ENABLED=1" | sudo dd status=none of=/etc/default/haproxy
if [ "$(pgrep -c haproxy)" -le 0 ]; then
sudo service haproxy start
else
sudo service haproxy restart
fi