-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path1-install_load_balancer
executable file
·37 lines (32 loc) · 1.04 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
#!/usr/bin/env bash
#script to install and configure HAproxy loadbalancer on the server(lb-01)
sudo apt-get update
sudo apt-get -y install --no-install-recommends software-properties-common
sudo add-apt-repository -y ppa:vbernat/haproxy-2.4
sudo apt-get -y install haproxy
# lets make a backup of the default cofig file (just incase ^_^)
sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bckp
sudo chown -R "$USER":"$USER" /etc/default/
sudo chown -R "$USER":"$USER" /etc/haproxy/
loadbl_config=\
"defaults
mode http
timeout client 15s
timeout connect 10s
timeout server 15s
timeout http-request 10s
frontend iamitsfoss-frontend
bind *:80
default_backend iamitsfoss-backend
backend iamitsfoss-backend
balance roundrobin
server 130022-web-01 54.146.84.110:80 check
server 130022-web-02 100.26.156.138:80 check
"
sudo echo -e "$loadbl_config" > /etc/haproxy/haproxy.cfg
echo "ENABLED=1" >> /etc/default/haproxy
if [[ "$(pgrep -f haproxy)" ]]; then
sudo service haproxy restart
else
sudo service haproxy start
fi