FreeBSD / OpenSIPS with PostgreSQL

FreeBSD / OpenSIPS with PostgreSQL

The following notes provide some tips for installing the OpenSIPS Sip Router with PostgreSQL on FreeBSD.

This is hard... getting OpenSIPS sip proxy up and running on FreeBSD with PostgreSQL database.

Status: This is copied from historical posting: "OpenSIPS with PostgreSQL on FreeBSD".


Why OpenSIPS on FreeBSD ...

So why put OpenSIP on FreeBSD?

I will not argue for merits of the various *nix flavous, but I have been using FreeBSD since version 2.0.5 in 1995, when it was distributed via Walnut Creek CD, so it is the easiset of the various *nix flavors for me plus:

I will not argue for merits of the various *nix flavous, but I have been using FreeBSD since version around 1995, when it was distributed via Walnut Creek CD, so it is the easiset of the various *nix flavors for me plus:

  • There is a single central distribution, which makes it easier to get documentation and guideance
  • I am now pretty comfortable and famillar with its installation and configuration
  • In looking at the various SIP proxy options, I found that OpenSIPS has best documentation and it has a B2BUA module, which I need to allow me to configure my SIP proxy with Cisco UME & Cisco ATA for PSTN support
  • I also use PostgreSQL as my database as it is generally regarded as the most robust (if not the most popular) of the Open Source databases
  • Finally FreeBSD has a cool Daemon logo and PostgreSQL has a elephant logo ;-)

The disadvantage of these selections is that much of the available documentation assumes a combination of Linux & MySQL, hence my collection of notes to help others who want to use OpenSIPS on FreeBSD and PostgreSQL.


The Build Process

To build a full OpenSIP installation, including all the modules (with one exception....) and additional adminstration tools requires that you prepare a number of dependent modules.

The following are the headline items that we will be building (using FreeBSD Ports libraries):

  1. Apache (Ver. 2.4) - Web Server required for PHP Database Admin Tooling
  2. PostgreSQL (Ver. 9.2) - Database Server
  3. PHP (Ver. ) - PHP Web Scripting language used to host PG Admin
  4. PHP PGAdmin (Ver. x) - Useful PostgreSQL database adminstration tool to help administer the OpenSIPS database
  5. OpenSIPS Control Panel (Vers. X) - PHP based OpenSIPS user adminstration panel
  6. OpenSIPS (Ver. 10.1.0) - SIP Proxy
  7. Additional Libraries required by various OpenSIPS modules - lots of these...

Now follow instructions and links to help you with your installation.

1

Install PostgreSQL, Apache (with multi-thread Perl library) & SSL by following the instructions here

Start by building the SSL library and selecting the multi-threaded option, this will ensure that thread support is propogated across, the various Perl,Apache, PostgreSQL and PHP builds.

NOTE 1: When building the Apache Runtime Library I selected support for Berkeley DB (needed later by OpenSIPS), Threads & PostgreSQL. There is no need for other DB support.

NOTE 2: When building Apache 2.4 I removed the dbm authenticaion support as there is no need for this, but included DBD (which uses the APR build before Apache).

The Ports locations are:

  • OpenSSL - /usr/ports/security/openssl
  • PostgreSQL - /usr/ports/databases/postgresql9.2-server
  • Berkeley DB (4.8) - /usr/ports/db48
  • Apache Portable Runtime - /user/ports/devel/apr1
  • Apache (2.4) - /usr/ports/web/apache24
2

Build the libraries needed for a full build of OpenSIPS Proxy.

The modules required are:

  • Perl 5 DBI for PostgreSQL - /usr/ports/databases/p5-DBD-Pg
  • XMLRPC Library - /usr/ports/net/xmlrpc-c-devel
  • OpenLDAP Client - /usr/ports/net/openldap24-sasl-client
  • Radius Client (NG) - /usr/ports/net/radiusclient
  • M4 (Macro processor) - should have already been install from Apache build (Step 1)
  • ncurses library - /usr/ports/devel/ncurses
  • libconfuse - /usr/ports/devel/libconfuse
  • Perl Compatible Regular Expresssions - should have already been installed from Apache Build (Step 1)
  • Micro HTTP Library - /usr/ports/www/libmicrohttp
  • libmemcached - /usr/ports/databases/libmemcached
  • Rabbit MQ - /usr/ports/net/rabbit-c-devel
  • GeoIP - /usr/ports/net/GeoIP
  • redis-devel - /usr/ports/databases/redis-devel
  • hiredis - /usr/ports/databases/hiredis
  • Json Library - /usr/ports/devel/json-c
  • Pear (PHP) MDB2 PostgreSQL support (for OpenSIPS Control Panel) = /usr/local

The following additional programs are also required to setup up robust SIP proxy solution:

  • Monit -/usr/ports/sysutil/monit
  • RTP Proxy - /usr/ports/net/rtpproxy
  • phpPGAdmin - /usr/ports/database/phppgadmin

 

3

Get OpenSIPS source code via GIT, svn or as a tarball.

I used version current stable release version: 1.10.0

I wanted to build all modules (with exception of the database specific ones).

Easiest way to build the system is to edit: Makefile and Make.conf

To build with TLS support edit Makefile and uncomment out the line:

TLS=1

Based on the libraries included in step 2 above, you can build everything but edit Make.def to exclude the following:

exclude_modules ?= cachedb_couchbase cachedb_cassandra cachedb_mongodb cachedb_redis db_berkeley db_http db_mysql db_perlvdb db_unixodbc lua osp snmpstats sngtc

The OSP module can be included if you build the "OSP Toolkit" (OSP - Open Settlement Protocol). I have not managed to get this built (and do not need it so have excluded it).

The other exclusion worthmentioning is sngtc (Sangoma Voice Transcoding Module), which requires special hardware and was introduced with version 1.10 of OpenSIPS Proxy.

You need to use gmake (GNU Make) build tool and as per FreeBSD convention do build to install in /usr/local.

# gmake prefix=/usr/local LD_EXTRA_OPTS="-L /usr/local/lib" all

# game prefix=/usr/local install

 

4

Configure the various services:

1. Edit /etc/rc.conf to start the various daemon on bootup

postgresql_enable="YES"

rtpproxy_enable="YES"

rtpproxy_flags="-F -p /var/run/rtpproxy.pid -l <your-ip-address> -s udp:127.0.0.1:7899"

apache24_enable="YES"

opensips_enable="YES"

opensips_flags="-P /var/run/opensips.pid"

monit_enable="YES"

2. Initiatlise the PostgreSQL database

# su pgsql

# initdb -D /usr/local/pgsql/data

# /usr/local/etc/rc.d/postgresql start

# psql postgres

create role pgsuper with createdb createrole createuser password 'XXXXXX';

create role pgopensips with createdb password 'XXXXXX';

\q

# exit

3. Create the OpenSIPS DB tables

a. Edit opensipsctrc & osipconsolerc to have correct domain and point to the PostgreSQL database (files are in /usr/local/etc/opensips and change DBENGINE=PGSQL and other DBxxx config variables).

b. Run the opensips db control to create the database tables.

# /usr/local/sbin/opensipsdbctl create

c. Change the table, sequence & view owner to pgopensips (in the case where you did not use pgopensips as the creating user within the prior configuration)

# su pgsql

# for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" opensips` ; do psql -c "alter table $tbl owner to pgopensips" opensips ; done

# for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" opensips` ; do psql -c "alter table $tbl owner to pgopensips" opensips ; done

# psql postgres

alter database opensips owner to pgopensips;

\q

# exit

NOTE 1: The ownership altering script is from here (with thanks).

[4. Optionally update the missed_calls (this is to maintain capability with the opensips.cfg routing script that is part of the OpenSIPS Live VM (with thanks), which is a good way to start with a working basis routing configuration).

I do this via phpPgAdmin (installed earlier) but the same can be achived via SQL commands:

alter table missed_calls add column caller_id character varying(64) constraint default null;

alter table missed_calls add column callee_id character varying(64) constrain default null;

5. Set up the monit script

Here is my sample which is based the script from the Live VM (with thanks)

6. Setup the opensips.cfg routing script.

Here is my sample, which is based on the script from the Live VM (with thanks)

7. Add opensips start script into /usr/local/etc/rd.d

Here is my simple and minimal opensips script to start/stop opensips proxy running

5

Install OpenSIPS Control Panel with PostgreSQL support (see here for basic installation steps).

1. Create the admin tables within the opensips database

2. Add admin account

3. Create the CDR Viewer record, but edit the cdrs.pgsql script to change DEFAULT from: '0000:00:00 00:00:00' to '-infinity'.

4. Update /etc/crontab to add the cron jobs

5. Add the monitoring tables (config/tool/system/smonitor/tables.pgsql)

6. Edit the config files..: (config/db.inc.php)

7. Link the opensips control panel /web directory to www/apache34/data/cp

8. Fix nathelper table configuration to point to rtpproxy_sockets

9. Fix fifo socket identifer config for dialog. dispatcher

10.If you want to use the permissions & siptrace tools then you also need to ensure you have loaded the "permissions.so" and "siptrace.so" modules within the opensips.cfg file

6

Testing the configuration

1. Test that OpenSIPS Control Panel is working and add the domains via the system functions.

2. Add Users via OpenSIPS Control panel

3. Add DialPlan via OpenSIPS Control panel. Note that you must have at least a local call dial plan at minimum to get calls to work.

The OpenSIPS Control panel needs to be changed to allow correct dial plan editing. It is simpler to just use phpPgAdmin and directly edit the dialplan tables within the opensips database. The "attrs" column is where you set the selection of the routing:

'userloc' -- means call is assumed to be internally destined

'pstn' -- direct call to external gateway


References & Link: