16.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 16.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:

    # iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
    # service iptables save
  5. Enable and start the haproxy service on each server:

    # chkconfig haproxy on
    # service haproxy start

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

    # service haproxy reload