Wednesday, June 17, 2015

How to install and configure Opensips with authentication on Ubuntu-14.10:




Used OS: Ubuntu 14.10 (64 Bit)


Update OS :

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential openssl bison flex
sudo apt-get install mysql-server libmysqlclient-dev

Must know your mysql root password

Download the opensips from http://opensips.org/ site

cd /usr/src
wget http://opensips.org/pub/opensips/1.8.0/src/opensips-1.8.0_src.tar.gz

tar -zxvf opensips-1.8.0_src.tar.gz

cd opensips-1.8.0-tls

Compile the Opensips:
we will compile Opensips with all available modules:

make all include_modules="db_mysql" modules
make install include_modules="db_mysql" modules

Now copy the files from the extracted directory to the followings:

cp /usr/src/opensips-1.8.0-tls/packaging/debian/opensips.default /etc/default/opensips
cp /usr/src/opensips-1.8.0-tls/packaging/debian/opensips.init /etc/init.d/opensips


Modify following changes:

vi /etc/default/opensips

RUN_OPENSIPS=yes
USER=opensips                                //User to run as
GROUP=opensips                            //Group to run as
MEMORY=64                           //128 (Optional)


Modify following file:

vi /etc/init.d/opensips

DAEMON=/usr/local/sbin/opensips
       save and exit

Provide executable permission:
chmod +x /etc/init.d/opensips

Create opensips user:
adduser opensips
Pass: *******

Now create the dir (for PID file):
mkdir /var/run/opensips

Configuring the Opensips:
=========================
Change the file in /usr/local/etc/opensips/opensipsctlrc:
vi /usr/local/etc/opensips/opensipsctlrc

Make the following change:
SIP_DOMAIN=localhost
DBENGINE=MYSQL
DBHOST=localhost
DBNAME=opensips
DBRWUSER=opensips
DBRWPW="opensipsrw" //Database password
DBROUSER=opensipsro
DBROPW=opensipsro
DBROOTUSER="root"
USERCOL="username"
INSTALL_EXTRA_TABLES=ask
INSTALL_PRESENCE_TABLES=ask
INSTALL_SERWEB_TABLES=ask
CTLENGINE="FIFO"
OSIPS_FIFO="/tmp/opensips_fifo"
PID_FILE=/var/run/opensips/opensips.pid


Create database:
opensipsdbctl create
Password: <mysql password>                    //Ask for the root mysql password.

Configuring Mysql support:

Change the opensips.cfg:

vi /usr/local/etc/opensips/opensips.cfg
loadmodule "db_mysql.so"
loadmodule "auth.so"
loadmodule "auth_db.so"
modparam("usrloc", "db_mode", 0); #THIS LINE MUST TO BE COMMENTED
modparam("usrloc", "db_mode", 2)
modparam("usrloc", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")                                                                                                    /*/opensipsrw == <Opensip's DB password>

Add following for auth_db params:
Add or uncomment the following lines if you want to enable the DB based authentication:

modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("auth_db", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
                                                                                    /*/opensipsrw == <Opensip's DB password>

//Add following lines for authentication (opensips.cfg)
243         if (is_method("REGISTER"))
244         {
245         ##### following(in-between ##) lines required for auth/register
246                 if (!www_authorize("", "subscriber")) {
247                   www_challenge("", "0");
248                   exit;
249                 }
250         #####
251
252                 if (   0 ) setflag(7);
253
254                 if (!save("location"))
255                         sl_reply_error();
256
257                 exit;
258         }



Create the opensips/softphone user:
opensipsctl add test1 test
opensipsctl add 123 123 //user pass == 123 123

Create the Opensips user in the Mysql:

mysql> GRANT ALL PRIVILEGES ON *.* TO opensips@localhost IDENTIFIED BY '<opensips/Password>';

GRANT ALL PRIVILEGES ON *.* TO opensips@127.0.0.1 IDENTIFIED BY '<opensips/Password>';


Starting/Run OpenSIPS:

There are two ways:

1. /etc/init.d/opensips start | stop
2. opensipsctl start | stop



========================== Enjoy ===============================

2 comments:

  1. i get error during connecting to db mysql
    please help

    ReplyDelete
  2. May 26 16:52:29 fk /usr/local/sbin/opensips[1114]: ERROR:db_mysql:db_mysql_connect: driver error(2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    May 26 16:52:29 fk /usr/local/sbin/opensips[1114]: ERROR:db_mysql:db_mysql_new_connection: initial connect failed
    May 26 16:52:29 fk /usr/local/sbin/opensips[1114]: ERROR:core:db_do_init: could not add connection to the pool
    May 26 16:52:29 fk /usr/local/sbin/opensips[1114]: ERROR:auth_db:auth_fixup: unable to open database connection


    i test in both debian jessi and ubuntu 14 x64 ,

    - mysql is running
    - i can connect through root and user pass with terminal without any problem

    ReplyDelete