Install Kamailio SIP Server on Rocky Linux 8|AlmaLinux 8

Posted on 24 views

In this post, we shall perform a complete step-by-step installation of Kamailio SIP Server on Rocky Linux 8 | AlmaLinux 8. If you’re new to the world of VoIP and PBX systems, Kamailio is a successor a project previous known as (OpenSER and SER). It is a free to use and Open Source SIP Server released under the GPLv2+ license. Kamailio is capable of handling thousands of call setups per second. Kamailio can be setup as single server or to work in clustered and distributed manner.

Key features of Kamailio SIP Server

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

  • Robust and Performant SIP (RFC3261) Server – Proxy, SIP Application server, Registrar server, Location server, and Redirect server.
  • It is a flexible sip server a small footprint and modular architecture
  • Kamailio provides robust SIP Routing Capabilities
  • In Transport, it has support for UDP, TCP, TLS and SCTP protocols
  • Asynchronous Processing
  • Uses secure Communication through authentication, authorization, and encryption mechanisms
  • Support for Accounting, and IP and DNS features
  • Kamailio can be used in geographic distributed VoIP platforms
  • Kamailio least-cost-routing scales up to millions of routing rules
  • Straightforward interconnection with PSTN gateways
  • Support for Multiple Database Backends – (MySQL, PostgreSQL, SQLite, UnixODBC, BerkeleyDB, Oracle, text files) and other database types which have unixodbc drivers
  • Extensibility APIs – Support Perl, Java, Lua, JavaScript, Python interfacing among many other languages

Install Kamailio SIP Server on Rocky Linux 8 | AlmaLinux 8

With the introduction of Kamailio SIP Server, we can switch our focus to the actual installation. The requirements for this installation are as captured below:

  • Rocky Linux 8 | AlmaLinux 8 server
  • Internet access is required on the server
  • Terminal access to the server as root or as standard user with sudo powers

Step 1: Update system and set SELinux in Permissive

Update your system by running the following commands

sudo dnf update

After the upgrade is done, set SELinux in Permissive mode or optionally disable it.

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

Confirm the status of SELinux after the update:

$ 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: Add Kamailio YUM Repository

All Kamailio packages for the latest releases are provided in an RPM repository. This repo has to be added to the system manually.

Add Kamailio YUM repository on your system using below commands:

sudo yum -y install dnf-plugins-core
sudo yum config-manager --add-repo https://rpm.kamailio.org/centos/kamailio.repo

Check the current list of repositories configured on your system to confirm:

$ sudo dnf -y repolist
repo id                                                                   repo name
appstream                                                                 Rocky Linux 8 - AppStream
baseos                                                                    Rocky Linux 8 - BaseOS
extras                                                                    Rocky Linux 8 - Extras
kamailio                                                                  Kamailio - latest - Packages for the Kamailio latest release

We can see Kamailio repo in the output.

Step 3: Install Kamailio SIP Server on Rocky Linux 8 | AlmaLinux 8

We need a database server while running Kamailio SIP server for storing data. The version of MariaDB available on the system repositories is ok for this purpose.

sudo dnf -y install mariadb-server

Start and secure MariaDB server installation

sudo systemctl enable --now mariadb
sudo mysql_secure_installation

Ensure connection to MariaDB shell is working

$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit

Install all Kamailio SIP Server packages and dependencies:

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

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

...
Dependencies resolved.
======================================================================================================================================================================================================
 Package                                           Architecture                        Version                                                           Repository                              Size
======================================================================================================================================================================================================
Installing:
 kamailio                                          x86_64                              5.5.2-0.el8.centos                                                kamailio                               6.2 M
 kamailio-debuginfo                                x86_64                              5.5.2-0.el8.centos                                                kamailio                               4.3 M
 kamailio-gzcompress                               x86_64                              5.5.2-0.el8.centos                                                kamailio                                24 k
 kamailio-ldap                                     x86_64                              5.5.2-0.el8.centos                                                kamailio                               109 k
 kamailio-mysql                                    x86_64                              5.5.2-0.el8.centos                                                kamailio                                82 k
 kamailio-outbound                                 x86_64                              5.5.2-0.el8.centos                                                kamailio                                29 k
 kamailio-presence                                 x86_64                              5.5.2-0.el8.centos                                                kamailio                               736 k
 kamailio-tls                                      x86_64                              5.5.2-0.el8.centos                                                kamailio                               195 k
 kamailio-unixodbc                                 x86_64                              5.5.2-0.el8.centos                                                kamailio                                45 k
 kamailio-utils                                    x86_64                              5.5.2-0.el8.centos                                                kamailio                                43 k
 kamailio-xmpp                                     x86_64                              5.5.2-0.el8.centos                                                kamailio                                60 k
Upgrading:
 vim-common                                        x86_64                              2:8.0.1763-16.el8                                                 appstream                              6.3 M
 vim-enhanced                                      x86_64                              2:8.0.1763-16.el8                                                 appstream                              1.4 M
Installing dependencies:
 libtool-ltdl                                      x86_64                              2.4.6-25.el8                                                      baseos                                  57 k
 mysql-common                                      x86_64                              8.0.26-1.module+el8.4.0+652+6de068a7                              appstream                              133 k
 mysql-libs                                        x86_64                              8.0.26-1.module+el8.4.0+652+6de068a7                              appstream                              1.4 M
 unixODBC                                          x86_64                              2.3.7-1.el8                                                       appstream                              453 k
Installing weak dependencies:
 kamailio-debugsource                              x86_64                              5.5.2-0.el8.centos                                                kamailio                               3.9 M
Enabling module streams:
 mysql                                                                                 8.0

Transaction Summary
======================================================================================================================================================================================================
Install  16 Packages
Upgrade   2 Packages

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

The version of Kamailio installed can be checked with the following command:

$ kamailio -version
version: kamailio 5.5.2 (x86_64/linux) 55e232
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_BLOCKLIST, 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: 55e232
compiled on 14:13:04 Aug 25 2021 with gcc 8.4.1

Step 5: Connect Kamailio to database server

We need to edit Kamailio main configuration file /etc/kamailio/kamctlrc and configure DBENGINE

sudo vim /etc/kamailio/kamctlrc

Set DBENGINE to MySQL and DBHOST to localhost:

DBENGINE=MYSQL
DBHOST=localhost

Create all databases and tables required by Kamailio:

$ 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 successfully created.
Create the presence related tables? (y/n): y
INFO: creating presence tables into kamailio ...
INFO: Presence tables successfully created.
Create the tables for imc cpl siptrace domainpolicy carrierroute
		drouting userblocklist htable purple uac pipelimit mtree sca mohqueue
		rtpproxy rtpengine secfilter? (y/n): y
INFO: creating extra tables into kamailio ...
INFO: Extra tables successfully created.
Create the 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 successfully created.

Two database users are created:

  • 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.

Access can be tested like below:

$ mysql -u kamailio -p
Enter password: kamailiorw
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 68
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye

$ mysql -u kamailioro -p
Enter password: kamailioro
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 69
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye

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

kamailio-configuration

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 Rocky Linux 8 | AlmaLinux 8 Linux.

$ systemctl status kamailio
 kamailio.service - Kamailio - the Open Source SIP Server
   Loaded: loaded (/usr/lib/systemd/system/kamailio.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-12-09 15:56:10 UTC; 10s ago
 Main PID: 10550 (kamailio)
    Tasks: 33 (limit: 49496)
   Memory: 23.5M
   CGroup: /system.slice/kamailio.service
           ├─10550 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10551 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10552 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10553 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10554 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10555 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10556 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10557 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10558 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10559 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10560 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10561 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10562 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10563 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10564 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10565 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10566 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10567 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10568 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10569 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10570 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10571 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10572 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10573 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10574 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10575 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10576 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10577 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10578 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10579 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10580 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           ├─10581 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
           └─10582 /usr/sbin/kamailio --atexit=no -DD -P /run/kamailio/kamailio.pid -f /etc/kamailio/kamailio.cfg -m 64 -M 8
...

 

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.