Search This Blog

Saturday 27 August 2011

Failover Redundancy in Ubuntu 11.10 with CARP

Failover Redundancy in Ubuntu 11.10 
 
1. Install ucarp:

root@master:~# apt-get install ucarp
root@slave:~#    apt-get install ucarp



2. For the primary (master) host change /etc/network/interfaces as follows:

# This file describes the network interfaces available on your system 
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface

auto lo 
iface lo inet loopback

# The primary network interface

auto eth0 
iface eth0 inet static

address 192.168.1.130 
netmask 255.255.255.0 
network 192.168.1.0 
broadcast 192.168.1.255 
gateway 192.168.1.1

# The secondary network interface

auto eth1 
iface eth1 inet static 
address 192.168.2.1 
netmask 255.255.255.0 
network 192.168.2.0 
broadcast 192.168.2.255

ucarp-vid 1 
ucarp-vip 192.168.2.254 
ucarp-password secret 
ucarp-advskew 14 
ucarp-advbase 1 
ucarp-facility local1 
ucarp-master yes 
ucarp-upscript /usr/share/ucarp/vip-up 
ucarp-downscript /usr/share/ucarp/vip-down

iface eth1:ucarp inet static 
address 192.168.2.254 
netmask 255.255.255.0

3. For the secondary (slave) host change /etc/network/interfaces as follows:

# This file describes the network interfaces available on your system 
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface

auto lo 
iface lo inet loopback

# The primary network interface

auto eth0 
iface eth0 inet static

address 192.168.1.130 
netmask 255.255.255.0 
network 192.168.1.0 
broadcast 192.168.1.255 
gateway 192.168.1.1

# The secondary network interface

auto eth1 
iface eth1 inet static

address 192.168.2.2 
netmask 255.255.255.0 
network 192.168.2.0 
broadcast 192.168.2.255

ucarp-vid 1 
ucarp-vip 192.168.2.254 
ucarp-password secret 
ucarp-advskew 14 
ucarp-advbase 1 
ucarp-facility local1 
ucarp-master no 
ucarp-upscript /usr/share/ucarp/vip-up 
ucarp-downscript /usr/share/ucarp/vip-down

iface eth1:ucarp inet static

address 192.168.2.254 
netmask 255.255.255.0

4. Add to the /etc/rc.local:

root@master:~# ucarp -i eth1 -s 192.168.2.1 -v 1 -p secret -a 192.168.2.254 -u /etc/vip-up.sh -d /etc/vip-down.sh -z -B

root@slave:~# ucarp -i eth1 -s 192.168.2.2 -v 1 -p secret -a 192.168.2.254 -u /etc/vip-up.sh -d /etc/vip-down.sh -z -B


5. To check if works correctly check ip addresses on the interfaces on both hosts:

ip addr show

The virtual ip assigned to the ucarp interface should be seen only on the master host.
Ping the virtual ip to check if it is reachable.
Shutdown the master and observe that the slave takes over and virtual ip now can be seen.
Again, ping the virtual ip.

2 comments:

  1. Thanks for the post. It's great protocol. First time I setting it up under Ubuntu (http://sysadm.pp.ua/linux/carp-ubuntu.html) - cluster with three node still working. Could you please point me to right direction for building geo-distributed redundant IP solution??

    ReplyDelete