Running multiple instances of haproxy on CentOS 7.2

Sometimes for security reasons and traffic separation it is necessary to run multiple instances of haproxy on the same system. The only restriction is to use different sockets (IP:port pairs) for each instance.

Steps:

1. Create a new configuration directory under /etc:

mkdir -p /etc/haproxy2
touch /etc/haproxy2/haproxy2.conf

2. Create a symlink for the haproxy binary

ln -s /usr/sbin/haproxy /usr/sbin/haproxy2

Now haproxy can be invoke using haproxy2

3. Create a copy of the initialization script

cp /etc/init.d/haproxy /etc/init.d/haproxy2

Edit the commented lines (4-7) of the haproxy2 script by replacing haproxy with haproxy2 as follows:

#!/bin/sh
#
# chkconfig: - 85 15
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
#              for high availability environments.
# processname: haproxy2
# config: /etc/haproxy2/haproxy2.cfg
# pidfile: /var/run/haproxy2.pid

4. Don’t forget to fill in the required configuration directives into /etc/haproxy2.conf as usually
Adjust the paths accordingly. E.g.

 chroot /var/lib/haproxy2
 stats socket /run/haproxy2/admin.sock mode 660 level admin

5. Test the service using

service haproxy2 start

6. Enable the service to start at boot time

systemctl enable haproxy2