You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

This guide will help you to install Latest Kamailio SIP Server on CentOS 7 / CentOS 8 Linux server. This is part of Series tutorials on Building an Enterprise VOIP System. Kamailio is a distribution of SER and provides a scalable SIP server suitable for small through to carrier grade installations.

Features of Kamailio

Kamailio’s main advantages for use alongside Media server like Asterisk are:

  • Kamailio can handle over 5000 call setups per second.
  • Can serve up to 300,000 active subscribers with just a 4GB Ram System.
  • Clustering can easily be realized by adding more Kamailio servers

Kamailio can function as:
● Registrar server
● Location server
● Proxy server
● SIP Application server
● Redirect server

Other Features of Kamailio are:

  • NAT traversal support for SIP and RTP traffic
  • Load balancing with many distribution algorithms and
    failover support
  • Provides flexible least cost routing
  • Easy to realize routing failover
  • Support both IPv4 and IPv6
  • SCTP multi-homing and multi-streaming
  • Communication can be over UDP, TCP, TLS, and SCTP
  • Digest SIP User authentication
  • Provides event-based accounting
  • Data storage can be to database, Radius or Diameter
  • Extensible Java, Python, Lua and Perl Programming interface
  • TLS support for SIP signaling and transparent handling of SRTP for secure audio

We have tested this guide on:

  • Kamailio 5.x
  • CentOS 7 / CentOS 8

Install Kamailio SIP Server on CentOS 7 / CentOS 8

Before we dive deep into the installation process, let’s get some heads up on basics about Kamailio SIP Server.

Step 1: Set SELinux to a Permissive/Disabled mode

If you’re not SELinux lover, I recommend you put it in Permissive mode:

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

If you decide to permanently disable it, you’ll need to reboot your  CentOS system:

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
sudo reboot

After rebooting, confirm SELinux status:

$ sestatus 
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31

Step 2: Install MariaDB Database server

Kamailio requires a database server to function. For this, we’ll use the MariaDB database server which can be installed on CentOS 7 / CentOS 8:

sudo yum -y install mariadb-server
sudo systemctl enable --now mariadb
sudo mysql_secure_installation

Step 3: Add Kamailio RPM Repository

CentOS 8:

sudo wget -O /etc/yum.repos.d/kamailio.repo http://download.opensuse.org/repositories/home:/kamailio:/v5.3.x-rpms/CentOS_8/home:kamailio:v5.3.x-rpms.repo

As of this article update, some packages are not on CentOS 8 repository. I had to use Fedora 29 repository on CentOS 8. If the same issue happens to you, change the repository by running the commands below.

sudo wget -O /etc/yum.repos.d/kamailio.repo http://download.opensuse.org/repositories/home:/kamailio:/v5.3.x-rpms/Fedora_29/home:kamailio:v5.3.x-rpms.repo

CentOS 7:

sudo wget -O /etc/yum.repos.d/kamailio.repo http://download.opensuse.org/repositories/home:/kamailio:/v5.3.x-rpms/CentOS_7/home:kamailio:v5.3.x-rpms.repo

Step 4: Install Kamailio SIP Server on CentOS 8 / CentOS 7

Once the repository is added, install Kamailio SIP Server on CentOS 8 / CentOS 7 Linux.

sudo yum install vim kamailio kamailio-presence kamailio-ldap kamailio-mysql kamailio-debuginfo kamailio-xmpp kamailio-unixodbc kamailio-utils kamailio-tls kamailio-outbound kamailio-gzcompress

Dependency tree should be shown nd you can hit th y key in your keyboard to begin installation.

Dependencies resolved.
========================================================================================================================================================
 Package                           Arch                Version                                             Repository                              Size
========================================================================================================================================================
Installing:
 kamailio                          x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms              5.6 M
 kamailio-debuginfo                x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms              3.8 M
 kamailio-gzcompress               x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms               19 k
 kamailio-ldap                     x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms               99 k
 kamailio-mysql                    x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms               74 k
 kamailio-outbound                 x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms               24 k
 kamailio-presence                 x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms              673 k
 kamailio-tls                      x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms              187 k
 kamailio-unixodbc                 x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms               39 k
 kamailio-utils                    x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms               37 k
 kamailio-xmpp                     x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms               53 k
Upgrading:
 vim-common                        x86_64              2:8.0.1763-13.el8                                   AppStream                              6.3 M
 vim-enhanced                      x86_64              2:8.0.1763-13.el8                                   AppStream                              1.4 M
Installing dependencies:
 mysql-common                      x86_64              8.0.17-3.module_el8.0.0+181+899d6349                AppStream                              143 k
 mysql-libs                        x86_64              8.0.17-3.module_el8.0.0+181+899d6349                AppStream                              1.2 M
 unixODBC                          x86_64              2.3.7-1.el8                                         AppStream                              458 k
Installing weak dependencies:
 kamailio-debugsource              x86_64              5.3.3-4.1                                           home_kamailio_v5.3.x-rpms              3.7 M
Enabling module streams:
 mysql                                                 8.0                                                                                             

Transaction Summary
========================================================================================================================================================
Install  15 Packages
Upgrade   2 Packages

Total download size: 24 M
Is this ok [y/N]: y

Confirm installed Kamailio version:

$ kamailio -version
version: kamailio 5.3.3 (x86_64/linux) c918a3
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: c918a3 
compiled on 14:32:52 Mar 16 2020 with gcc 8.2.1

Step 5: Configuring Kamailio on CentOS 8 / CentOS 7

Edit the file /etc/kamailio/kamctlrc  and make sure the DBENGINE variable is set to MySQL. Remove the pound symbol to uncomment it.

sudo vi /etc/kamailio/kamctlrc

Set Database engine to MYSQL

DBENGINE=MYSQL
DBHOST=localhost

Run the command below to create users and tables needed by Kamailio ( Schema).

$ sudo kamdbctl create
MySQL password for root:
INFO: test server charset
INFO: creating database kamailio …
INFO: granting privileges to database kamailio …
INFO: creating standard tables into kamailio …
INFO: Core Kamailio tables succesfully created.
Install presence related tables? (y/n): y
INFO: creating presence tables into kamailio …
INFO: Presence tables succesfully created.
Install tables for imc cpl siptrace domainpolicy carrierroute
drouting userblacklist htable purple uac pipelimit mtree sca mohqueue
rtpproxy rtpengine secfilter? (y/n): y
INFO: creating extra tables into kamailio …
INFO: Extra tables succesfully created.
Install tables for uid_auth_db uid_avp_db uid_domain uid_gflags
uid_uri_db? (y/n): y
INFO: creating uid tables into kamailio …
INFO: UID tables succesfully created.

When asked for root password, enter the MySQL root user password as configured through mysql_secure_installation

Answer Yes to all the questions that follow. The kamdbctl create command will add two Mysql users:

kamailio: With the password.kamailiorw It has read/write access permissions to the Kamailio database.

kamailioro: The password for this user is kamailioro. It has read-only access permissions to the Kamailio database.

Next is to edit /etc/kamailio/kamailio.cfg to configure Kamailio:

sudo vi /etc/kamailio/kamailio.cfg

Add the following lines just below #!KAMAILIO.

#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB
#!define WITH_NAT
#!define WITH_PRESENCE
#!define WITH_ACCDB

Start Kamailio

sudo systemctl restart kamailio

Enable the service to start on boot:

sudo systemctl enable kamailio

That’s the end. You should now have a running Kamailio SIP server on your CentOS 8 / CentOS 7 Linux.

$ systemctl status kamailio
● kamailio.service - Kamailio (OpenSER) - the Open Source SIP Server
   Loaded: loaded (/usr/lib/systemd/system/kamailio.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-05-03 16:35:23 EAT; 12s ago
 Main PID: 9648 (kamailio)
    Tasks: 41 (limit: 24003)
   Memory: 50.0M
   CGroup: /system.slice/kamailio.service
           ├─9648 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9649 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9650 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9651 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9652 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9653 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9654 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9655 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9656 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9658 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
           ├─9659 /usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 4
......

Other guides:

Install Asterisk PBX on CentOS 8

Install Asterisk PBX on CentOS 7

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF