Rackspace Community

Setting up HAProxy

Article ID: 436

Last updated on June 11, 2014

Authored by: Rackspace Support

Because more customers are requesting high availability (HA) setups with load balancing, Rackspace has implemented HAProxy as a software load balancer on cloud servers. When you choose the size of the load balancer, be sure to consider the bandwidth constraints of cloud servers. We recommend that you use, at minimum, a 4 GB instance for your HAProxy node, but this depends on the bandwidth usage and the number of requests received by the server.

The following instructions use an operating system based on Red Hat Enterprise Linux. As a result, the guide is short, and HAProxy is installed via the EPEL repository

Install HAProxy

For most distributions, you can install HAProxy using your distribution's package manager. For example, to install on Debian or Ubuntu, run the following command:

sudo aptitude install haproxy

On CentOS 5, run:

To download HAProxy on CentOS 5, you must set up access to the EPEL software repository. Run the following commands:

Configure HAProxy

You can configure HAProxy only after you have configured your web servers because you need to use their 10.x ServiceNet IP addresses. ServiceNet is used because you are not be charged for bandwidth overage, and it has faster throughput.

To make HAProxy functional, you need to change a number of items in /etc/haproxy/haproxy.cfg. These changes are described in this section. Remember that you must edit the values shown in this section to reflect your server's IP addresses.

First, change the value of listen webfarm to reflect your server's eth0 or public IP address. Following is an example value:

listen webfarm 127.0.0.1:80

Then, add your web servers.

In the following example, which shows a four-server configuration, replace the 10.0.0.x IP address with the eth1 or private IP address of your web servers.

Session Persistence with SSL

If you want to also balance SSL traffic, you must set the balance mode to source, as shown in the following example. This setting takes a hash of the client's IP address and the number of servers in rotation, and traffic is sent from one IP address to the same web server consistently. The persistence is reset if the number of servers is changed: