CERN

CARP(e diem)

So. I’ve been setting up CARP today. It’s pretty simple. Very simple, actually.

On the node you want to have as master, do the following;

root@alihlt-carp0:~$ sysctl net.inet.carp.preempt=1
net.inet.carp.preempt: 0 -> 1

This will make the node always try to become master, so that, in case the master goes down, it will become master again when it comes back online. To make it persistent through boot, add the following to /etc/sysctl.conf (or uncomment it if it’s already there);

root@alihlt-carp0:~$ cat /etc/sysctl.conf|grep preempt
net.inet.carp.preempt=1 # 1=Enable carp(4) preemption

Then, let’s set up the CARP-interfaces (two, in our case — internal and external);

root@alihlt-carp0:~$ ifconfig carp0 137.138.11.19/16 vhid 55 pass supersecret advbase 1 advskew 0
root@alihlt-carp0:~$ ifconfig carp1 10.162.56.2/24 vhid 66 pass supersecret advbase 1 advskew 0
root@alihlt-carp0:~$ ifconfig carp0
carp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        lladdr 00:00:5e:00:01:37
        priority: 0
        carp: MASTER carpdev trunk0 vhid 55 advbase 1 advskew 0
        groups: carp
        status: master
        inet 137.138.11.19 netmask 0xffff0000 broadcast 137.138.255.255
        inet6 fe80::200:5eff:fe00:137%carp0 prefixlen 64 scopeid 0xc
root@alihlt-carp0:~$ ifconfig carp1
carp1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        lladdr 00:00:5e:00:01:42
        priority: 0
        carp: MASTER carpdev trunk1 vhid 66 advbase 1 advskew 0
        groups: carp
        status: master
        inet 10.162.56.2 netmask 0xffffff00 broadcast 10.162.56.255
        inet6 fe80::200:5eff:fe00:142%carp1 prefixlen 64 scopeid 0xd

That’s it! Now, we need to make it persistent through reboots;

root@alihlt-carp0:~$ echo "inet 137.138.11.19 255.255.0.0 137.138.255.255 vhid 55 pass supersecret advbase 1 advskew 0" > /etc/hostname.carp0
root@alihlt-carp0:~$ echo "inet 10.162.56.2 255.255.255.0 10.162.56.255 vhid 66 pass supersecret advbase 1 advskew 0" > /etc/hostname.carp1

Now, we apply the exactly the same configuration on the other node(s), where the only thing we change, is the value of “advskew”; the higher this number is, the lower down the list it comes when a new master is selected (it’s based on a formula, so, you can also change “advbase”, but this leads to longer time before a backup takes over in case the master goes down). I’ve used 100 as the value on the backup.

Output from the node that currently is the backup;

carp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        lladdr 00:00:5e:00:01:37
        priority: 0
        carp: BACKUP carpdev trunk0 vhid 55 advbase 1 advskew 100
        groups: carp
        status: backup
        inet 137.138.11.19 netmask 0xffff0000 broadcast 137.138.255.255
        inet6 fe80::200:5eff:fe00:137%carp0 prefixlen 64 scopeid 0xc
root@alihlt-carp1:~$ ifconfig carp1
carp1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        lladdr 00:00:5e:00:01:42
        priority: 0
        carp: BACKUP carpdev trunk1 vhid 66 advbase 1 advskew 100
        groups: carp
        status: backup
        inet 10.162.56.2 netmask 0xffffff00 broadcast 10.162.56.255
        inet6 fe80::200:5eff:fe00:142%carp1 prefixlen 64 scopeid 0xd