First, Install dependencies needed to build HAProxy

yum install -y make gcc gcc-c++ pcre-devel openssl-devel readline-devel systemd-devel zlib-devel

Download Lua source code and then Install Lua

curl -R -O
tar zxf lua-5.3.5.tar.gz
cd lua-5.3.5
make linux test
make linux install
cd ..

Download OpenSSL source code and then Install OpenSSL

curl -R -O
tar xvzf openssl-1.1.1c.tar.gz
cd openssl-1.1.1c
./config --prefix=/usr/local/openssl-1.1.1c shared
make install

Download HAProxy source code and then Install HAProxy

curl -R -O 
tar -xzf haproxy-2.0.7.tar.gz
cd haproxy-2.0.7
make -j $(nproc) TARGET=linux-glibc USE_OPENSSL=1 SSL_LIB=/usr/local/openssl-1.1.1c/lib SSL_INC=/usr/local/openssl-1.1.1c/include USE_ZLIB=1 USE_LUA=1 LUA_LIB=/usr/local/lib/ LUA_INC=/usr/local/include/ USE_PCRE=1 USE_SYSTEMD=1 EXTRA_OBJS="contrib/prometheus-exporter/service-prometheus.o"
make install
cp /usr/local/sbin/haproxy /usr/sbin/haproxy
useradd -M -r -s /sbin/nologin haproxy

Add Service for HAProxy

nano /etc/systemd/system/haproxy.service

Then paste in the following

Description=HAProxy Load Balancer
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/" "EXTRAOPTS=-S /run/haproxy-master.sock"
ExecStartPre=/usr/local/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecStart=/usr/local/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS
ExecReload=/usr/local/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecReload=/bin/kill -USR2 $MAINPID

Then finish HAProxy Installation Process by running

systemctl daemon-reload
mkdir -p /etc/haproxy
touch /etc/haproxy/haproxy.cfg
systemctl enable haproxy
systemctl start haproxy
cd ..

Optional remove build dependencies for haproxy

yum remove readline-devel pcre-devel openssl-devel

Speak with an expert on our team to discuss Cloud solutions tailored to your business.

You’ll receive free recommendations tailored to your business.