How to Configure HA Proxy
We’ll be compiling our guide soon. Already have one? Let us know and we might be able to publish it (We’ll obviously credit you for the article!)
What in the world is load balancing? In it’s simplest form you might have a Linux server with HA Proxy software installed (actually you’d have at least two). These servers would be configured to talk to a couple of Web Servers. Traffic coming into the Web Servers would go via the load balancer and it would decide which Web Server the request is send to. HA Proxy has a number of load balancing algorithms including least connect and round robin. With “round robin” each server is used in turn, first server a then server b. You could add more servers if your traffic increased. With “least connect” the request is sent to the least busiest server, there by balancing load.
/etc/haproxy/haproxy.cfg is the configuration file you need to change.
There will be a frontend and a backend section. The frontend defines how messages are forwarded to the backend. The backend specifies the server where the web server runs (in this example.)
Here’s a little snippet of haproxy.cfg (purely fictional)
acl devopsportal hdr(host) -i devopslinux.net
use_backend devopsportal if devopsportal
server devopslinux01.net xxx.xxx.xxx.xxx:8080 check
server devopslinux02.net xxx.xx.xxx.xxx:8080 check
http requests coming in get diverted to the two servers in the backend section using round robin i.e. using 01 then 02 etc. You could also specific “leastconn” instead of round robin and this would direct traffic to the “quietest” server.
A load balancer will allow your web/app server backends to be highly available, as if one goes down, the other(s) are still available. It’s worth noting here, some real world experience, I have had two Apache web servers sitting behind a single HA Proxy server, running “round robin”. One of the web servers went down and due to round robin being set, we had intermittent failures, each time the proxy server tried to send to the downed server it failed. This was in a test environment so it wasn’t that important and there may be some configuration options to prevent this.
You could have a floating IP address which could “float” between two HA Proxy servers which would load balance between them. See the diagram I drew below :