I recently had the little challenge to build up a failover cluster on Ubuntu for SMTP services (postfix in my case).
Initially I had one single SMTP server running postfix. When the server is down, well… the service is down as well. So I decided to build up a second one, that would take over in case the first one crashes. What I want is a basic failover cluster (active/passive).
I wanted to keep it very simple and efficient, without going through the complex configuration of heartbeat for example.
I therefore decided to use Ucarp, a implementation of carp for Ubuntu.
Here is my architecture :
Server #1 : My first server where I configured postfix (IP : 172.17.0.75)
Server #2 : My second server where I configured postfix exactly like on Server #1 (IP : 172.17.0.76)
172.17.0.74 : The virtual IP address, created using Ucarp.
Ucarp is very simple : it works that way. If server #1 is up, then the virtual IP 172.17.0.74 is assigned to server #1. If server #1 is down, then the virtual IP 172.17.0.74 is assigned to server #2 (assuming server #2 is up). This way you have a simple failover cluster…
Here is how to set it up :
Step 1 : On Server #1 (172.17.0.75)
- Login to server #1 on and install ucarp
> sudo apt-get install ucarp
- Edit the file /etc/network/interfaces
> sudo nano /etc/network/interfaces # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth1 iface eth1 inet static ################################ # standard network configuration ################################ address 172.17.0.75 netmask 255.255.240.0 gateway 172.17.1.254 network 172.17.0.0 broadcast 172.17.0.255 ################################ # ucarp configuration ################################ # vid : The ID of the virtual server [1-255] ucarp-vid 1 # vip : The virtual address ucarp-vip 172.17.0.74 # password : A password used to encrypt Carp communications ucarp-password secret # advskew : Advertisement skew [1-255] ucarp-advskew 1 # advbase : Interval in seconds that advertisements will occur ucarp-advbase 1 # master : determine if this server is the master ucarp-master yes # The carp network interface, on top of eth1 iface eth1:ucarp inet static address 172.17.0.74 netmask 255.255.240.0
- Restart the network interfaces, so that the ucarp config is taken into consideration
> sudo /etc/init.d/networking restart
Step 2 : On Server #2 (172.17.0.76)
- Login to server #1 on and install ucarp
> sudo apt-get install ucarp
- Edit the file /etc/network/interfaces
> sudo nano /etc/network/interfaces # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth1 iface eth1 inet static ################################ # standard network configuration ################################ address 172.17.0.76 netmask 255.255.240.0 gateway 172.17.1.254 network 172.17.0.0 broadcast 172.17.0.255 ################################ # ucarp configuration ################################ # vid : The ID of the virtual server [1-255] ucarp-vid 1 # vip : The virtual address ucarp-vip 172.17.0.74 # password : A password used to encrypt Carp communications ucarp-password secret # advskew : Advertisement skew [1-255] ucarp-advskew 100 # advbase : Interval in seconds that advertisements will occur ucarp-advbase 1 # master : determine if this server is the master ucarp-master no # The carp network interface, on top of eth1 iface eth1:ucarp inet static address 172.17.0.74 netmask 255.255.240.0
- Restart the network interfaces, so that the ucarp config is taken into consideration
> sudo /etc/init.d/networking restart
Step 3 : Check that it works fine
While the two servers are running, check the interface on server #1 :
> sudo ifconfig eth1 Link encap:Ethernet HWaddr 00:0c:29:5b:d8:03 inet addr:172.17.0.75 Bcast:172.17.0.255 Mask:255.255.240.0 inet6 addr: fe80::20c:29ff:fe5b:d803/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:66814 errors:0 dropped:0 overruns:0 frame:0 TX packets:21871 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:11618538 (11.6 MB) TX bytes:10521832 (10.5 MB) eth1:ucarp Link encap:Ethernet HWaddr 00:0c:29:5b:d8:03 inet addr:172.17.0.74 Bcast:172.17.15.255 Mask:255.255.240.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
You will see the section highlighted in red, that shows that the carp IP address 172.17.0.74 is active on the interface.
If you do the same, but this time on server #2, you’ll see that the carp IP is not active :
> sudo ifconfig
eth1 Link encap:Ethernet HWaddr 00:0c:29:92:ba:ac
inet addr:172.17.0.76 Bcast:172.17.0.255 Mask:255.255.240.0
inet6 addr: fe80::20c:29ff:fe92:baac/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:67433 errors:0 dropped:0 overruns:0 frame:0
TX packets:340 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4644650 (4.6 MB) TX bytes:73256 (73.2 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
If you then shutdown server #1, you’ll be able to see that the Carp IP address is transferred to server #2 :
> sudo ifconfig eth1 Link encap:Ethernet HWaddr 00:0c:29:92:ba:ac inet addr:172.17.0.76 Bcast:172.17.0.255 Mask:255.255.240.0 inet6 addr: fe80::20c:29ff:fe92:baac/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:68775 errors:0 dropped:0 overruns:0 frame:0 TX packets:402 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4739385 (4.7 MB) TX bytes:82180 (82.1 KB) eth1:ucarp Link encap:Ethernet HWaddr 00:0c:29:92:ba:ac inet addr:172.17.0.74 Bcast:172.17.15.255 Mask:255.255.240.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
If you turn back on server #1, you’ll see that server #1 will get the carp back. Server #1 is the master, and if it is up, it will get the Carp back.
Step 4 : Use it !!!
Now that it works fine, you can start using it.
Just make sure you use the CARP IP address 172.17.0.74 (instead of 75 or 76).
Conclusion :
This is a simple, a very fast way of setting up a failover cluster.The big advantages is that it is simple to setup and manage.
The disadvantages is that it only provide IP failover : the configuration of the services running on top of the server (postfix, apache, mysql, …) are not transferred, nor synchronized.
Side notes :
I’m running Ubuntu Server 10.04 LTS x64 in a virtualized environment over ESXi 5.
So if you wonder if it works as well on virtual machines, well the answer is yes !
Credits :
http://valeriytroshin.blogspot.fr/2011/08/carp-failover-redundancy-in-ubuntu-1104.html : Great and nearly only source of inspiration when I setup my servers !


