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. This can be solved by installing Kamailio from source files.
This guide will cover step by step installation of Kamailio Proxy server from source.

Prerequisites
Install mysql server for Centos 7 and set the password(Don’t forget this password). I will install MariaDB instead.
You can install MariaDB server using command below:

[[email protected] ~]# yum -y install mariadb-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.44-2.el7.centos will be installed
--> Processing Dependency: mariadb(x86-64) = 1:5.5.44-2.el7.centos for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(vars) for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
--> Processing Dependency: perl(strict) for package: 1:mariadb-server-5.5.44-2.el7.centos.x86_64
.................................................................................................
Dependencies Resolved

Configure Mysql/MariaDB

sed -i "/[mysqld]$/a innodb_file_per_table" /etc/my.cnf
sed -i "/[mysqld]$/a init-connect = 'SET NAMES utf8'" /etc/my.cnf
sed -i "/[mysqld]$/a collation-server = utf8_general_ci" /etc/my.cnf
sed -i "/[mysqld]$/a default-storage-engine = innodb" /etc/my.cnf
Start and enable Mysql to run on boot up
[[email protected] ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[[email protected] ~]# systemctl start mariadb

Set MariDB root password for logging in:

[[email protected] ~]# mysql_secure_installation

/bin/mysql_secure_installation: line 379: find_mysql_client: command not found 

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

Cleaning up... 

All done! If you've completed all of the above steps, your MariaDB

installation should now be secure. 

Thanks for using MariaDB!

If SELinux is not of use to you, you may consider disabling it:

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

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

[[email protected] ~]# find / -name "kamai*" -print0 | xargs -0 /bin/rm -rf

Then

[[email protected] ~]# mysql -u root -p

Enter the password you set before, then:

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:

[[email protected] ~]# yum install bison pcre-devel libpcap-devel flex git

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

  1. Switch to root user
[[email protected] ~]# su -
  1. Change directory to /usr/src/
[[email protected] ~]# cd /usr/src/
[[email protected] ~]# git clone git://git.sip-router.org/kamailio kamailio
[[email protected] ~]# cd kamailio/
  1. Install epel repo to install required packages before installation.
[[email protected] src]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Preparing... ################################# [100%]
package epel-release-7-5.noarch is already installed
[[email protected] src]#
  1. Install following packages:
[[email protected] src]# yum install libevent* 
[[email protected] src]# yum install json-* 
[[email protected] src]# yum install libunistring-devel.x86_64 
[[email protected] src]# yum install webkitgtk3-devel.x86_64 
[[email protected] src]# yum install perl* 
[[email protected] src]# yum install librabbitmq* 
[[email protected] src]# yum install postgresql*
  1. Enable modules not compiled by default when installing Kamailio, these are the ones I compiled with:
[[email protected] kamailio-master]# make include_modules="db_mysql db_postgres 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:

target architecture <x86_64>, host architecture <x86_64>
making config...
rm -f modules.lst
make --no-print-directory modules.lst
saving modules list...
[[email protected] kamailio-master]#
  1. Compile Kamailio
[[email protected] kamailio-master]# make all
  1. Install Kamailio
[[email protected] kamailio-master]# make install

All binaries and executable scripts associated with kamailio are installed in

/usr/local/sbin directory
[[email protected]]# ls /usr/local/sbin/kam*

-rwxr-xr-x 1 root root 6107979 Mar 21 23:58 /usr/local/sbin/kamailio
-rwxr-xr-x 1 root root 60732 Mar 21 23:58 /usr/local/sbin/kamcmd
-rwxr-xr-x 1 root root 58868 Mar 21 23:58 /usr/local/sbin/kamctl
-rwxr-xr-x 1 root root 10930 Mar 21 23:58 /usr/local/sbin/kamdbctl
-rw-r--r-- 1 root root 18164 Mar 21 22:40 /usr/local/sbin/kamdbctl.base
-rw-r--r-- 1 root root 13699 Mar 21 22:43 /usr/local/sbin/kamdbctl.mysql
[[email protected] kamailio-git]# 

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/

[[email protected] ~]# ls /usr/local/lib64/kamailio/modules/ 
 total 31180 
 -rwxr-xr-x 1 root root 360769 Mar 21 02:57 acc.so 
 -rwxr-xr-x 1 root root 74003 Mar 21 02:57 alias_db.so 
 -rwxr-xr-x 1 root root 300336 Mar 21 02:57 app_perl.so 
 -rwxr-xr-x 1 root root 107489 Mar 21 02:57 async.so 
 -rwxr-xr-x 1 root root 144271 Mar 21 02:57 auth_db.so 
 -rwxr-xr-x 1 root root 250591 Mar 21 02:57 auth_diameter.so 
 -rwxr-xr-x 1 root root 273151 Mar 21 02:57 auth.so 
 -rwxr-xr-x 1 root root 101679 Mar 21 02:57 auth_xkeys.so 
 -rwxr-xr-x 1 root root 404087 Mar 21 02:57 avpops.so 
 -rwxr-xr-x 1 root root 177385 Mar 21 02:57 avp.so 
 -rwxr-xr-x 1 root root 58787 Mar 21 02:57 benchmark.so 
 -rwxr-xr-x 1 root root 40193 Mar 21 02:57 blst.so 
 -rwxr-xr-x 1 root root 131230 Mar 21 02:57 call_control.so 
 -rwxr-xr-x 1 root root 74108 Mar 21 02:57 cfg_db.so 
 -rwxr-xr-x 1 root root 45412 Mar 21 02:57 cfg_rpc.so 
 -rwxr-xr-x 1 root root 227208 Mar 21 02:57 cfgt.so 
 -rwxr-xr-x 1 root root 114928 Mar 21 02:57 cfgutils.so 
 -rwxr-xr-x 1 root root 165348 Mar 21 02:57 corex.so 
 -rwxr-xr-x 1 root root 45704 Mar 21 02:57 counters.so 
 -rwxr-xr-x 1 root root 431232 Mar 21 02:57 ctl.so 
 -rwxr-xr-x 1 root root 154837 Mar 21 02:57 db2_ops.so 
 -rwxr-xr-x 1 root root 231271 Mar 21 02:57 db_cluster.so 
 -rwxr-xr-x 1 root root 178048 Mar 21 02:57 db_flatstore.so 
 -rwxr-xr-x 1 root root 365310 Mar 21 02:57 db_mysql.so 
 -rwxr-xr-x 1 root root 305656 Mar 21 02:57 db_text.so 
 -rwxr-xr-x 1 root root 261719 Mar 21 02:57 debugger.so 
 -rwxr-xr-x 1 root root 962503 Mar 21 02:57 dialog.so 
 -rwxr-xr-x 1 root root 288178 Mar 21 02:57 dialplan.so 
 -rwxr-xr-x 1 root root 430058 Mar 21 02:57 dispatcher.so 
 -rwxr-xr-x 1 root root 37240 Mar 21 02:57 diversion.so 
 -rwxr-xr-x 1 root root 391882 Mar 21 02:57 dmq.so 
 -rwxr-xr-x 1 root root 134805 Mar 21 02:57 dmq_usrloc.so 
 -rwxr-xr-x 1 root root 202129 Mar 21 02:57 domainpolicy.so 
 -rwxr-xr-x 1 root root 159914 Mar 21 02:57 domain.so 
 -rwxr-xr-x 1 root root 333955 Mar 21 02:57 drouting.so 
 -rwxr-xr-x 1 root root 132634 Mar 21 02:57 enum.so 
 -rwxr-xr-x 1 root root 152707 Mar 21 02:57 exec.so 
 -rwxr-xr-x 1 root root 115480 Mar 21 02:57 group.so 
 -rwxr-xr-x 1 root root 417230 Mar 21 02:57 htable.so 
 -rwxr-xr-x 1 root root 295208 Mar 21 02:57 imc.so 
 -rwxr-xr-x 1 root root 255221 Mar 21 02:57 ipops.so 
 -rwxr-xr-x 1 root root 202288 Mar 21 02:57 jsonrpc-s.so 
 -rwxr-xr-x 1 root root 651064 Mar 21 02:57 kazoo.so 
 -rwxr-xr-x 1 root root 178880 Mar 21 02:57 kex.so 
 -rwxr-xr-x 1 root root 39729 Mar 21 02:57 log_custom.so 
 -rwxr-xr-x 1 root root 64051 Mar 21 02:57 malloc_test.so 
 -rwxr-xr-x 1 root root 172426 Mar 21 02:57 mangler.so 
 -rwxr-xr-x 1 root root 94707 Mar 21 02:57 matrix.so 
 -rwxr-xr-x 1 root root 61354 Mar 21 02:57 maxfwd.so 
 -rwxr-xr-x 1 root root 201082 Mar 21 02:57 mediaproxy.so 
 -rwxr-xr-x 1 root root 231435 Mar 21 02:57 mi_datagram.so 
 -rwxr-xr-x 1 root root 177997 Mar 21 02:57 mi_fifo.so 
 -rwxr-xr-x 1 root root 57966 Mar 21 02:57 mi_rpc.so 
 -rwxr-xr-x 1 root root 388247 Mar 21 02:57 mohqueue.so 
 -rwxr-xr-x 1 root root 100079 Mar 21 02:57 mqueue.so 
 -rwxr-xr-x 1 root root 266045 Mar 21 02:57 msilo.so 
 -rwxr-xr-x 1 root root 289080 Mar 21 02:57 msrp.so 
 -rwxr-xr-x 1 root root 247832 Mar 21 02:57 mtree.so 
 -rwxr-xr-x 1 root root 293165 Mar 21 02:57 nathelper.so 
 -rwxr-xr-x 1 root root 191313 Mar 21 02:57 nat_traversal.so 
 -rwxr-xr-x 1 root root 40559 Mar 21 02:57 nosip.so 
 -rwxr-xr-x 1 root root 88447 Mar 21 02:57 outbound.so 
 -rwxr-xr-x 1 root root 70653 Mar 21 02:57 path.so 
 -rwxr-xr-x 1 root root 97764 Mar 21 02:57 pdb.so 
 -rwxr-xr-x 1 root root 167937 Mar 21 02:57 pdt.so 
 -rwxr-xr-x 1 root root 409038 Mar 21 02:57 permissions.so 
 -rwxr-xr-x 1 root root 152010 Mar 21 02:57 pike.so 
 -rwxr-xr-x 1 root root 181115 Mar 21 02:57 pipelimit.so 
 -rwxr-xr-x 1 root root 90392 Mar 21 02:57 prefix_route.so 
 -rwxr-xr-x 1 root root 150515 Mar 21 02:57 presence_dialoginfo.so 
 -rwxr-xr-x 1 root root 58405 Mar 21 02:57 presence_mwi.so 
 -rwxr-xr-x 1 root root 1178764 Mar 21 02:57 presence.so 
 -rwxr-xr-x 1 root root 345846 Mar 21 02:57 presence_xml.so 
 -rwxr-xr-x 1 root root 24186 Mar 21 02:57 print_lib.so 
 -rwxr-xr-x 1 root root 43924 Mar 21 02:57 print.so 
 -rwxr-xr-x 1 root root 726258 Mar 21 02:57 p_usrloc.so 
 -rwxr-xr-x 1 root root 890404 Mar 21 02:57 pv.so 
 -rwxr-xr-x 1 root root 206004 Mar 21 02:57 qos.so 
 -rwxr-xr-x 1 root root 141957 Mar 21 02:57 ratelimit.so 
 -rwxr-xr-x 1 root root 462087 Mar 21 02:57 registrar.so 
 -rwxr-xr-x 1 root root 286444 Mar 21 02:57 rr.so 
 -rwxr-xr-x 1 root root 51967 Mar 21 02:57 rtimer.so 
 -rwxr-xr-x 1 root root 116717 Mar 21 02:57 rtjson.so 
 -rwxr-xr-x 1 root root 451487 Mar 21 02:57 rtpengine.so 
 -rwxr-xr-x 1 root root 353613 Mar 21 02:57 rtpproxy.so 
 -rwxr-xr-x 1 root root 152772 Mar 21 02:57 sanity.so 
 -rwxr-xr-x 1 root root 893493 Mar 21 02:57 sca.so 
 -rwxr-xr-x 1 root root 206268 Mar 21 02:57 sdpops.so 
 -rwxr-xr-x 1 root root 768699 Mar 21 02:57 seas.so 
 -rwxr-xr-x 1 root root 316866 Mar 21 02:57 sipcapture.so 
 -rwxr-xr-x 1 root root 258124 Mar 21 02:57 siptrace.so 
 -rwxr-xr-x 1 root root 107851 Mar 21 02:57 sipt.so 
 -rwxr-xr-x 1 root root 386956 Mar 21 02:57 siputils.so 
 -rwxr-xr-x 1 root root 185067 Mar 21 02:57 sl.so 
 -rwxr-xr-x 1 root root 104602 Mar 21 02:57 smsops.so 
 -rwxr-xr-x 1 root root 333833 Mar 21 02:57 sms.so 
 -rwxr-xr-x 1 root root 74093 Mar 21 02:57 speeddial.so 
 -rwxr-xr-x 1 root root 193204 Mar 21 02:57 sqlops.so 
 -rwxr-xr-x 1 root root 141004 Mar 21 02:57 sst.so 
 -rwxr-xr-x 1 root root 60818 Mar 21 02:57 statistics.so 
 -rwxr-xr-x 1 root root 55789 Mar 21 02:57 statsc.so 
 -rwxr-xr-x 1 root root 135737 Mar 21 02:57 statsd.so 
 -rwxr-xr-x 1 root root 86706 Mar 21 02:57 stun.so 
 -rwxr-xr-x 1 root root 114104 Mar 21 02:57 tcpops.so 
 -rwxr-xr-x 1 root root 367046 Mar 21 02:57 textops.so 
 -rwxr-xr-x 1 root root 142981 Mar 21 02:57 textopsx.so 
 -rwxr-xr-x 1 root root 61468 Mar 21 02:57 timer.so 
 -rwxr-xr-x 1 root root 889065 Mar 21 02:57 tls.so 
 -rwxr-xr-x 1 root root 53313 Mar 21 02:57 tmrec.so 
 -rwxr-xr-x 1 root root 1790729 Mar 21 02:57 tm.so 
 -rwxr-xr-x 1 root root 266523 Mar 21 02:57 tmx.so 
 -rwxr-xr-x 1 root root 201782 Mar 21 02:57 topoh.so 
 -rwxr-xr-x 1 root root 238731 Mar 21 02:57 topos.so 
 -rwxr-xr-x 1 root root 222580 Mar 21 02:57 tsilo.so 
 -rwxr-xr-x 1 root root 124814 Mar 21 02:57 uac_redirect.so 
 -rwxr-xr-x 1 root root 570919 Mar 21 02:57 uac.so 
 -rwxr-xr-x 1 root root 115442 Mar 21 02:57 uid_auth_db.so 
 -rwxr-xr-x 1 root root 111639 Mar 21 02:57 uid_avp_db.so 
 -rwxr-xr-x 1 root root 120776 Mar 21 02:57 uid_domain.so 
 -rwxr-xr-x 1 root root 67301 Mar 21 02:57 uid_gflags.so 
 -rwxr-xr-x 1 root root 70301 Mar 21 02:57 uid_uri_db.so 
 -rwxr-xr-x 1 root root 86624 Mar 21 02:57 uri_db.so 
 -rwxr-xr-x 1 root root 165571 Mar 21 02:57 userblacklist.so 
 -rwxr-xr-x 1 root root 496254 Mar 21 02:57 usrloc.so 
 -rwxr-xr-x 1 root root 32024 Mar 21 02:57 uuid.so 
 -rwxr-xr-x 1 root root 300801 Mar 21 02:57 websocket.so 
 -rwxr-xr-x 1 root root 132876 Mar 21 02:57 xhttp_rpc.so 
 -rwxr-xr-x 1 root root 107349 Mar 21 02:57 xhttp.so 
 -rwxr-xr-x 1 root root 93588 Mar 21 02:57 xlog.so 
 -rwxr-xr-x 1 root root 192366 Mar 21 02:57 xprint.so 
  1. Open Kamailio configuration file
[[email protected] ~]# vi /usr/local/etc/kamailio/kamailio.cfg 

Add the following lines just after #!KAMAILIO line.

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

Should look something like:

 #!KAMAILIO 
 #!define WITH_MYSQL 
 #!define WITH_TLS 
 #!define WITH_AUTH 
 #!define WITH_USRLOCDB 
 #!define WITH_NAT 
 #!define WITH_PRESENCE 
 #!define WITH_ACCDB 
 #!define WITH_VOICEMAIL 
 #!define WITH_PSTN 
 # 
 # Kamailio (OpenSER) SIP Server v4.4 - default configuration script 
 # - web: http://www.kamailio.org
 # - git: http://sip-router.org
 # 
 # Direct your questions about this file to: <[email protected]> 
 # 
 # Refer to the Core CookBook at http://www.kamailio.org/wiki/
 # for an explanation of possible statements, functions and parameters. 
  1. Create default kamailio file in /etc/default/ directory.
cat > /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 
  1. Create pid file directory
[[email protected]]# mkdir -p /var/run/kamailio 
[[email protected]]# chown kamailio:kamailio -R /var/run/kamailio

 

  1. Add Kamailio user and group
[[email protected] ]# groupadd -g 5000 kamailio 
[[email protected] ]# useradd -u 5000 -g 5000 -d /var/run/kamailio -M -s /bin/false kamailio 
[[email protected]]# chown kamailio:kamailio -R /var/run/kamailio/ 
  1. Create Kamailio Systemd file for starting and stopping kamailio service.
cat >/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 
  1. Edit the file kamctlrc to set the database engine
nano /usr/local/etc/kamailio/kamctlrc 

DBENGINE =MYSQL # uncomment this line
12. Create the database used by kamailio

 [[email protected]# /usr/local/sbin/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
 userblacklist htable purple uac pipelimit mtree sca mohqueue
rtpproxy? (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. 

And you are done installing Kamailio SIP proxy service. Start it by:
Reloading the daemons and check status

 [[email protected]# systemctl reload.daemon 
 [[email protected]# systemctl start kamailio 
 [[email protected]# systemctl enable kamailio

If you Love what we do, support us by downloading this tutorial as pdf from the link below:

Other Kamailio and Voip Tutorials available are:

How to install Asterisk PBX 13.x on CentOS 7 step by step guide

Complete guide on how to Install Openfire XMPP chat server on Centos 7