In one of my older blog posts I wrote about Simple load balancing with Apache proxy_balancer. This blog post was about how to increase the availability of a web server by using two Apache servers and it’s proxy_balancer module. But what about if the server with the “Load Balancer” running is going down?
To address this case, two servers with the same configuration are required (Apache + proxy_balancer) and CARP (Common Address Redundancy Protocol). CARP works similar like Cisco’s HSRP/VRRP (Hot Standby Routing Protocol/ Virtual Router Redundancy Protocol) and Debian GNU/Linux provides the package ucarp: user-space replacement to VRRP — automatic IP fail-over. The package can be installed on both servers by using:
Configuration on first server
The example assumes the first server is at IP n.n.n.11, the second server is at IP n.n.n.12 and the shared, virtual IP of both servers is at n.n.n.10. On the first server I add the following lines to the file /etc/network/interfaces:
On the second server I’m adding the same configuration into the /etc/network/interfaces file:
Starting the virtual interfaces and testing
By using the traditional ifconfig command I’m bringing up on both servers the virtual interface:
Note: same can be accomplished by the new ip command.
For testing, I’m constantly pinging the virtual IP n.n.n.10, the IP of the first server n.n.n.11 and the IP of the second server n.n.n.12 from another computer.
By using the XCP-NG management console, I’m logging in and shutting down on the first server the eth0 interface:
The IP address of the first server stops to respond to the ping command, however the virtual IP address n.n.n.10 is still responding (which is in this case now the second server). By using the command:
I’m bringing up the eth0 interface again and I repeat this process on the second server to verify that the virtual IP address is also responding if the second server is down.