Running two instance of haproxy on the same machine

I have haproxy running on machine A. How can I create a another instance of it? (having its own configuration file). I tried to make a copy of haproxy in /etc/ with different name and added it to init.d what it did not work, any ideas?

2 Answers

You have to make a copy of your /etc/haproxy/haproxy.cfg.

cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy_s.cfg

Make sure that you don't have any conflicting ports for the frontends in this copy. At this point you can start haproxy manually by issuing the following command.

/usr/sbin/haproxy -D -f /etc/haproxy/haproxy_s.cfg -p /var/run/haproxy_s.pid
  • -D will start haproxy in daemon mode
  • -f is the path to the configfile
  • -p is the path to the pidfile

If you want to start the new instance of haproxy via the init script or load it during system boot you need to make a copy of the init script first.

cp /etc/init.d/haproxy /etc/init.d/haproxy_s

In addition to that you'll need to create a symbolic link to the binary of haproxy.

ln -s /usr/sbin/haproxy /usr/sbin/haproxy_s

After that you need to make the following changes to /etc/init.d/haproxy_s

exec="/usr/sbin/haproxy_s"
cfgfile=/etc/haproxy/haproxy_s.cfg
pidfile=/var/run/haproxy_s.pid
lockfile=/var/lock/subsys/haproxy_s

I've tested this configuration on my RHEL 6 installation. It should be possible to port the solution to other Linux distributions with slight modifications as long as those distributions are using the init system.

What did not work about it? Errors? Anything in the logs?

What you will need to do is copy the config file, and make some changes.

Once a port is bound by a service, that same port can not be bound by anohter until release. You will need to change your port bindings in the new config file, and then launch it specifying that new config file with -f.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like