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

 

RTPProxy: Compiling & Installing on Debian 8

cd /usr/src/
git clone https://github.com/sippy/rtpproxy.git
cd rtpproxy
./configure
make
make install

cp scripts/rtpproxy.init.debian /etc/init.d/rtpproxy
chmod +x /etc/init.d/rtpproxy
sed -i "s/DAEMON=\/usr\/bin\/rtpproxy/DAEMON=\/usr\/local\/bin\/rtpproxy/g" /etc/init.d/rtpproxy

cat > /etc/default/rtpproxy <<EOT
# Defaults for rtpproxy
# I like to use same user as Kamailio when running on Kamailio box
USER="kamailio"
GROUP="kamailio"
PIDFILE="/var/run/rtpproxy.pid"
# replace with your network interface IP address
LISTEN_ADDR=9.8.7.6

# The control socket.
CONTROL_SOCK="unix:/var/run/rtpproxy.sock"
# To listen on an UDP socket, uncomment this line:
#CONTROL_SOCK=udp:127.0.0.1:7722

# Additional options that are passed to the daemon.
EXTRA_OPTS="-l \$LISTEN_ADDR"

DAEMON_OPTS="-s \$CONTROL_SOCK -u \$USER:\$GROUP -p \$PIDFILE \$EXTRA_OPTS"

EOT

/etc/init.d/rtpproxy start

FreeSWITCH: High call volume alert script

I was tasked to come up with a way to monitor for high call volume in FreeSWITCH. I came up with this here is a simple script that will check the channel count and email me if it’s greater than $MAX_CALLS

 

#!/bin/bash

MAX_CALLS=100
CHANNEL_COUNT=$(/usr/bin/fs_cli -x "show channels count" | awk '/total/ {print $1}')

if [ $CHANNEL_COUNT -gt $MAX_CALLS ]; then
        # From
        FROM="alert@voipxswitch.com"
        # Subject
        SUBJECT="High Call Volume"
        # To
        TOEMAIL="admin@voipxswitch.com"

        /usr/bin/mailx "-aFrom:$FROM" -s "$SUBJECT" "$TOEMAIL"<<END
This is an email alert to notify you that the server has reached $CHANNEL_COUNT calls.
END

fi

Kamailio: Compiling & Installing on Debian 8

Here we will compile and install Kamailio from GIT master branch and create our own systemd service configuration file.

# install dependencies
apt-get install libpq-dev pkg-config build-essential bison make libperl-dev git linux-headers-$(uname -r) libunistring-dev flex libjson-c-dev libevent-dev 

# download & compile
cd /usr/src
git clone git://git.sip-router.org/kamailio kamailio-git
cd kamailio-git

# include your own modules, these are what i compile
make include_modules="db_postgres debugger usrloc dispatcher registrar auth auth_db avp avpops tm rr pv sl maxfwd nathelper textops siputils uac uac_redirect db_text xlog sanity htable app_perl path ctrl tls ctl mi_fifo kex permissions dmq dialog websocket xhttp textopsx sdpops kazoo tmx uuid presence presence_xml presence_dialoginfo presence_mwi outbound" cfg

make all

make install

# add kam group/user
groupadd -g 6001 kamailio
useradd -u 6001 -g 6001 -d /usr/local/kamailio -M -s /bin/false kamailio

# create custom directories for kamailio
mkdir -p /usr/local/kamailio/{run,etc,tmp}

# create kamailio default file
cat >/etc/default/kamailio <<EOT
RUN_KAMAILIO=yes
USER=kamailio
GROUP=kamailio
SHM_MEMORY=64
PKG_MEMORY=8
PIDFILE=/usr/local/kamailio/run/kamailio.pid
CFGFILE=/usr/local/kamailio/etc/kamailio.cfg
#DUMP_CORE=yes
EOT

# create systemd file
cat >/etc/systemd/system/kamailio.service<<EOT
[Unit]
Description=Kamailio (OpenSER) - the Open Source SIP Server
After=syslog.target network.target

[Service]
Type=forking
EnvironmentFile=-/etc/default/kamailio
PIDFile=\$PIDFILE
# ExecStart requires a full absolute path
ExecStart=/usr/local/sbin/kamailio -P \$PIDFILE -f \$CFGFILE -m \$SHM_MEMORY -M \$PKG_MEMORY -u \$USER -g \$GROUP
ExecStopPost=/bin/rm -f \$PIDFILE
Restart=on-abort

[Install]
WantedBy=multi-user.target

EOT

# enable kamailio service
systemctl enable kamailio

# if you change the systemd file you can reload changes with:
systemctl daemon-reload

# set permissions to /usr/local/kamailio
chown kamailio:kamailio -R /usr/local/kamailio

Please note, by default, Kamailio will install it’s configuration files in /usr/local/etc/kamailio, modules in /usr/local/lib64/kamailio, and binaries in /usr/local/sbin