17.2 Installing and Configuring HAProxy

To install HAProxy:

  1. Install the haproxy package on each front-end server:

    # yum install haproxy
  2. Edit /etc/haproxy/haproxy.cfg to configure HAProxy on each server. See Section 17.2.1, “About the HAProxy Configuration File”.

  3. Enable IP forwarding and binding to non-local IP addresses:

    # echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
    # echo "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf
    # sysctl -p
    net.ipv4.ip_forward = 1
    net.ipv4.ip_nonlocal_bind = 1
  4. Enable access to the services or ports that you want HAProxy to handle.

    For example, to enable access to HTTP and make this rule persist across reboots, enter the following commands:

    # firewall-cmd --zone=zone --add-service=http
    # firewall-cmd --permanent --zone=zone --add-service=http

    To allow incoming TCP requests on port 8080:

    # firewall-cmd --zone=zone --add-port=8080/tcp
    # firewall-cmd --permanent --zone=zone --add-port=8080/tcp
  5. Enable and start the haproxy service on each server:

    # systemctl enable haproxy
    ln -s '/usr/lib/systemd/system/haproxy.service' \
    # systemctl start haproxy

    If you change the HAProxy configuration, reload the haproxy service:

    # systemctl reload haproxy