Debian Codegraph @

demo/web-load-balancer/setup_load_balancer.sh

raw
1 #!/bin/sh
2 #
3 # This script sets up the HAProxy load balancer initially, configured with
4 # no working backend servers. Presumably in a real environment you would
5 # do this sort of setup with a real configuration management system. For
6 # this demo, however, this shell script will suffice.
7 #
8 set -e
9
10 # Install HAProxy
11 sudo apt-get update
12 sudo apt-get install -y haproxy
13
14 # Configure it in a jank way
15 cat <<EOF >/tmp/haproxy.cfg
16 global
17 daemon
18 maxconn 256
19
20 defaults
21 mode http
22 timeout connect 5000ms
23 timeout client 50000ms
24 timeout server 50000ms
25
26 listen stats
27 bind *:9999
28 mode http
29 stats enable
30 stats uri /
31 stats refresh 2s
32
33 listen http-in
34 bind *:80
35 balance roundrobin
36 option http-server-close
37 EOF
38 sudo mv /tmp/haproxy.cfg /etc/haproxy/haproxy.cfg
39
40 # Enable HAProxy
41 cat <<EOF >/tmp/haproxy
42 ENABLED=1
43 EOF
44 sudo mv /tmp/haproxy /etc/default/haproxy
45
46 # Start it
47 sudo /etc/init.d/haproxy start