Install HAProxy
Run this command on both load balance servers:
Name Resolution
You can modify your host file for name resolution and just use the names of servers in your configuration files rather than the IP addresses. If a server IP changes in the future, you only need to modify the host which is much easier than tracking down various application configuration files. You could do this with an internal DNS server but I prefer using the local host file for fastest resolution.
Edit the local host file (on all load balance servers):
Add the Orthanc servers (substituting for your own values):
Code: Select all
192.168.107.103 srv-dicom1
192.168.107.104 srv-dicom2
Allow Virtual IP Binding
If you try to bind the inactive proxy to an IP it is not currently using (because the other proxy is using it) then it will fail to load the service. We need to modify the system to allow binding to a non-local IP that is not currently active.
On both load balance servers, edit the sysctl.conf file:
Add the following to the end of the file:
Activate the change:
HAProxy Configuration
This is the default ownership and file permission settings of the configuration file:
Code: Select all
sudo chown root:root /etc/haproxy/haproxy.cfg
sudo chmod 644 /etc/haproxy/haproxy.cfg
Backup the original configuration file (on both servers):
Code: Select all
sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.bak
Edit the configuration file (on all load balance servers):
Add the following to the bottom (substituting your own values)
Code: Select all
frontend fe-lb
## Bind to port 4242 on the virtual IP
bind 192.168.1.100:4242
mode tcp
## Must use tcplog when using tcp mode.
option tcplog
default_backend be-dicom
## Balance between the various backend servers (unencrypted).
backend be-dicom
mode tcp
## Must use tcplog when using tcp mode.
option tcplog
## Various policies for determining how to route traffic to the servers.
# balance first
# balance leastconn
balance roundrobin
# balance source
# balance static-rr
server dicom1 srv-dicom1 weight 1 check port 4242 rise 2 fall 3 inter 2000 fastinter 1000 downinter 5000
server dicom2 srv-dicom2 weight 1 check port 4242 rise 2 fall 3 inter 2000 fastinter 1000 downinter 5000
## HAProxy stats web gui - This entire section is optional.
listen stats
## Setup listener on port 9000 on any interface.
bind *:9000
## http mode so a web browser can be used to access it.
mode http
## Enable metrics to be recorded.
stats enable
## Configure the URI. Example: http://192.168.107.100:9000/stats
stats uri /stats
## How long the browser waits before refreshing the page.
stats refresh 30s
## Title for popup window.
stats realm HAProxy\ Statistics
## Hide the HAProxy version. Ex: version 1.8.8-1ubuntu0.4, released 2019/01/24
stats hide-version
## Define user credentials.
stats auth haproxy:haproxy
stats auth viewer:viewer
## Allows taking down and bringing up backend servers.
stats admin if TRUE
Validate the changes to the configuration files:
Code: Select all
sudo haproxy -f /etc/haproxy/haproxy.cfg -c
On both servers, restart the proxy service:
Verify that the service started and is running (active):
You can also verify it is listening on the expected ports (if you have net-tools installed):
Output:
Code: Select all
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20102/haproxy
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 20102/haproxy
tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 20102/haproxy
Stats Firewall Rules
If you use the optional "stats" section which listens on port 9000, you will need to add a firewall rule. If not using the proxy stats, ignore this section.
On each load balance server, edit the firewall script that was created during the initial setup of the server (if you
followed my instructions):
Code: Select all
sudo vi /var/scripts/prod/en-firewall.sh
Add the following rules under the Application-specific section which allows connectivity from from anything on your local subnet:
Code: Select all
echo "Adding HAProxy Stats rules"
ufw allow from 192.168.1.0/24 proto tcp to any port 9000 comment 'ProxyStats' 1>/dev/null 2>&1
Or you can reduce access even further by limiting to just specific IP addresses such as your admin workstations like this:
Code: Select all
echo "Adding HAProxy Stats rules"
ufw allow from 192.168.1.30 proto tcp to any port 9000 comment 'ProxyStats' 1>/dev/null 2>&1
ufw allow from 192.168.1.31 proto tcp to any port 9000 comment 'ProxyStats' 1>/dev/null 2>&1
ufw allow from 192.168.1.32 proto tcp to any port 9000 comment 'ProxyStats' 1>/dev/null 2>&1
Run the updated rules:
Code: Select all
sudo /var/scripts/prod/en-firewall.sh
Open a web browser and have a look at the statistics page at
http://192.168.1.100:9000/stats/
