Using HAProxy for a load-balanced web service.
Update OS
# dnf clean all && dnf update
Install haproxy
# dnf install haproxy
Use haproxy.cfg.template
as haproxy config file.
# cp haproxy.cfg.template /etc/haproxy/haproxy.cfg
Note: Replace the IP's of the webservers:
...
backend app
balance roundrobin
server web1 192.168.0.21:80 check
server web2 192.168.0.22:80 check
# systemctl enable --now haproxy
Note: Fix selinux
if needed
- Enable booleans
# setsebool -P nis_enabled 1
# setsebool -P haproxy_connect_any 1
- Enable port
# semanage port -a -t http_port_t -p tcp 150
Update OS
# dnf clean all && dnf update
Install httpd
# dnf install httpd
Enable service
# systemctl enable --now httpd
Use index.html.template
as index file.
# cp index.html.template /var/www/html/index.html
Note: Replace the hostname of the webservers:
...
<h1>
Hello from [hostname]
</h1>
...
Use curl
to test the load balancing of web servers
# curl localhost
<html>
<head><title>Apache is running!</title></head>
<body>
<h1>
Hello from webserver1
</h1>
</body>
</html>
# curl localhost
<html>
<head><title>Apache is running!</title></head>
<body>
<h1>
Hello from webserver2
</h1>
</body>
</html>