
HAProxy is fast and flexible traffic ballancer, but in Centos repositories is available in old (1.8) version. The latest (at this moment) LTS version is 2.4.
How to install it on Centos8? Here you are:
yum install gcc pcre-devel tar make wget -y
cd /usr/src && wget https://www.haproxy.org/download/2.4/src/haproxy-2.4.4.tar.gztar zxvf haproxy-2.4.4.tar.gz
cd haproxy-2.4.4
In this moment you can chose options of compilation, to see which are available type: make help
make TARGET=linux-glibc USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1
make install
useradd -r haproxy
mkdir -p /etc/haproxy
mkdir -p /var/lib/haproxy
touch /var/lib/haproxy/stats
ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
Now the init script or you can write systemd-unit yourself:cp examples/haproxy.init /etc/init.d/haproxy
chmod 755 /etc/init.d/haproxy
systemctl daemon-reload
chkconfig haproxy on
And that’s all. Now the basic config file:
global
log /dev/log local2
chroot /var/lib/haproxy
stats timeout 30s
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
option forwardfor
option http-server-close
option forwardfor except 127.0.0.0/8
timeout http-request 25s
timeout queue 120s
timeout check 5s
timeout connect 5000
timeout client 50000
timeout server 50000
frontend http_front
bind :80
bind :443 ssl crt /path/to/sslcertificate.pem
mode http
stats uri /haproxy?stats
http-request redirect scheme https code 301 unless { ssl_fc }
default_backend http_back
backend http_back
balance roundrobin
server srv1 192.168.0.1:80 check
server srv2 192.168.0.2:80 check
And it’s ready, so: systemctl start haproxy
and that’s all