We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install Kamailio SIP Proxy Server From Source on CentOS 7

Learn how to – Install Kamailio SIP Proxy Server From Source on CentOS 7.

Welcome to our guide on how to install Kamailio SIP Proxy Server From Source on CentOS 7 server. I had earlier written a tutorial on How to install Kamailio in CentOS 7 from repo. The link to the article is below:

How to Install Latest Kamailio SIP Server on CentOS 7

Disadvantage of installing using repo is that you won’t always get latest version of Kamailio SIP server. If you want to get the latest release of Kamailio on your server, consider building Kamailio SIP Server from source files.

Setup Pre-requisites

  • Running CentOS 7 server
  • MariaDB Database Server

Ensure the server is update:

sudo yum -y update
sudo reboot

Then Install MariaDB Database server.

sudo yum install mariadb-server

Now start and enable MariaDB database service and enable it to run on boot up:

sudo systemctl enable --now mariadb

Set MariaDB root password for logging in:

sudo  mysql_secure_installation

It will ask you to set root password and disable remote root login:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Install Kamailio SIP Proxy Server From Source In CentOS 7

If SELinux is not of use to you, you may consider putting it Permissive mode:

sudo sed -i 's/(^SELINUX=).*/SELINUX=permissive/' /etc/selinux/config

If you had a prior installation of Kamailio especially from the repository, do a complete wipe off:

sudo su -
find / -name "kamai*" -print0 | xargs -0 /bin/rm -rf

Then drop old database:

$ mysql -u root -p
MariaDB [(none)]> SHOW DATABASES;
If there's a database called kamailio,drop it: 
MariaDB [(none)]> DROP DATABASE kamailio; 
MariaDB [(none)]> EXIT

Install the following required dependencies:

sudo yum -y install epel-release
sudo yum groupinstall "Development Tools"
sudo yum install bison pcre-devel libpcap-devel flex git libevent json* libunistring-devel  webkitgtk3-devel perl librabbitmq mariadb-devel libevent-devel librabbitmq-devel perl-devel mod_perl-devel perl-Encode-devel perl-Qt-devel perl-Glib-devel perl-Tk-devel

Download the latest version of Kamailio from github and install it.

sudo su -
cd /usr/src/
git clone git://git.sip-router.org/kamailio kamailio
cd kamailio/

Enable modules not compiled by default when installing Kamailio, these are the ones I compiled with:

sudo make include_modules="db_mysql dialplan websocket debugger permissions usrloc dispatcher registrar uuid sdpops presence auth auth_db avp tm presence_mwi outbound sl maxfwd nat xhttp helper kazoo db_text textops siputils uac presence_dialoginfo kex uac_redirect xlog sanity htable rr pv app_perl path ctrl tls ctl mi_fifo dmq dialog avpops textopsx tmx presence_xml" cfg

Output:

make -C src/ cfg 
target architecture <x86_64>, host architecture <x86_64>
make[1]: Entering directory `/usr/src/kamailio/src'
making config...
rm -f modules.lst
make --no-print-directory modules.lst
saving modules list...
make[1]: Leaving directory `/usr/src/kamailio/src'

Compile Kamailio:

sudo make all

Install Kamailio:

sudo make install

All binaries and executable scripts associated with kamailio are installed in:

$ ls /usr/local/sbin/kam*

Explanation of each:

  • kamdbctl – Database command line control and management utility.
  • kamailio – Kamailio SIP server daemon application.
  • kamctl – Command line utility used to manage Kamailio SIP server
  • kamcmd – A Unix tool for invoking Kamailio RPC functions

Kamailio modules installed are located in: /usr/local/lib64/kamailio/modules/

$ ls /usr/local/lib64/kamailio/modules/ 

See my screenshot for all modules.

Open Kamailio configuration file:

sudo vi /usr/local/etc/kamailio/kamailio.cfg 

Add the following lines just after #!KAMAILIO line.

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

Create default kamailio file in /etc/default/ directory.

sudo tee /etc/default/kamailio<<EOF
RUN_KAMAILIO=yes 
USER=kamailio 
GROUP=kamailio 
SHM_MEMORY=64 
PKG_MEMORY=8
PIDFILE=/var/run/kamailio/kamailio.pid
CFGFILE=/usr/local/etc/kamailio/kamailio.cfg
#DUMP_CORE=yes
EOF

Add Kamailio user and group:

sudo groupadd -g 5000 kamailio 
sudo useradd -u 5000 -g 5000 -d /var/run/kamailio -M -s /bin/false kamailio 

Create pid file directory

sudo mkdir -p /var/run/kamailio 
sudo chown kamailio:kamailio -R /var/run/kamailio

Create Kamailio Systemd file for starting and stopping kamailio service.

sudo tee /etc/systemd/system/kamailio.service<<EOF
[Unit]
Description=Kamailio SIP Proxy Server
After=syslog.target network.target mariadb.service

[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
EOF

Edit the file kamctlrc to set the database engine

$ sudo vi /usr/local/etc/kamailio/kamctlrc 
DBENGINE=MYSQL

Create the database used by kamailio:

sudo /usr/local/sbin/kamdbctl create

And you are done installing Kamailio SIP proxy service. Start it by:

sudo systemctl daemon-reload
sudo systemctl start kamailio 
sudo  systemctl enable kamailio

Confirm service status:

$ sudo systemctl status kamailio 
● kamailio.service - Kamailio SIP Proxy Server
   Loaded: loaded (/etc/systemd/system/kamailio.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-05-03 16:31:49 UTC; 10s ago
  Process: 18887 ExecStopPost=/bin/rm -f (code=exited, status=0/SUCCESS)
  Process: 18907 ExecStart=/usr/local/sbin/kamailio -P $PIDFILE -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP (code=exited, status=0/SUCCESS)
 Main PID: 18909 (kamailio)
   CGroup: /system.slice/kamailio.service
           ├─18909 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18913 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18914 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18915 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18916 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18917 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18918 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18919 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18920 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18921 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18922 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18923 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18924 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
           ├─18925 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai...
....

If you want to use

How to Install RTPProxy from Source in CentOS 7.x

Cart

Your Cart is Empty

Back To Shop