How to install Asterisk 1.8 on CentOS 6.x

How to install Asterisk 1.8 on CentOS 6.x

1.   Introduction
The purpose of this article is to provide a step by step description of the Asterisk setup as a media server for the Nixxis platform. If the server has not been installed yet, make sure to follow AS1_CentOs_v6.x_Installation_guide.pdf  documentation first before continuing with this setup.

2.   Prerequisites
To be able properly complete the setup of the Centos Server you will need at least the following configuration details before starting the installation as well as a working internet connection either directly or via a (NAT) router/firewall.

                1.     Nixxis Application server information
                IP :

If you do not have any of these details, please contact the Project coordinator to provide you with these details before commencing the installation of the server. In no extent can any information be chosen at random as this can risk the whole infrastructure of the network.

3.   System preparations
If the setup of the IP PBX is not performed directly after installation the Operation System, please make sure to run the system update procedures first, if in doubt, run the system update.

3.1. Disabling iptables

                /etc/rc.d/init.d/iptables stop
                /etc/rc.d/init.d/ip6tables stop

                chkconfig iptables off
                chkconfig ip6tables off

3.2. Disabling Selinux
                sed -i "s/[\s]*SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
                setenforce 0

3.3. System Update
To perform a system update use the following command:

                yum –y update

After the system update, a reboot might be needed if a new kernel was installed (if in doubt please reboot before continuing)

4.   Installing system packages

4.1. C++ compiler
To install the C++ compiler use the following command:

                yum install gcc-c++

4.2. System related packages
Asterisk also has some dependencies which can be installed with the following command:

                yum -y install kernel-source kernel-devel bison openssl-devel libtermcap-devel ncurses-devel sox libxml2-devel dialog

4.3. System Tool packages

                yum install –y wget mlocate ntp wireshark unzip samba-client

4.4. IVR and scripting related packages
To be able to use and run the standard IVR script delivered with the Nixxis platform, you will need to install the PHP CLI package with the following command:

                yum –y install php-cli

4.5. Ensure time is correct

                ntpdate pool.ntp.org

make sure ntpd is set to auto start on boot with the following command:

                chkconfig ntpd on

Start the ntpd service:

                /etc/init.d/ntpd start

4.6. FTP server
Nixxis application server would be able to update the IVR scripts, it needs FTP access to the media server. To install the ftp server please perform the following action:

                yum –y install vsftpd

By default the vsftpd configuration allows anonymous access and needs some modification.
Open the /etc/vsftpd/vsftpd.conf and make sure the following values are set accordingly:

                anonymous_enable=NO                  unable anonymous user to connect on the server.
                local_enable=YES                              enable local users to access the server.
                write_enable=YES                              enable local users to write on the server.
                chroot_local_user=YES                       no need to authenticate
                reverse_lookup_enable=NO             unable to transform ip address into the hostname.

Afterwards make sure vsftpd is set to auto start on boot with the following command:

                chkconfig vsftpd on

4.7. Installing and customizing nano
Install nano with the following command:

                yum install -y nano

Customizing nano:

                echo 'include "/usr/share/nano/asterisk.nanorc"' >> /etc/nanorc
                echo 'include "/usr/share/nano/php.nanorc"' >> /etc/nanorc
                echo 'include "/usr/share/nano/html.nanorc"' >> /etc/nanorc
                echo 'include "/usr/share/nano/sh.nanorc"' >> /etc/nanorc

                cd /usr/share/nano

                mv sh.nanorc sh2.nanorc


4.8. Installing Simple network monitoring protocol (SNMP)
You have to install SNMP using:

                yum –y install net-snmp

Starting the service with the following command:

                /etc/init.d/snmpd start

5.   Downloading Asterisk sources
After this, Asterisk can be downloaded and installed following:
Create the folder and download the sources from Digium in it:

                mkdir /usr/src/asterisk
                cd /usr/src/asterisk


Untar the archives:

                tar zxvf libpri-1.4-current.tar.gz
                tar zxvf asterisk-1.8-current.tar.gz

6.   Downloading and installing hardware/IAX2 support drivers

6.1. Downloading and installing Dahdi
For IAX2 Trunking time or Transcoder cards from Digium, the Dahdi (Digium Asterisk Hardware Device Interface) interface is needed (this replaces the old zaptel interfaces).

To download the dahdi drivers please execute the following commands in the same folder (/usr/src/asterisk):

                yum install -y make
                tar zxvf dahdi-linux-complete-current.tar.gz

                cd /usr/src/asterisk/dahdi-linux-complete-current.tar.gz/
                make all
                make install
                make config

6.2. Configuring Dahdi
To configure Dahdi with the devices that are present within the machine please execute the following command:

                dahdi_genconf modules

This step will generate the /etc/dahdi/modules conf based on the hardware detected in the machine.
Start the service:

                service dahdi start

7.   Compiling and installing Asterisk
7.1. Install Asterisk
Execute the following commands:

                yum install curl curl-devel

                cd /usr/src/asterisk/asterisk-1.8*
                ./configure

(If you choose asterisk 1.8.25 use ./configure --disable-xmldoc instead of ./configure )

                make menuselect

It is very important to remove the flag BUILD_NATIVE in Compiler Flags.
Make sure to select func_curl in Dialplan Functions.

Within the “menuselect” tool make sure that at least the different sound packages are selected. Make sure that with the 3 sound sections
-       Core Sound Package
-       Music On Hold
-       Extra Sound Packages

At least the ALAW and WAV sets for both ‘EN’ and ‘FR’ are selected.

It’s highly advisable to install also the g729 packages in case there is a change of usage of g729 codecs. This will avoid transcoding for standard sound files and Music on Hold.

Build asterisk with the following commands:

                make
                make install
                make samples

7.2. Creating IVR and Recording users
The system uses one user accounts to store IVR and Recording files, please create the following users and give them a password. This password might need to be used later in the Nixxis Application server setup to access the media gateway.

You can create another user to use the file synchronization through SSH between the AppServer and the MediaServer.
This one needs to be present into the SUDOERS file (Allowing other user to run sudo)
Or, the recording user can be added in the SUDOERS file.

For the documentation, we will assume than the user recording has the right to do a “reload” of asterisk.

                adduser recording
                passwd recording (password is Rec0rding)
                chmod ugo+rx /home/recording

7.3. Web-server installation and configuration
To configure and setup the lighttpd web-server for use with Nixxis, you will need some of the configuration files from the “InstallV2.*.zip” file (see below).

Nixxis uses the LameMP3 encoder and Lighttpd web-server for recording/configuration purposes, to be able easily install these packages, the RPMforge repository need to be added to the system:

                cd /usr/src
                rpm -Uv rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

                yum install -y lighttpd lame

7.4. Transfer Nixxis Asterisk configuration files
Supplied with this documentation you should have received a set of Asterisk configuration files “InstallV2.*.zip /Asterisk” which contain the basis of the configuration and scripting files.
These files need to be transferred onto the media server and can (before or after transfer) be adapted to your current installation situation.

Note: An easy way of transferring files onto a server can be done using the SFTP protocol. Either filezilla client (windows) or Cyberduck (Mac OS X) support SFTP and allow to login in to the server to transfer files directly.

Unpack “InstallV2.*.zip” (please find it on : http://update.nixxis.net/v2.1/InstallV2.*.zip
user: install
password: qR4Eqkuz)

Via Filezilla, transfer the folders ‘etc’, ‘usr, ‘var’ and ‘srv’ to the relevant folders on the media server.

Via Linux:

                cd /usr/src/asterisk/
                wget http://update.nixxis.net/v2.1/InstallV2.*.zip --user install --password qR4Eqkuz

                unzip InstallV2.1.4.zip -d ./nixxis

                pushd /usr/src/asterisk/nixxis/MediaServer/
                cp -rf /usr/src/asterisk/nixxis/ MediaServer/etc/* /etc
                cp -rf /usr/src/asterisk/nixxis/ MediaServer/usr/* /usr
                cp -rf /usr/src/asterisk/nixxis/ MediaServer/var/* /var
                cp -rf /usr/src/asterisk/nixxis/ MediaServer/srv/* /srv

Update the rights:
-        /usr/sbin/* files to be executable à chmod a+x /usr/sbin/*
-       /srv/www/lighttpd/* files to be executable à chmod a+x /srv/www/lighttpd/*
-       /var/lib/asterisk/agi-bin/* files to be executable à chmod a+x /var/lib/asterisk/agi-bin/*

7.5. Activate CGI module
Open /etc/lighttpd/modules.conf with a text editor (like nano)

                nano /etc/lighttpd/modules.conf

Search the line #include “conf.d/cgi.conf”, edit this line and remove the “#” in the beginning of the line.

                nano /etc/lighttpd/conf.d/cgi.conf

Comment (“#” at the beginning of the line) everything except two lines:

                server.modules += ( "mod_cgi" )

and

                cgi.assign = ( "" => "" )

Change the right of the folder /var/log/lighttpd/*

                chgrp recording /var/log/lighttpd/
                chmod g+w /var/log/lighttpd/

Open /etc/lighttpd/lighttpd.conf and modify the user that will execute lighttpd:

                nano /etc/lighttpd/lighttpd.conf

Search the section “server.username” and “server.groupname” and modify “lighttpd” by “recording”   

Stop the service:

                service lighttpd stop

Update the /var/log/lighttpd to be write-able for the group recording:

                chown recording:recording /var/log/lighttpd/
                chown recording:recording /var/log/lighttpd/*
                chmod 777 /var/log/*

                chown recording:recording /srv/www/lighttpd
                chown recording:recording /srv/www/lighttpd/*
                chmod 777  /srv/www/lighttpd/*

Make sure lighttpd is started on boot of the server and start the service:

                chkconfig lighttpd on
                service lighttpd start
                service lighttpd stop
                service lighttpd restart

7.6. Asterisk configuration files
The folder /etc/asterisk/ contains the asterisk configuration files. If you do not already have your own extensions.conf then you can start with the extensions_sample.conf and rename it to extensions.conf to have a clean example to start your installation with.

Based on sip_sample.conf, generate your own sip.conf defining the various sip peers.

7.7. Adapting config files
To adapt the Asterisk config files, refer you at the “AS3_Asterisk_V1.8_Configuration_guide.pdf.

For the Application server to be able to trigger on-demand recording, a user and password need to be added to the manager.conf

Edit the manager.conf file and add the following lines to create a manager user named “nixxis” with the password “nixxis00”

                [general]
                enabled = yes

                

                [nixxis]

                secret=nixxis00
                read = system,call,log,verbose,command,agent,user,config
                write = system,call,log,verbose,command,agent,user,config

For extra security, especially when the Asterisk server is also connect directly to the internet, it is advisable to also limit the access of the manager user to the local LAN subnet. An example of this would look like this if the local LAN is 192.168.1.0/24:

                [nixxis]

                secret=nixxis00
                deny=0.0.0.0/0.0.0.0
                permit=192.168.1.0/255.255.255.0
                read = system,call,log,verbose,command,agent,user,config
                write = system,call,log,verbose,command,agent,user,config

7.8. Automatically start Asterisk on server boot
To be sure that the asterisk service is started at boot time of the server automatically, please perform the following actions:

                cp -rf /usr/src/asterisk/asterisk-1.8.*/contrib/init.d/rc.redhat.asterisk /etc/init.d/asterisk
                chkconfig asterisk on

Modify the PATH on the file (/etc/init.d/asterisk): AST_SBIN=__ASTERISK_SBIN_DIR__ to AST_SBIN=/usr/sbin

Asterisk can now be started, restarted and stopped via the service command:

                service asterisk start
                service asterisk restart
                service asterisk stop

8.   Installing Nixxis V2 related options
The steps below are related to a configuration of Asterisk for Nixxis Contact Suite V2.

8.1. Music on Hold configuration files
The “Music on Hold” feature is now controlled from the Nixxis Administrator tool, to be able to activate the within the Asterisk installation please perform the following steps:

Create the empty config file:

                touch /etc/asterisk/musiconhold_nixxis.conf

Make sure the config file is owned by the user recording:

                chown recording:recording /etc/asterisk/musiconhold_nixxis.conf

Afterwards make sure the config file is included within the basic musiconhold configuration of Asterisk.

Edit the file:

                nano /etc/asterisk/musiconhold.conf

And after the section default add the inclusion of the nixxis musiconhold config, the section should look like this:

                [default]

                mode=files
                directory=/var/lib/asterisk/moh
                #include "musiconhold_nixxis.conf"               

8.2. SuDo manipulation
To be able to control Asterisk thru the web-server (reload musiconhold after changes in the admin), the user ‘recording’ needs to be able to have the rights to connect to the Asterisk CLI. The following steps show how to perform this action:

If you are not comfortable with the VI editor please execute the following command to use Nano as text editor for the following manipulation:

                export EDITOR=nano

Now launch the editing of the sudo config file thru the command:

                visudo

In the Section ## Command Aliases add an Alias to allow execution of the asterisk cli and perl interpreter:

                ## Asterisk
                Cmnd_Alias ASTERISK = /usr/sbin/asterisk, /usr/bin/perl

Furthermore, make sure the requiretty option is not activated, by making sure the line ‘Defaults requiretty’ has a # sign in front of it, if this sign is not there, make sure to add it. The line should look like this:

                #Defaults requiretty

At the end of the file add a definition for the user recording, to allow it to execute the alias Asterisk:

                recording ALL= NOPASSWD: ASTERISK

Close the editor and the SuDo settings will be updated automatically.

8.3. Setup of sound file synchronization
As of Nixxis Contact Suite V2.2, all sound files are stored on the application server and thru SSH request the synchronization of these files is triggered on each asterisk that is part of the installation.

Create the necessary folders:

                mkdir /home/soundsv2

Make sure the folder is owned by user recording:

                chown recording:recording /home/soundsv2

The contents of the folder soundsv2 should show the same files/folders as on the Application server (after a save on the NCS side)

9.   Maintenance scripts
Nixxis provides 3 maintenance scripts with the Nixxis-asterisk-rxx.zip in the scripts folder. Below follows an explanation on each of the 3 scripts. All 3 scripts can be run from CRON at a fixed (nightly) job to perform the actions needed. There is a 4th script that uses a command already included with Centos to remove old recordings from the server.

We advise to store the files in /usr/sbin/ for them to be widely available to the system.

9.1. Setting up cronjobs
All script mentioned above are best executed at a pre-programmed time every day. Following is an example on how to setup a crontab, though more detailed information is available at the CentOS documentation website:


This example of a crontab entry will run the MP3 converter every day at 23:00 to convert the recordings on disk:

By default the crontab editor uses VI as editor, the user can tell the system to use a different editor by default, for example Nano by executing the following command:

                export EDITOR=nano

Next we launch the command to edit the crontab by executing:

                crontab –e

We add a line per job to be executed, in our case to run the job at 23:00

                0 23 * * * /usr/sbin/nixxis_mp3_converter.sh

Exit the editor while saving the changes we made to the file. After this to following command can be used to verify if the job has been put in place:

                crontab –l

9.2. nixxis_mp3_converter.sh
This scripts converts all .wav recording files into MP3 encoded files. This has a big advantage on the amount of disk-space occupied by recordings if they are kept on the Asterisk servers.

The script by default considers that all recordings are stored in /home/recording (though this can be edited in the script itself if it is not the case).

We advise to run this script in a cronjob outside of production hours to avoid high CPU load during production.

To enable the playing of the mp3 files:

                Run “make menuselect”
                Select “Add-ons”
                Make sure “format_mp3” is selected: [*]format_mp3
                Use the “Menu Select” command ‘x’ to Save and Quit
                Run “contrib/scripts/get_mp3_source.sh” <-- IMPORTANT or you won’t have MP3 source to compile and your build will fail!
                Run “make install”

You will now have MP3 support in Asterisk in addition to the default 16-bit, monaural, 8KHz sample rate WAV file format.

9.3. nixxis_recmove.sh
This script will move all recordings to a given FTP server (normally used to move the recordings from the Asterisk to the Application Server or some other external storage device.

The “recmove” script is based on the scriptable FTP client Kermit which needs to be installed on the server first.

                cd /usr/src
                mkdir kermit
                cd kermit
                cp /usr/src/asterisk/nixxis/ MediaServer/etc/.
                tar -xvf kermit.tar
                make linux
                make install

Afterwards adapt the nixxis_remove.sh with the settings of the ftp server, the example file contains the following line, which needs to be edited with the server, username and password of the remote FTP connection:

                ftp open 192.168.1.2 /user:recording /password:recording

Furthermore we need to tell the script how many days of recordings we’d like to keep on the Asterisk server. Any recordings older are moved by this script to the remote server. To set the number of days to keep, edit the following 2 lines of the script to reflect the number of days, the example will keep 21 days of recordings, meaning anything older than 21 days will be moved to the remote server.

                ftp put /before:-21days /delete *

if fail exit 1 ftp put /before:-21days /delete *: \v(ftp_message)

Last step is to put the script into a CRON job, for this see example earlier in this chapter.

9.4. Tmpwatch
This script allows you to remove files older than a certain number of hours from the server. This allows for the cleaning of the /home/recording folder in the case there is no off-server retention of recording needed.

A simple crontab entry can be setup to remove the recordings from disk. The following example will remove all recordings older then 30 days (5040 hours) from the server at 04:30.

                30 4 * * * /usr/sbin/tmpwatch 5040 /home/recording/

Use this wisely and make sure to understand that the numerical value of tmpwatch is in HOURS and not days!

9.5. (Optional) Fail2ban installation

                yum install fail2ban
                cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

For more information:

                UK: http://www.fail2ban.org/wiki/index.php/Asterisk

    • Related Articles

    • How to install Asterisk 11 on CentOS 7.x

      1.   Introduction The purpose of this article is to provide a description of the Asterisk setup as a media server for the Nixxis platform by using the Asterisk 11 on CentOS 7 automated installation script available on the Nixxis Support bitbucket. If ...
    • How to install Asterisk 18 on Redhat 8

      Introduction The purpose of this article is to provide a step by step description of the Asterisk setup as a media server for the Nixxis platform. To be able properly complete the setup, you will need at least the following configuration details ...
    • How to install CentOS 7.x

      1.   Introduction The purpose of this article is to provide a description of the CentOS 7.x setup on a media server for the Nixxis platform by using the CentOS 7 automated installation script available on the Nixxis Support bitbucket. 2.  ...
    • [Installation] - NCS v3.x - Installation and configuration procedure

      Introduction The purpose of this document is to guide you through the installation and the configuration process of Nixxis Contact Suite V3.x Application Server. 1. Prerequisites General prerequisites: Important to make sure prerequisites are ...
    • [Installation] - NCS v3.x - Installation and configuration procedure (EN)

      Introduction The purpose of this document is to guide you through the installation and the configuration process of Nixxis Contact Suite V3.x Application Server. 1. Prerequisites General prerequisites: Important to make sure prerequisites are ...