Installing and Configuring HAProxy

Before you can set up load balancing by using HAProxy, you must first install and configure the feature.

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

    Run the following command:

    sudo dnf install haproxy
  2. Edit the /etc/haproxy/haproxy.cfg file to configure HAProxy on each server.

    See HAProxy Configuration Directives for more information.

  3. Configure the firewall to enable access to the services or ports that you want HAProxy to handle.

    To accept incoming TCP requests on port 80, run the following commands:

    sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
    sudo systemctl reload firewalld
  4. Enable and start the haproxy service on each server.

    Run the following command:

    sudo systemctl enable --now haproxy

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

    sudo systemctl reload haproxy