Skip to main content

Guide to Kamailio Installation

As of this writing, this guide will guarantee that you will have a successful Kamailio installation -- tried and tested. Please comment if this post needs to be updated. 😁

Setup YUM Repository:

1) Install wget so we can pull down the rpm.

Code:
yum install wget

2) Let’s download the yum repo file for our CentOS version and update the system so yum is aware of the new repository.

Code:
cd /etc/yum.repos.d/

Code:
wget http://download.opensuse.org/repositories/home:/kamailio:/v4.4.x-rpms/CentOS_7/home:kamailio:v4.4.x-rpms.repo

3) Update system so yum is aware of the new repository.

Code:
yum update

4) You can look at the kamailio packages in the YUM repository by typing:

Code:
yum search kam



Install Kamailio and Required Database Modules:

1) Install the following packages from the new repo.

Code:
sudo yum install -y kamailio kamailio-ldap kamailio-mysql kamailio-presence kamailio-postgres kamailio-debuginfo kamailio-xmpp kamailio-unixodbc kamailio-utils kamailio-tls kamailio-outbound kamailio-gzcompress

2) Set kamailio to start at boot.

chkconfig kamailio on

3) The Kamailio configuration files will be owned by the root user, rather than the kamailio user created by the Kamailio package. We will need to change the ownership of these files.

Code:
chown kamailio:kamailio /etc/default/kamailio

Code:
chown -R kamailio:kamailio /etc/kamailio/

Code:
echo "d /run/kamailio 0750 kamailio kamailio" > /etc/tmpfiles.d/kamailio.conf



Install MySQL:

1) Since we plan on using MySQL, we will need to install the MySQL server as well as the client.

Code:
yum install -y mariadb-server mariadb

2) Next we need to start up MySQL:

Code:
systemctl start mariadb

3) And enable mysqld at boot.

Code:
systemctl enable mariadb

4)

Code:
/usr/bin/mysql_secure_installation

5) Now we can set a root password for mysql:

You can hit yes to all the options. There is no root password as of yet, so the first question will be blank. Be sure to use a secure unique password for your root user.

Enter current password for root (enter for none): (press enter)

Set root password? [Y/n] Y
New password: (enter leads)
Re-enter new password: (enter leads)

Remove anonymous users? [Y/n] Y

Disallow root login remotely? [Y/n] Y

Remove test database and access to it? [Y/n] Y

Reload privilege tables now? [Y/n] Y



Configure Kamailio to use MySQL:

By default, Kamailio does not use MySQL. To change this we need to edit one of Kamailio’s configuration files.

Code:
vi /etc/kamailio/kamctlrc

Then press "i" to edit the file.

1) Uncomment the DBENGINE parameter by removing the pound symbol and make sure the value equals MYSQL. The parameter should look like this afterwards:

Code:
DBENGINE=MYSQL

2) To have the kamdbctl command create the mysql database with the correct permissions, we will want to set the databaseusers and passwords in kamctlrc

Uncomment code to appear like this:
## database read/write user
DBRWUSER="kamailio"

## password for database read/write user
DBRWPW="kamailiorw"

## database read only user
DBROUSER="kamailioro"

## password for database read only user
DBROPW="kamailioro"

3) Press ESC then type ":wq"



Create the Kamailio Database Schema:

1) This command will create all the users and tables needed by Kamailio. You will be prompted to put in the MySQL root password that you created in the Install MySQL section of this document. You will be asked if you want to install different tables – just say “yes” to all the questions.

Code:
/usr/sbin/kamdbctl create

2) Below are all the prompts you will be presented:

MySQL password for root: (enter leads)

Install presence related tables? (y/n): y

Install tables for imc cpl siptrace domainpolicy carrierroute userblacklist htable purple uac pipelimit mtree sca mohqueue rtpproxy?
(y/n): y

Install tables for uid_auth_db uid_avp_db uid_domain uid_gflags uid_uri_db? (y/n): y



Enable the mysql and auth modules:

1) Code:
vim /etc/kamailio/kamailio.cfg

2) Add the following to the beginning of the /etc/kamailio/kamailio.cfg after #!KAMAILIO

(Press "i" to edit the file.)

Code:
#!define WITH_MYSQL
#!define WITH_AUTH

Then press ESC then type ":wq" and enter.



Start the Kamailio Server:

Code:
systemctl start kamailio

Note:
The startup options for Kamailio is located at /etc/default/kamailio

Code:
systemctl status kamailio

Note:
Ignore ALERT: <core> [main.c:740]

Code:
kamctl ul show

Note:
Ignore the 3 ERRRORS.

Solution - code:
vim /etc/kamailio/kamailio.cfg

press "i"

Find and uncomment code to appear like this:
modparam("mi_fifo", "fifo_name", "/var/run/kamailio/kamailio_fifo")

Change to:
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")

Then press ESC then type ":wq" and enter.

Code:
vi /etc/kamailio/kamctlrc

press "i"

Find and uncomment code to appear like this:
FIFOPATH="/var/run/kamailio/kamailio_fifo"

Change to:
FIFOPATH="/tmp/kamailio_fifo"

Then press ESC then type ":wq" and enter.

Note:
Ignore ERRORS and proceed to the next code.

Code:
systemctl stop kamailio

Code:
systemctl start kamailio

Code:
kamctl ul show

Show databases:

Code:
mysql -u root -p

Enter password: (enter leads)

Code:
show databases;

Code:
use kamailio;

Code:
show tables;


Check the subscriber database:

Code:
select * from subscriber;

Code:
exit



Create SIP User Accounts (users 1001 and 1002):

Code:
kamctl add 1001@domain.com 1234

Code:
kamctl add 1002@domain.com 1234

Code:
kamctl db show subscriber



Test Kamailio:

In order to test that Kamailio is working correctly, create a SIP user account and register that account using a softphone such as X-Lite, Linphone, or Zoiper.

Download Zoiper and X-Lite (MAC / Windows).

Code:
ifconfig

Note:
Take note of your inet domain.
i.e.
192.168.1.180

Code:
systemctl stop firewalld

Code:
systemctl status firewalld

-----

Go to Xlite > Account Setting:

Account name: (enter 1001)

User ID: (1001)

Domain: (192.000.1.180)

Password: (1234)

Click OK.

-----

Go to Zoiper:

User: (1002@domain.com)

Pass: (1234)

Domain: (192.000.1.180)

-----

Then try to call either 1001 or 1002.

Ringing indicates a successful setup.

Comments