<commit_before>Installation
************

Table of contents
=================

* Introduction
* Prerequisites
* Sip server installation
* SBC installation
* Postgresql configuration
* Web server install
* PyFreeBilling installation
* Next step

Introduction
============

This howto is written for Debian 8 server.
You need 2 interfaces with 2 ip public addresses, one for customers side and the other one for provider side.

Prerequisites
=============

First, you need to install these packages

::

    apt-get install git-core build-essential autoconf automake libtool libtool-bin libncurses5 libncurses5-dev gawk libjpeg-dev zlib1g-dev pkg-config libssl-dev libpq-dev unixodbc-dev odbc-postgresql postgresql postgresql-client libpq-dev libxml2-dev libxslt-dev ntp ntpdate libapache2-mod-wsgi apache2 gcc python-setuptools python-pip libdbd-pg-perl libtext-csv-perl sqlite3 libsqlite3-dev libcurl4-openssl-dev libpcre3-dev libspeex-dev libspeexdsp-dev libldns-dev libedit-dev libmemcached-dev python-psycopg2 python-dev libgeoip-dev libffi-dev
    
Postgresql configuration
========================

* create user and database :

::

    su postgres

::

    createuser -P pyfreebilling --interactive
        Enter password for new role:
        Enter it again:
        Shall the new role be a superuser? (y/n) n
        Shall the new role be allowed to create databases? (y/n) y
        Shall the new role be allowed to create more new roles? (y/n) y

::

    createdb -O pyfreebilling -E UTF8 pyfreebilling
    exit


Sip server installation
=======================

* First, install dependencies, edit sources.list :

::

    nano /etc/apt/sources.list

* Add this lines at the end of the files :

::

    # Kamailio 4.4 Release
    deb http://deb.kamailio.org/kamailio44 jessie main
    deb-src http://deb.kamailio.org/kamailio44 jessie main

* Add the repo GPG key, update the packages list, and install packages :

::

    wget -O- http://deb.kamailio.org/kamailiodebkey.gpg | sudo apt-key add -
    apt-get update
    apt-get install libpq5 libpq-dev
    apt-get install kamailio kamailio-tls-modules kamailio-postgres-modules kamailio-outbound-modules kamailio-extra-modules kamailio-xml-modules


* After finishing the installation, you have to edit  /etc/default/kamailio file:

::

    #
        # Kamailio startup options
        #

        # Set to yes to enable kamailio, once configured properly.
        RUN_KAMAILIO=yes

        # User to run as
        USER=kamailio

        # Group to run as
        GROUP=kamailio

        # Amount of shared and private memory to allocate
        # for the running Kamailio server (in Mb)
        #SHM_MEMORY=64
        #PKG_MEMORY=8

        # Config file
        CFGFILE=/etc/kamailio/kamailio.cfg

        # Enable the server to leave a core file when it crashes.
        # Set this to 'yes' to enable Kamailio to leave a core file when it crashes
        # or 'no' to disable this feature. This option is case sensitive and only
        # accepts 'yes' and 'no' and only in lowercase letters.
        # On some systems it is necessary to specify a directory for the core files
        # to get a dump. Look into the kamailio init file for an example configuration.
        DUMP_CORE=yes

* Configration files are located in /etc/kamailio/ folder.

The /etc/kamailio/kamctlrc is the configuration file for kamctl and kamdbctl tools. You need to edit it and set the SIP_DOMAIN to your SIP service domain (or IP address if you don't have a DNS hostname associated with your SIP service).

Set also the DBENGINE to be PGSQL and adjust other setting as you want. Very important are the passwords to connect to PostgreSSQL server, respectively DBRWPW and DBROPW. By default, their values are kamailiorw and kamailioro. You should change them before executing kamdbctl create (step detailed the section Create Database).

::

    sed "/^[# ]*SIP_DOMAIN/cSIP_DOMAIN=sip.<DOMAIN>.net" -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBENGINE/cDBENGINE=PGSQL' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBHOST/cDBHOST=localhost' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBNAME/cDBNAME=kamailiopyfb' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBRWUSER/cDBRWUSER=kamailio' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBRWPW/cDBRWPW="k<PASSWORD>"' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBROUSER/cDBROUSER=kamailioro' -i /etc/kamailio/kamctlrc
    sed '/^[#]*DBROPW/cDBROPW=kamailioro' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBROOTUSER/cDBROOTUSER="postgres" ' -i /etc/kamailio/kamctlrc


* Create DB :
  Install Kamailio DB with db name kamailiopyfb and drop these tables : usr_preferences, subscriber, address, dbaliases and dialplan.

To create the database structure needed by Kamailio, run:

::

    echo :*:*:pyfreebilling:mypasswd > /root/.pgpass
    # Change **mypasswd** by  kamailiorw db password
    chmod 600 /root/.pgpass
    kamdbctl create

The database name created in PostgreSQL is kamailio. Two access users to PostgreSQL server were created:

* kamailio - (with password set by DBRWPW in kamctlrc) - user which has full access rights to kamailio database
* kamailioro - (with password set by <PASSWORD> in kamctlrc) - user which has read-only access rights to kamailio database


* Start / stop kamailio :

If the default startup system is systemd, then kamailio can be managed via systemctl:

::

    systemctl start kamailio<commit_msg>Update installation.rst<commit_after>Installation
************

Table of contents
=================

* Introduction
* Prerequisites
* Sip server installation
* SBC installation
* Postgresql configuration
* Web server install
* PyFreeBilling installation
* Next step

Introduction
============

This howto is written for Debian 8 server.
You need 2 interfaces with 2 ip public addresses, one for customers side and the other one for provider side.

Prerequisites
=============

First, you need to install these packages

::

    apt-get install git-core build-essential autoconf automake libtool libtool-bin libncurses5 libncurses5-dev gawk libjpeg-dev zlib1g-dev pkg-config libssl-dev libpq-dev unixodbc-dev odbc-postgresql postgresql postgresql-client libpq-dev libxml2-dev libxslt-dev ntp ntpdate libapache2-mod-wsgi apache2 gcc python-setuptools python-pip libdbd-pg-perl libtext-csv-perl sqlite3 libsqlite3-dev libcurl4-openssl-dev libpcre3-dev libspeex-dev libspeexdsp-dev libldns-dev libedit-dev libmemcached-dev python-psycopg2 python-dev libgeoip-dev libffi-dev
    
Postgresql configuration
========================

* create user and database :

::

    su postgres

::

    createuser -P pyfreebilling --interactive
        Enter password for new role:
        Enter it again:
        Shall the new role be a superuser? (y/n) n
        Shall the new role be allowed to create databases? (y/n) y
        Shall the new role be allowed to create more new roles? (y/n) y

::

    createdb -O pyfreebilling -E UTF8 pyfreebilling
    exit


Sip server installation
=======================

* First, install dependencies, edit sources.list :

::

    nano /etc/apt/sources.list

* Add this lines at the end of the files :

::

    # Kamailio 4.4 Release
    deb http://deb.kamailio.org/kamailio44 jessie main
    deb-src http://deb.kamailio.org/kamailio44 jessie main

* Add the repo GPG key, update the packages list, and install packages :

::

    wget -O- http://deb.kamailio.org/kamailiodebkey.gpg | sudo apt-key add -
    apt-get update
    apt-get install libpq5 libpq-dev
    apt-get install kamailio kamailio-tls-modules kamailio-postgres-modules kamailio-outbound-modules kamailio-extra-modules kamailio-xml-modules


* After finishing the installation, you have to edit  /etc/default/kamailio file:

::

    #
        # Kamailio startup options
        #

        # Set to yes to enable kamailio, once configured properly.
        RUN_KAMAILIO=yes

        # User to run as
        USER=kamailio

        # Group to run as
        GROUP=kamailio

        # Amount of shared and private memory to allocate
        # for the running Kamailio server (in Mb)
        #SHM_MEMORY=64
        #PKG_MEMORY=8

        # Config file
        CFGFILE=/etc/kamailio/kamailio.cfg

        # Enable the server to leave a core file when it crashes.
        # Set this to 'yes' to enable Kamailio to leave a core file when it crashes
        # or 'no' to disable this feature. This option is case sensitive and only
        # accepts 'yes' and 'no' and only in lowercase letters.
        # On some systems it is necessary to specify a directory for the core files
        # to get a dump. Look into the kamailio init file for an example configuration.
        DUMP_CORE=yes

* Configration files are located in /etc/kamailio/ folder.

The /etc/kamailio/kamctlrc is the configuration file for kamctl and kamdbctl tools. You need to edit it and set the SIP_DOMAIN to your SIP service domain (or IP address if you don't have a DNS hostname associated with your SIP service).

Set also the DBENGINE to be PGSQL and adjust other setting as you want. Very important are the passwords to connect to PostgreSSQL server, respectively DBRWPW and DBROPW. By default, their values are kamailiorw and kamailioro. You should change them before executing kamdbctl create (step detailed the section Create Database).

::

    sed "/^[# ]*SIP_DOMAIN/cSIP_DOMAIN=sip.<DOMAIN>.net" -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBENGINE/cDBENGINE=PGSQL' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBHOST/cDBHOST=localhost' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBNAME/cDBNAME=kamailiopyfb' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBRWUSER/cDBRWUSER=kamailio' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBRWPW/cDBRWPW="kamailio"' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBROUSER/cDBROUSER=kamailioro' -i /etc/kamailio/kamctlrc
    sed '/^[#]*DBROPW/cDBROPW=kamailioro' -i /etc/kamailio/kamctlrc
    sed '/^[# ]*DBROOTUSER/cDBROOTUSER="postgres" ' -i /etc/kamailio/kamctlrc


* Create DB :
  Install Kamailio DB with db name kamailiopyfb (do not install extra tables) and drop these tables : usr_preferences, subscriber, address, dbaliases and dialplan.

To create the database structure needed by Kamailio, run:

::

    echo :*:*:pyfreebilling:mypasswd > /root/.pgpass
    # Change **mypasswd** by  kamailiorw db password
    chmod 600 /root/.pgpass
    kamdbctl create

The database name created in PostgreSQL is kamailio. Two access users to PostgreSQL server were created:

* kamailio - (with password set by DBRWPW in kamctlrc) - user which has full access rights to kamailio database
* kamailioro - (with password set by DBROPW in kamctlrc) - user which has read-only access rights to kamailio database


* Start / stop kamailio :

If the default startup system is systemd, then kamailio can be managed via systemctl:

::

    systemctl start kamailio
{'fraction_non_alphanumeric': 0.09344156443132552, 'fraction_numerical': 0.005165575131445438, 'mean_word_length': 3.357717041800643, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3684567', 'n_tokens_mistral': 3631, 'n_tokens_neox': 3519, 'n_words': 1203}