Categories
Corosync Failover High-Availability Kamailio Pacemaker SIP VoIP

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:

kam01: 10.10.10.18
kam02: 10.10.10.19

Floating IP: 10.10.10.200

First, add both nodes to /etc/hosts

10.10.10.18    kam01
10.10.10.19    kam02

Install corosync and pacemaker:

apt-get install ntp corosync pacemaker -y

Generate /etc/corosync/authkey:

corosync-keygen

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
}
EOF

Add corosync config:

cat >/etc/corosync/corosync.conf<<EOF
#
totem {
        version: 2
        transport: udpu
        interface {
                member {
                        memberaddr: 10.10.10.18
                }
                member {
                        memberaddr: 10.10.10.19
                }
                ringnumber: 0
                bindnetaddr: 10.10.10.0
                mcastport: 5405
        }
}

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

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="10.10.10.200" nic="eth0" cidr_netmask="255.255.255.0" 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:

# TO CLEAR CONFIG AND START OVER
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:

# TO LIST RESOURCE AGENTS
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:

# ADVANCED EDITING
cibadmin --query > tmp.xml
vi tmp.xml
cibadmin --replace --xml-file tmp.xml

 

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

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?

regards
Milton

Leave a Reply

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