Skip to content

HAProxy

The following describe how to configure a Red Hat Enterprise Linux 8 or equivalent server to serve out HAproxy load balancers.

Install HAProxy:

dnf install haproxy -y 

Back up the original configuration file:

mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak

And add the following base configuration:

/etc/haproxy/haproxy.cfg
global
    log         127.0.0.1 local2
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    stats socket /var/lib/haproxy/stats

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    30s
    timeout queue           1m
    timeout connect         30s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 30s
    timeout check           30s
    maxconn                 4000

listen stats
    bind 0.0.0.0:9000
    mode http
    balance
    timeout client 5000
    timeout connect 4000
    timeout server 30000
    stats uri /stats
    stats refresh 5s
    stats realm HAProxy\ Statistics
    stats auth admin:changeme
    stats admin if TRUE

This haproxy.conf example is the minimal configuration ready to define load balancers.

Set the SELinux boolean to allow haproxy to connect to any port:

setsebool -P haproxy_connect_any=1

Open firewall to enable access to HAProxy:

firewall-cmd --permanent --add-port=9000/tcp --zone=public
firewall-cmd --reload

If SELinux is enforcing, label the new port:

semanage port -a -t http_port_t -p tcp 9000

Enable and start HAProxy:

systemctl enable haproxy.service --now

View the graphical statistics report at http://192.168.1.100:9000/stats. In this example the username is admin and password is changeme as defined in the haproxy.cfg previously.

This should be all set for adding load balancers.