Install HAProxy 1.8 on CentOS 7

HaproxyThis is just a short write-up on installing HAProxy version 1.8 on CentOS 7 using Software Collections. HAProxy  is an application layer (Layer 7) load balancing and high availability solution that you can use to implement a reverse proxy for HTTP and TCP-based Internet services. I am using it to expose my webservices through a reverse proxy.

If default HAProxy version 1.5 is installed then it should be removed because it is blocking the new version we are going to install.

# yum remove haproxy
...
warning: /etc/haproxy/haproxy.cfg saved as /etc/haproxy/haproxy.cfg.rpmsave
...

This warning indicates that your old HAProxy config file is renamed. This is useful to know if you are planning to use the same file in HAProxy version 1.8.

Install the Software Collections (SCL) repository to get access to the new HAProxy version

# yum install centos-release-scl

Update your repositories and accept the new repository.

Installing HAProxy 1.8

# yum install rh-haproxy18-haproxy rh-haproxy18-haproxy-syspaths

The rh-haproxy18-haproxy-syspaths package is a system-wide wrapper for the rh-haproxy18-haproxy package and allows us to run HAProxy 1.8 as a service. This package conflicts with the HAProxy and cannot be installed on one system.

If we now look in /etc/haproxy/haproxy.cfg we will see that the config file is a symling to the new package

# ls -l /etc/haproxy/
lrwxrwxrwx. 1 root root 44 Jul 17 18:19 haproxy.cfg -> /etc/opt/rh/rh-haproxy18/haproxy/haproxy.cfg

If you had HAProxy 1.5 installed previously and would like to continue using the config file, copy it to the new location. First we preserve the original HAProxy 1.8 config file by renaming it or just copy the rules that you need from the old config.

# mv /etc/opt/rh/rh-haproxy18/haproxy/haproxy.cfg /etc/opt/rh/rh-haproxy18/haproxy/haproxy.cfg.original
# cp /etc/haproxy/haproxy.cfg.rpmsave /etc/opt/rh/rh-haproxy18/haproxy/haproxy.cfg

We are now ready to start HAProxy 1.8 with our old config file

# systemctl start rh-haproxy18-haproxy
# systemctl status rh-haproxy18-haproxy

If we would like to have the new HAProxy version to auto-start on reboot

# systemctl enable rh-haproxy18-haproxy

Done.

Installing HAProxy 1.8 on RedHat 7 is similar, except you use subscription-manager and add the software collections repository.