Simple High Availability with CARP

Simple High Availability with CARP

In one of my older blog posts I wrote about Simple load balacing with Apache proxy_balancer. This blog post was about how to increase the availabilty 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 Reduncancy Protocol). CARP works similar like Cisco's HSRP/VRRP (Hot Standby Routung Protocol/Virtual Router Redundancy Protcol) 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:


# apt install ucarp

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:


#
# First server
#
# Virtual Server ID
ucarp-vid       1

# Virtual Server IP
ucarp-vip       n.n.n.10

# Shared Password
ucarp-password  some_password

# Advertisement skew
ucarp-advskew   1

# Advertisement base interval
ucarp-advbase   1

# Master server
ucarp-master    no

# Virtual interface 
iface eth0:ucarp inet static
  address n.n.n.10/24
  gateway n.n.n.1

On the second server I'm adding the same configuration into the /etc/network/interfaces file:


#
# Second Server
#
# Virtual Server ID
ucarp-vid       1

# Virtual Server IP
ucarp-vip       n.n.n.10

# Shared Password
ucarp-password  some_password

# Advertisement skew
ucarp-advskew   1

# Advertisement base interval
ucarp-advbase   1

# Master server
ucarp-master    no

# Virtual interface 
iface eth0:ucarp inet static
  address n.n.n.10/24
  gateway n.n.n.1

Starting the virtual interfaces and testing

By using the traditional ifconfig command I'm bringing up on both servers the virtual interface:


# ifconfig eth0:ucarp up
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.


PING n.n.n.10 (n.n.n.10) 56(84) bytes of data.
64 bytes from n.n.n.10: icmp_seq=1 ttl=64 time=0.256 ms
...

PING n.n.n.11 (n.n.n.11) 56(84) bytes of data.
64 bytes from n.n.n.11: icmp_seq=1 ttl=64 time=0.358 ms
...

PING n.n.n.12 (n.n.n.12) 56(84) bytes of data.
64 bytes from n.n.n.12: icmp_seq=1 ttl=64 time=0.252 ms
...

By using the XCP-NG management console, I'm logging in and shutting down on the first server the eth0 interface:


# ifconfig eth0 down
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:

# ifconfig eth0 up
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.

Search my web site