in Server_doc

FailOver Using Carp

  • Compile kernel Freebsd and add “device carp” on the KERNEL line
  • Set Sysctl /etc/sysctl.conf, and add line below :
net.inet.carp.allow=1
net.inet.carp.preempt=1
net.inet.carp.log=2
net.inet.carp.arpbalance=1

This setting must be same on both server.

  • Set Rc.conf /etc/rc.conf, and add line below :

web1 (master):

cloned_interfaces="carp0 carp1"
ifconfig_carp0="vhid 1 pass testist 172.16.1.157/23"
ifconfig_carp1="vhid 1 pass testist 203.101.123.11/23"

web2 (backup):

cloned_interfaces="carp0 carp1"
ifconfig_carp0="vhid 1 advskew 100 pass testist 172.16.1.157/23"
ifconfig_carp1="vhid 1 advskew 100 pass testist 203.101.123.11/23"

NB : advbase and advskew, which are used to control how frequently the host sends advertisements when it is the master for a virtual host, and pass which is used to authenticate carp advertisements. References “

example Master / Webserver1 :

webserver1# ifconfig
em0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM>
        ether 00:0c:29:2d:b3:89
        inet 172.16.1.151 netmask 0xfffffe00 broadcast 172.16.1.255
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
plip0: flags=8810<POINTOPOINT,SIMPLEX,MULTICAST> metric 0 mtu 1500
pfsync0: flags=0<> metric 0 mtu 1460
        syncpeer: 224.0.0.240 maxupd: 128
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=3<RXCSUM,TXCSUM>
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
        inet6 ::1 prefixlen 128
        inet 127.0.0.1 netmask 0xff000000
        nd6 options=3<PERFORMNUD,ACCEPT_RTADV>
pflog0: flags=0<> metric 0 mtu 33200
carp0: flags=49<UP,LOOPBACK,RUNNING> metric 0 mtu 1500
        inet 172.16.1.157 netmask 0xfffffe00
        carp: MASTER vhid 1 advbase 1 advskew 0

example Backup / webserver2 :

webserver2# ifconfig
em0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM>
        ether 00:0c:29:74:7c:86
        inet 172.16.1.152 netmask 0xfffffe00 broadcast 172.16.1.255
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
plip0: flags=8810<POINTOPOINT,SIMPLEX,MULTICAST> metric 0 mtu 1500
pfsync0: flags=0<> metric 0 mtu 1460
        syncpeer: 224.0.0.240 maxupd: 128
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=3<RXCSUM,TXCSUM>
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
        inet6 ::1 prefixlen 128
        inet 127.0.0.1 netmask 0xff000000
        nd6 options=3<PERFORMNUD,ACCEPT_RTADV>
pflog0: flags=0<> metric 0 mtu 33200
carp0: flags=49<UP,LOOPBACK,RUNNING> metric 0 mtu 1500
        inet 172.16.1.157 netmask 0xfffffe00
        carp: BACKUP vhid 1 advbase 1 advskew 100

Respond from messages log :

Oct  1 13:12:41 webserver2 kernel: carp0: link state changed to UP
Oct  1 13:14:38 webserver2 kernel: carp0: MASTER -> BACKUP (more frequent advertisement received)
Oct  1 13:14:38 webserver2 kernel: carp0: link state changed to DOWN

Line1 When the master server was down, carp tell to the backup server to up, and Line2 set the carp as a master server, and after that on Line3, is the message when the master server was up, the backup server state changed to down. And the master was set to Up again. Credited to : al