Kamailio: High-Availability/Failover with Corosync and Pacemaker on Debian 7

In this setup, we will have 2 Kamailio servers, referred to as ‘nodes’. One will be active and one will standby. There is a 3rd ‘floating’ IP that is moved to which ever node is active. Kamailio should be configured to use the floating IP. In this example, the nodes are:


Floating IP:

First, add both nodes to /etc/hosts    kam01    kam02

Install corosync and pacemaker:

apt-get install ntp corosync pacemaker -y

Generate /etc/corosync/authkey:


Copy corosync-key  to kam02:

scp -P 22 /etc/corosync/authkey root@kam02:/etc/corosync

Enable corosync on kam01 & kam02:

sed -i "s/START=no/START=yes/g" /etc/default/corosync

Enable pacemaker service in corosync:

cat > /etc/corosync/service.d/pcmk << EOF
service {
  name: pacemaker
  ver: 1

Add corosync config:

cat >/etc/corosync/corosync.conf<<EOF
totem {
        version: 2
        transport: udpu
        interface {
                member {
                member {
                ringnumber: 0
                mcastport: 5405

logging {
        to_logfile: yes
        logfile: /var/log/corosync/corosync.log
        debug: off
        timestamp: on
        logger_subsys {
                subsys: AMF
                debug: off

Start corosync and pacemaker:

service corosync start
service pacemaker start

Configure corosync, changes will propagate to other node. Make sure to disable stonith:

crm configure property stonith-enabled=false
crm configure primitive FAILOVER-IP ocf:heartbeat:IPaddr2 params ip="" nic="eth0" cidr_netmask="" op monitor interval="10s"
crm configure primitive KAM-HA lsb:kamailio op monitor interval="30s"
crm configure group KAM-HA-GROUP FAILOVER-IP KAM-HA
crm configure colocation KAM-HA-GROUP-COLO inf: FAILOVER-IP KAM-HA
crm configure order KAM-HA-ORDER inf: FAILOVER-IP KAM-HA
crm configure property no-quorum-policy=ignore

You need no-quorum-policy=ignore for a 2 node cluster. If you messed up during the crm configure part, you can start over using these commands:

crm configure property stop-all-resources=true
crm configure erase

It’s sometimes useful to see what resource agents are available, you can check with these commands:

crm ra list lsb
crm ra list systemd # (if using systemd init system)
crm ra list ocf heartbeat
crm ra list ocf pacemaker

If you need to migrate services and floating IP to other node you can run:

crm resource migrate KAM-HA-GROUP kam02

If you need edit specific parameters in the config, you can export it to xml, make the changes and re-import them:

cibadmin --query > tmp.xml
vi tmp.xml
cibadmin --replace --xml-file tmp.xml


One thought on “Kamailio: High-Availability/Failover with Corosync and Pacemaker on Debian 7”

  1. Hey. good tutorial, what would happen if the clusters have two interface one for internet and another for LAN, the idea is that these kamailios will face to some asterisks servers? do I just need to use one of the floating ip for the fail over (i.e the LAN ip) or does the public ip will also need to be part of the settings?


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.