Add Kamailio GPG Key
wget -O- https://deb.kamailio.org/kamailiodebkey.gpg | sudo apt-key add -
Add Kamailio 5.2 repo
Add the following lines to the file
deb http://deb.kamailio.org/kamailio52 stretch mainUpdate the apt package manager so that it’s aware of the new repository.
deb-src http://deb.kamailio.org/kamailio52 stretch main
You can look at the kamailio packages in the apt repository by typing:
apt search kam
apt install kamailio kamailio-mysql-module
Set Kamailio to Start at Boot
systemctl enable kamailio
Install MariaDBWe will use MariaDB for the Kamailio database engine. Note, Kamailio has support for a number of database backends. But, we are going to use MariaDB
apt install mysql-server
Set MySQL to Start at Boot
systemctl enable mariadb
systemctl start mariadb
Configure Kamailio to use MariaDBBy default, Kamailio does not use MySQL. To change this we need to edit one of Kamailio’s configuration files.
Uncomment the DBENGINE parameter by removing the pound symbol and make sure the value equals MYSQL. The parameter should look like this afterwards:
Uncomment and setup the Database Read/Write and Database Read/Only fields. You can just use the default values for right now and you can change them at a later time.
## 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"
Create the Kamailio Database SchemaThe 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.
Below are all the prompts you will be presented:
MySQL password for root: '' 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 The following MySQL users and passwords are created (please change these in a production environment). kamailio - (With default password 'kamailiorw') - user which has full access rights to 'kamailio' database. kamailioro - (with default password 'kamailioro') - user which has read-only access rights to 'kamailio' database.
Enable MariaDB module and auth modules in the Kamailio Configuration
Add the following after #!KAMAILIO
Update the DBURL line to match the username and password you set in /etc/kamailio/kamctlrc earlier The line looks like this by default:
#!define WITH_MYSQL #!define WITH_AUTH
If you changed the username and password then the new user name and password would look like this
#!define DBURL "mysql://kamailio:kamailioro@localhost/kamailio
The new_username and new_password fields would be replaced with the values you entered in the /etc/kamailio/kamctlrc file.
#!define DBURL "mysql://new_username:new_password@localhost/kamailio
Start the Kamailio Server
Note, the startup options for Kamailio is located at /etc/default/kamailio
service start kamailio
Test KamailioIn order to test that Kamailio is working correctly, I’m going to create a SIP user account and register that account using a softphone such as X-Lite, Linphone, or Zoiper
Create SIP User AccountsThe following command will create a new SIP User. Note, that the domain portion has to be specified unless you export the SIP_DOMAIN environment variable:
Here is what I created:
kamctl add extension@domain extension password
kamctl add email@example.com opensourceisneat
Registering a SIP SoftphoneConfigure whichever softphone you choose with the following options: User ID: 1001
Password: opensourceisneat Once you are registered, you can view all the registered extensions in kamailio with the following command:
You will get something like this:
kamctl ul show
Domain:: location table=1024 records=1 max_slot=1 AOR:: 1001 Contact:: sip:firstname.lastname@example.org:40587; rinstance=636c6f6dedce9a2b;transport=UDP Q= Expires:: 3559 Callid:: OWNlYzg2YThmMmI1MGM1YjMyZTk3NjU2ZTdhMWFlN2E. Cseq:: 2 User-agent:: Z 3.3.21937 r21903 State:: CS_NEW Flags:: 0 Cflag:: 0 Socket:: udp:22.214.171.124:5060 Methods:: 5087 Ruid:: uloc-5a2f0176-36a3-1 Reg-Id:: 0 Last-Keepalive:: 1513030025 Last-Modified:: 1513030025