Networking HowTos
Networking HowTos

Compile HAProxy from source on Ubuntu

March 29, 2012 Linux, Ubuntu

This guide will step you through the process of compiling, installing, and setting up the latest version of HAProxy on Ubuntu.
Install HAProxy from the repository to get required scripts
Install HAProxy using the package management tools first, so we can get a copy of the sample config file, and the start up scripts.
Note: This may seem like a weird option, but we really only a few of the scripts/config files that come in this package. We wont be running the version that gets installed from the repository.

$ sudo apt-get install haproxy

This will probably install a older version of HAProxy, but we wont be using that. Keep it in mind if you ever run apt-get upgrade, and it comes up with HAProxy to upgrade. If you do upgrade, you may need to edit the start up script again as per the instructions below.
Compiling the latest version from source
Download the latest copy of HAProxy (see http://haproxy.1wt.eu/ for the latest version). At the time of of writing this article, it was version 1.4.20.

$ wget "http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.20.tar.gz"

Extract the file.

$ tar xzvf haproxy-1.4.20.tar.gz

Change directory into the newly created folder containing the HAProxy source code.

$ cd haproxy-1.4.20/

Start the compile process.

$ make TARGET=linux26

If you got errors during the above compile stage, you may be missing some dependencies required to compile HAProxy. If this is the case, run the command below, and then run the compile command above again.

$ sudo apt-get build-dep haproxy

Install the compiled binaries into the system.

$ sudo make install

Configuring the startup scripts to use the compiled version of HAProxy
On Ubuntu, by default the HAProxy service is disabled. To enable it you need to modify the /etc/default/haproxy file.
$ sudo nano /etc/default/haproxy
Modify the ‘ENABLED=0’ line to ‘ENABLED=1’ as shown below.
Change this:

ENABLED=0

To this:

ENABLED=1

Save and exit the editor.
Edit the startup script to tell it where the newly compiled haproxy binary is located.

$ sudo nano /etc/init.d/haproxy

Find the following line:

HAPROXY=/usr/sbin/haproxy

and modify it to read:

HAPROXY=/usr/local/sbin/haproxy

Save the file and exit the editor.
You can now start/stop HAProxy as you normally would with any Ubuntu service.

$ sudo /etc/init.d/haproxy start

or

$ sudo service haproxy start

You should now be running the latest version of HAProxy compiled from source code.

You Might Also Like