HAProxy is great solution for load balancing as it does not require lots of resources, it is scalable, easy to setup and fairly simple to manage. In this guide I’ll show you how to install and configure HAProxy and load balance 2 Apache Web Servers.
The distro of my choice is CentOS 7 but you can use any distro you like.
Thanks to its popularity HAProxy is available in the default CentOS repos. For the sake of simplicity I will use the version available in the default repo, though you need to keep in mind that this might not be the latest release of HAProxy.
If you are planning to build a proper load balanced solution, I would recommend installing HAProxy on a separate box.
In my case, thanks to the ACL rule named url_admin, all connections that match the /admin rule would be forwarded to the admin_back backend. That way I would make sure that all /admin connections would be forward to my admin server. You can of course adjust that.
HAProxy is very flexible so you could add lots of rules and different backend servers depending on your setup and requirements.
The restart is super quick and should not cause any major downtime.
You can see that the connections are being load balanced between the two webservers.
HAProxy comes with very handy builtin Statistics Report, you will be able to see the status of your backend servers, their uptime, the number of handled connections and more.
This is pretty much all that I wanted to cover here.
I would not get into the different types of load balancing and etc. but I might cover those in future articles.