Install HAProxy from source on Centos 7 x64

In this article I will show you how can you install the latest version (at this time 1.8.13) of HAProxy on Centos 7 x64. You can install HAProxy from Centos base repo too but that version is a little bit old (1.5.18). So I decided to write this short guide to help you. Detailed configuration isn’t scope in this article.

At first please install some dependecies to compile and run HAProxy 1.8.13.

yum -y install make \
gcc \
binutils \
pcre2-devel.x86_64 \
openssl-devel.x86_64 \
zlib-devel \
libslz-devel.x86_64 \
selinux-policy-devel \
systemd-devel.x86_64

Create a dedicated unix system user for HAProxy.

useradd -s /usr/sbin/nologin -r haproxy

Create configuration directory. HAProxy will looking for config files in this directory. I use /etc/haproxy for this purpose.

mkdir -p /etc/haproxy/errors

Download the latest version (in this example I use 1.8.13), extract, configure and compile it. You can find all configurable variable in Makefile.

curl -O http://www.haproxy.org/download/1.8/src/haproxy-1.8.13.tar.gz
tar xf haproxy-1.8.13.tar.gz
cd haproxy-1.8.13
make -j5 USE_SYSTEMD=1 USE_REGPARM=1 USE_PCRE_JIT=1 \
TARGET=linux2628 USE_THREAD=1 USE_LINUX_TPROXY=1 USE_TFO=1 USE_LIBCRYPT=1 \
CPU=generic USE_PCRE=1 USE_OPENSSL=1 USE_SLZ=1 DEBUG=-s

make install
cp -a examples/errorfiles/*.http /etc/haproxy/errors/

Create systemd service fo HAProxy. From the directory of HAProxy source you can find systemd files in contrib/systemd folder.

cd contrib/systemd
make
cp haproxy.service /lib/systemd/system/haproxy.service
systemctl daemon-reload
systemctl enable haproxy.service

After this you have to create your haproxy.cfg file under /etc/haproxy directory and start HAProxy with systemctl start haproxy command. Have a fun!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.