Blogs on System Administration, Scripting, System Monitoring, Cloud Computing & Virtualizaton, VoIP Systems, SMS Systems and Web Applications Development.

How to install Kannel in Centos 7?


Introduction

This article is to give an overview to install Kannel as SMS gateway with MySQL Support.

Description

In this article, we are installing latest Kannel version 1.4.4 in Centos 7.

Methodology

Before starting installation Process, Install some of the dependencies of Kannel:
$ sudo yum update
$ sudo yum groupinstall "Development tools" -y
$ sudo yum install libxml2-devel
 
Following is the step by step guide for installing Kannel from source.

Step # 1

Download and extract FreeSWITCH source:
$ cd /usr/local/src/
$ sudo wget http://www.kannel.org/download/1.4.4/gateway-1.4.4.tar.gz
$ sudo tar -zxvf gateway-1.4.4.tar.gz

Step # 2

Compile & Install Kannel with MySQL support:
$ cd /usr/local/src/gateway-1.4.4
$ sudo ./configure  --prefix=/etc/kannel --enable-start-stop-daemon
$ sudo make
$ sudo make install

Step # 3

Create path for SMSCs, logs and PID files:
$ sudo mkdir /etc/kannel/smscs
$ sudo mkdir /etc/kannel/logs
$ sudo mkdir /etc/kannel/run

Step # 4

Create main configuration file for Kannel i.e. kannel.conf
$ sudo vi /etc/kannel/kannel.conf
# kannel.conf
group = core
dlr-storage = internal
admin-port = 14000
admin-password = <admin-password>
status-password = <status-password>
admin-allow-ip = '*.*.*.*'
smsbox-port = 14004
log-level = 0
log-file = "/etc/kannel/logs/kannel.log"
box-allow-ip = "*.*.*.*"
 
# SMSC CONNECTIONS
# Here you can add as many SMSC you want and it will he easy to disable any SMSC
include = "/etc/kannel/smscs/smsc01.conf"
 
group = smsbox
smsbox-id = BOX1
bearerbox-host = X.X.X.X
sendsms-port = 14013
log-file = "/etc/kannel/logs/smsbox.log"
log-level = 0
access-log = "/etc/kannel/logs/access.log"
 
group = smsbox-route
smsbox-id = BOX1
smsc-id = SMSC01    
 
# For Receiving SMS
group = sms-service
keyword = default
catch-all = yes
max-messages = 0
 
# For Sending SMS
group = sendsms-user
username = <set-username-for-sending-sms>
password = <set-password-for-sending-sms>
#dlr-url = "http://someurl?"
default-smsc = SMSC01
concatenation= true
max-messages = 2
#forced-smsc = "SMSC01"

Step # 5

Create an SMSC file for the kannel
$ sudo vi /etc/kannel/smscs/smsc1.conf
 
group = smsc
smsc = smpp
smsc-id = SMSC01
host = <smsc-host>
port = <smsc-port>
system-id = <username>
smsc-password = <password>
system-type = SMPP
transceiver-mode = true
enquire-link-interval=30
reconnect-delay=10
interface-version=34
log-file = "/etc/kannel/logs/smsc01.log"
allowed-smsc-id = SMSC01

Step # 6

Create kannel init script:
$ sudo touch /etc/init.d/kannel
$ sudo chmod a+x /etc/init.d/kannel
$ sudo vi /etc/init.d/kannel

Add following code in init script of kannel:
#!/bin/sh
# Start/stop the Kannel boxes: One bearer box and one WAP box.
 
# This is the default init.d script for Kannel.  Its configuration is
# appropriate for a small site running Kannel on one machine.
 
# Make sure that the Kannel binaries can be found in $BOXPATH or somewhere
# else along $PATH.  run_kannel_box has to be in $BOXPATH.
 
BOXPATH=/etc/kannel/sbin
PIDFILES=/etc/kannel/run
CONFDIR=/etc/kannel
CONF=$CONFDIR/kannel.conf
 
USER=kannel
VERSION=""
#VERSION="-0.12.4"
 
RB=$BOXPATH/run_kannel_box$VERSION
BB=$BOXPATH/bearerbox$VERSION
WB=$BOXPATH/wapbox$VERSION
SB=$BOXPATH/smsbox$VERSION
SSD=$BOXPATH/start-stop-daemon$VERSION
 
PATH=$BOXPATH:$PATH
 
# On Debian, the most likely reason for the bearerbox not being available
# is that the package is in the "removed" or "unconfigured" state, and the
# init.d script is still around because it's a conffile.  This is normal,
# so don't generate any output.
#test -x $BOXPATH/$BB || exit 0
 
case "$1" in
  start)
    echo -n "Starting WAP gateway: bearerbox"
    $SSD --start --quiet --pidfile $PIDFILES/kannel_bearerbox.pid --exec $RB -- --pidfile $PIDFILES/kannel_bearerbox.pid $BB -- $CONF
    echo -n " smsbox"
    $SSD --start --quiet --pidfile $PIDFILES/kannel_smsbox.pid --exec $RB -- --pidfile $PIDFILES/kannel_smsbox.pid $SB -- $CONF
    echo "."
    ;;
 
  stop)
    echo -n "Stopping WAP gateway: "
    echo -n " smsbox"
    $SSD --stop --quiet --pidfile $PIDFILES/kannel_smsbox.pid --exec $RB
    echo -n " bearerbox"
    $SSD --stop --quiet --pidfile $PIDFILES/kannel_bearerbox.pid --exec $RB
    echo "."
    ;;
 
  status)
    CORE_CONF=$(grep -r 'group[[:space:]]*=[[:space:]]*core' $CONFDIR | cut -d: -f1)
    ADMIN_PORT=$(grep '^admin-port' $CORE_CONF | sed "s/.*=[[:space:]]*//")
    ADMIN_PASS=$(grep '^admin-password' $CORE_CONF | sed "s/.*=[[:space:]]*//")
    STATUS_URL="http://127.0.0.1:${ADMIN_PORT}/status.txt?password=${ADMIN_PASS}"
    lynx -source $STATUS_URL
    ;;
 
  reload)
    # We don't have support for this yet.
    exit 1
    ;;
 
  restart|force-reload)
    $0 stop
    sleep 1
    $0 start
    ;;
 
  *)
    echo "Usage: $0 {start|stop|status|reload|restart|force-reload}"
    exit 1
 
esac
 
exit 0

Step # 7

Starting kannel:
$ sudo service kannel start
Starting WAP gateway: bearerbox smsbox.

Verifying kannel Status
$ ps aux | grep kannel
 
root      2233  0.0  0.0  53172   684 ?        Ss   21:04   0:00 /etc/kannel/sbin/run_kannel_box --pidfile /etc/kannel/run/kannel_bearerbox.pid /etc/kannel/sbin/bearerbox -- /etc/kannel/kannel.conf
root      2235  0.0  0.1 384412  5712 ?        Sl   21:04   0:00 /etc/kannel/sbin/bearerbox -v 4 -- /etc/kannel/kannel.conf
root      2236  0.0  0.0  53172   744 ?        Ss   21:04   0:00 /etc/kannel/sbin/run_kannel_box --pidfile /etc/kannel/run/kannel_smsbox.pid /etc/kannel/sbin/smsbox -- /etc/kannel/kannel.conf
root     15412  0.0  0.1 377076  4120 ?        Sl   21:47   0:00 /etc/kannel/sbin/smsbox -v 4 -- /etc/kannel/kannel.conf
 
$ netstat -pln | grep box
 
tcp        0      0 0.0.0.0:14013               0.0.0.0:*                   LISTEN      15412/smsbox       
tcp        0      0 0.0.0.0:14000               0.0.0.0:*                   LISTEN      2235/bearerbox     
tcp        0      0 0.0.0.0:14004               0.0.0.0:*                   LISTEN      2235/bearerbox

Now Kannel v1.4.4 has been successfully installed in Centos 7.

Step # 8

Check Kannel status

Following is the URL to send SMS via Kannel:

12 comments:

  1. thanks, you have been great help

    ReplyDelete
  2. I think only one printing mistake is there in kannel.conf
    Instead of include = "/etc/kannel/smscs/smsc01.conf"
    it should be include = "/etc/kannel/smscs/smsc1.conf"
    Of course I have not yet fully configured it.
    curl 'http://X.X.X.X:14000/status?password=:14013; Connection refused.
    Please Help

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Same problem here although i was installing 1.4.5 and installed and configured entire kannel.conf to work with gsm modem. But after finishing installation i tried curl request but it failed i checked firewald multiple time all the required ports were opened on both tcp and udp but smsbox and bearerbox was not listening on those ports. And then I dont know how suddenly kennel started working for few minutes after that it failed again when i restarted the service. Checked kannel.conf & firewal rules multiple times but no luck. Now i am starting again from scratch to see where it went wrong.

      Delete
  3. Status is showing OK in curl command.
    But while sending SMS it shows, connection refused.
    Please Help.

    ReplyDelete
    Replies
    1. Check smsbox configurations in kannel.conf and check if the port is not closed.. Connection refused usually means no process is listing on that port. To confirm this try this command as root:

      netstat -nlp | grep box

      Delete
    2. Sorry its

      netstat -pln | grep box

      Delete
  4. In the post you are stating that you are installing kennel with mysql support but instead you are compiling it without mysql support.

    This line
    ./configure --prefix=/etc/kannel --enable-start-stop-daemon
    ./configure --prefix=/etc/kannel --enable-start-stop-daemon --with-mysql

    ReplyDelete
  5. *
    This line:
    ./configure --prefix=/etc/kannel --enable-start-stop-daemon

    Should be:
    ./configure --prefix=/etc/kannel --enable-start-stop-daemon --with-mysql

    Kindly fix this in the post as it can be little bit problematic for script kiddies like me.

    But Anyways thanks for this post I am currently following this to install kennel on a test build.

    ReplyDelete
  6. With business texting service USA, you also get the option of setting a customer signature that appears after every message you send. This is an excellent way to promote your business and it can be used as part of a marketing strategy.

    ReplyDelete

  7. Hello
    I have a question, I need some help
    => I need a solution that allows the user when he connects to a wifi guest to enter your number after receiving a code for access, a captive portal with SMS Gateway

    ReplyDelete

Please Enter your Comments Here.