IP PBX Asterisk - principles of operation and use cases

IP-PBX Asterisk can do everything that a traditional PBX can, plus it supports business-relevant VoIP protocols: voice mail, conference calls, call center, interactive menu, recording storage. We tell you how to set up the basic functionality of Asterisk PBX from scratch and get a working computer telephony server.

For an example of setting up Asterisk, let's take an office with the following characteristics:

  • 3 departments with 25 employees;
  • three-digit telephone numbers are used;
  • services are provided by one SIP provider.

We do not recommend installing Asterisk from the repository, since this installation may install the wrong version of Asterisk and the dependencies required for it. In this case, we use the Asterisk installation from source.

Different operating systems (Cent Os, Ubunty, etc.) have different commands and required dependencies.

Installing Asterisk from source

  1. Build and install the necessary dependencies and packages.

First you need to install additional packages that are necessary for installing and running Asterisk. Without some of these packages, Asterisk will refuse to install at all (for example, if gcc is missing). Without some packages, Asterisk will install and even work, but some functionality will not be available. For example, the bison package is required to process expressions in the extensions.conf file. Another example: libnewt is required for the astman management interface to work. The Asterisk server does not require it, but without this package you will not have the astman application, which is a separate program. Ours provides an example of installing Asterisk 13 on Cent OS 6.9:

yum -y install gcc gcc-c++ make ncurses-devel libxml2-devel sqlite-devel bison kernel-headers kernel-devel openssl openssl-devel newt newt-devel flex curl sox binutils

For versions 12-13 of Asterisk, the installation of the uuid and janson packages is required. To install the uuid library on RHEL/Centos, run the command:

yum -y install libuuid-devel

. To install the jansson library on RHEL/Centos, run the command:

yum -y install jansson-devel (requires installing the epel repository first: yum install epel-release)

Then we update the system to the latest version with the command yum update –y and reboot it: reboot

  1. Installation and installation of their sources

To get an effective and working solution, we recommend: install and configure Asterisk in its pure form, without additional expansion cards and modems. This way you will get a software PBX that can be easily transferred from one server to another. To do this, you need to install Asterisk from scratch, install pjproject with jansson, update the system and disable SELinux.

First, let's disable Selinux . To do this, go to /etc/selinux/config and set: SELINUX=DISABLED.

Also turn off FireWall (iptables) :

  1. Checking status: service iptables status;
  2. Disable: service iptables stop
  3. Disabling from startup: chkconfig iptables off
  4. Reboot the system: reboot

Download and install pjproject:

d /usr/src

git clone git://github.com/asterisk/pjproject pjproject

cd pjproject/

./configure –libdir=/usr/lib64 –prefix=/usr –enable-shared –disable-sound –disable-resample

make dep

make

make install

ldconfig

ldconfig -p | grep pj

To convert mp3 files you need the Lame package. Let's install it from the repository:

rpm -Uvh https://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

yum repolist - check installed repositories

Next, install the package itself: yum install lame

Download and install the Libpri library:

cd /usr/src/

wget https://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz

tar xvfz libpri-1.4-*.tar.gz

cd /usr/src/libpri-1.4.*

make

make install

If the wget command does not exist, then install it with the command yum –y install wget

Next, download and install asterisk 13 :

cd /usr/src/

wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz

tar xvfz asterisk-13-current.tar.gz

cd asterisk-13.*

contrib/scripts/get_mp3_source.sh

./configure –libdir=/usr/lib64

If there are no errors when checking and preparing the assembly of the necessary settings and models, then the Asterisk

make menuselect - all the necessary parameters are selected, but in principle you can leave them by default, the main thing is that the necessary channel drivers are enabled

Select modules and sounds (you can leave them as default). In modules we select only sip. (we don’t install pjsip):

Install voice acting for core and extra (for the second it is available in Russian). We recommend g729, alaw, ulaw, gsm codecs. Next, it’s up to your taste which codecs are needed:

Other settings can be left as default. If you installed a module, but realized that you don't need it, just disable it in the configuration and build again using make. Save the selected changes.

Continue installation:

make

make install

make config

make samples

ldconfig

If Asterisk is installed successfully, the Asterisk logo is visible in the log lines (appears after the configure stage) .

Add Asterisk to startup and get started:

chkconfig asterisk on

service asterisk start

Check that it starts correctly via the console:

asterisk -r

Reboot your computer to check that Asterisk . When entering asterisk –r we should get to the console, as in the screenshot above.

Installing and configuring Asterisk to work with WebRTC

There is a lot of information and instructions on the topic on the Internet, but at the moment they are no longer relevant and are quite complex. In many cases, webrtc2sip is used, but it is quite difficult to assemble and make it work. Below the cut, I wrote detailed instructions on how to get WebRTC to work via Asterisk.

Preparing the system (ubuntu 14.04)

update aptitude update && aptitude upgrade -y download version 12 of asterisk:
cd /usr/src/ wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-12-current.tar.gz tar -zxvf asterisk- 12-current.tar.gz

There is a script in the Aster package that installs all the dependencies, let's try to use it first.

cd asterisk-12.5.0/contrib/scripts/ ./install_prereq install in my case the script produced a bunch of conflicts, I have ubuntu 64 and the script is trying to install i386 packages. Therefore, we will install all dependencies manually. aptitude install -y libncurses-dev libz-dev libssl-dev libxml2-dev libsqlite3-dev uuid-dev uuid libcurl-dev libspeex-dev libspeexdsp-dev libogg-dev libvorbis-dev libasound2-dev portaudio19-dev libcurl4-openssl-dev libpq -dev unixodbc-dev libsqlite0-dev libmysqlclient15-dev libneon27-dev libgmime-dev libusb-dev liblua5.1-0-dev lua5.1 libopenh323-dev libvpb-dev libgtk2.0-dev libmysqlclient-dev libbluetooth-dev libradiusclient-ng -dev freetds-dev libsnmp-dev libiksemel-dev libcorosync-dev libnewt-dev libpopt-dev libical-dev libspandsp-dev libjack-dev libresample-dev libc-client-dev binutils-dev libsrtp-dev libgsm1-dev libedit-dev doxygen libjansson-dev libldap-dev subversion git libxslt1-dev mc htop iftop

Let's use the script again to install additional libsrtp and pjproject packages, they are very important for webrtc to work

./install_prereq install-unpackaged

here everything came together without problems, but if errors suddenly arise, we install everything manually

cd /usr/src/ git clone https://github.com/cisco/libsrtp.git cd libsrtp ./configure CFLAGS=-fPIC && make libsrtp.a && make uninstall && make install cd .. echo "/usr/local /lib" > /etc/ld.so.conf.d/usr_local.conf /sbin/ldconfig git clone https://github.com/asterisk/pjproject.git cd pjproject ./configure --enable-shared --with-external -speex --with-external-gsm --with-external-srtp --disable-sound --disable-resample && make && make install /sbin/ldconfig

At this point, the system is ready to install asterisk with webrtc support.

Installing Asterisk

cd /usr/src/asterisk-12.5.0/ ./configure && make menuselect
in the menu you need to check if there are asterisks

Channel Drivers -> chan_pjsip and chan_sip Resource Modules -> res_srtp, res_crypto and res_http_websocket

If everything is there, then we continue; if not, we check the dependencies again.

make && make install && make samples

We generate certificates.

mkdir /etc/asterisk/keys cd /usr/src/asterisk-12.5.0/contrib/scripts/ ./ast_tls_cert -C pbx.pbxware.ru -O “ATC Design” -d /etc/asterisk/keys the script will ask to install password (at least 4 characters) for the certificate.

The installation is complete, let's move on to the settings.

Settings

edit the http.conf file

[general] enabled=yes bindaddr=0.0.0.0 bindport=8088

rtp.conf

[general] rtpstart=10000 rtpend=20000 icesupport=yes stunaddr=stun.l.google.com:19302

sip.conf

[general] udpbindaddr=0.0.0.0:5060 realm=webrtc.pbxware.ru ; replace with your IP or the domain name of the server with asterisk. transport=udp,ws [webrtc](!) host=dynamic context=from-internal type=friend encryption=yes avpf=yes force_avp=yes icesupport=yes nat=force_rport,comedia directmedia=no disallow=all qualify=yes videosupport= yes allow=ulaw,alaw,vp8,h264,h263p,mpeg4 dtlsenable=yes dtlsverify=no dtlscertfile=/etc/asterisk/keys/asterisk.pem dtlscafile=/etc/asterisk/keys/ca.crt dtlssetup=actpass [101] (webrtc) defaultusername=101 secret=101badpassword [102](webrtc) defaultusername=102 secret=102badpassword [103](webrtc) defaultusername=103 secret=103badpassword [104](webrtc) defaultusername=104 secret=104badpassword [105](webrtc) ) defaultusername=105 secret=105badpassword [106](webrtc) defaultusername=106 secret=106badpassword

extensions.conf

[from-internal] exten => 999,1,Answer() same => n,Playback(demo-congrats) same => n,Hangup() exten => 888,1,Answer() same => n,Echo () same => n,Hangup() exten => _XXX,1,Noop(webrtc test call) same => n,DIAL(SIP/${EXTEN}) same => n,Hangup()

Testing

For testing, we can use the HTML5 sip client from the sipml5.org/call.htm server or install it on our server.

aptitude install apache2 cd /var/www/html/ svn checkout https://sipml5.googlecode.com/svn/trunk/ sipml5

Now the web HTML5 sip client is available on our server webrtc.pbxware.ru/sipml5/call.htm Settings

Display Name: web1 Private Identity*: 101 Public Identity*: sip: [email protected] Password: 101badpassword Realm*: webrtc.pbxware.ru

in Expert mode WebSocket Server URL[2]: ws://webrtc.pbxware.ru:8088/ws ICE Servers[4]: [{ url: 'stun:stun.l.google.com:19302'}]

Testing

Call between two laptops:

Call to Android (chrome)

call log

webrtc*CLI> == Using SIP VIDEO CoS mark 6 == Using SIP RTP CoS mark 5 — Executing [ [email protected] :1] NoOp("SIP/103-00000020", "webrtc test call") in new stack — Executing [ [email protected] :2] Dial("SIP/103-00000020", "SIP/104") in new stack == Using SIP VIDEO CoS mark 6 == Using SIP RTP CoS mark 5 — Called SIP/104 — SIP/104-00000021 is ringing webrtc*CLI> — SIP/104-00000021 answered SIP/103-00000020 — Channel SIP/103-00000020 joined 'simple_bridge' basic-bridge <13742dcb-5019-4fd2-b85e-0e1b70b1ccd7> — Channel SIP/104-00000021 joined 'simple_bridge' basic-bridge <13742dcb-5019-4fd2-b85e-0e1b70b1ccd7> webrtc*CLI> sip show channels Peer User/ANR Call ID Format Hold Last Message Expiry Peer 91.203.82.152 104 0a9b261a3926 a75 (ulaw| vp8) No Tx: ACK 104 91.203.82.152 103 3f8b4b42-600d-8 (ulaw|vp8) No Rx: ACK 103

Tests were carried out on chrome 37.0.2062.94 - voice, video, DTMF work. android chrome 37.0.2062.117 - voice, video, DTMF work. Firefox 32.0 - voice and DTMF work. The video only works in one direction.

PS Now the server is running, you can call and check how WebRTC works.

Add a calling plan

You will need a calling plan to make calls. Find the extensions.conf configuration file, make a backup copy of it, and clear the original version of comments and write the following into it:

extension - https://asterisk.ru/knowledgebase/Asterisk+config+extensions.conf

[local]

;for outcome. internal numbers between each other

exten => _XXX,1,Noop(Test ${CALLERID(num)} Hat)

exten => _XXX,n,Dial(SIP/${EXTEN})

This will add a calling plan for three-digit numbers. In our case, these are numbers 101 and 102 (in sip.conf)

Reload the dialplan:

dialplan reload

It's okay if error messages appear on the screen - you haven't completed the setup yet and will fix them in the next steps.

Check the list of users with the command:

sip show peers

Users, Passwords and Context

Install any software dialer or use a real phone. In the first option, you will need to configure the software to work with the PBX. In our example, we use Zoiper 5. An example of settings is listed in our wiki https://wiki.new-tel.net/doku.php?id=Zoiper-PC:

Software dialer settings for checking Asterisk

All further settings of the dialer and the principle of operation are indicated in the link above.

Now check connected peers using the command:

Sip show peers

If everything is correct, you will see the following line:, which shows our SIP line and the connection status of the SIP line:

Sip line IP-address A 5060 OK Cached RT

After setting up Asterisk, test calls on two subscribers. To do this, connect another physical or softphone. Call from one subscriber to another (by dialing from 101 to 102 and vice versa). Check the contents of the file /var/log/asterisk/full. – a record of the last call will appear there. It also records all messages and errors that occur when running Asterisk .

Records of all subsequent calls will also end up in this file. Later they can be transferred to the database.

Editing dialplan

To configure incoming and outgoing calls in Asterisk IP telephony, edit the extensions.conf file by adding the following code at the end (from the local context):

;for trunk output (example is indicated with the prefix 123#).

exten => _123#8XXXXXXXXXX,1,Set(CALLERID(all)=78125000963)

exten => _123#8XXXXXXXXXX,n,Noop( (CALLERID(all) + Boris)

exten => _123#8XXXXXXXXXX,n,Dial(SIP/7${EXTEN:5}@Ip-address)

; getting rid of the 123# prefix and replacing the number 8 with 7. Next, a call is sent to the IP provider’s host (specified in sip.conf)

[trunk_cid]

;for entry. via trunk to 101.

exten => _XXXXXXXXXX,1,Dial(SIP/101,30,r)

Reboot Asterisk with the core restart now command and make a test call again. Information about it will be added to the file full

Example of Asterisk console log:

This completes the basic setup of Asterix IP telephony. To expand the functionality after Asterisk is installed, set up a greeting and voice menu (ivr), activate voice mail, set up a queue for incoming calls, collect and view statistics (cdr viewer), record conversations, put music on hold (on hold), set up conferences, transfer, interception and call forwarding.

Easy installation of Asterisk + FreePBX for beginners

Situation

There are quite a lot of descriptions on the Internet today about deploying IP telephony, and there are basically two options:

  • We take a ready-made distribution in the form of an installation image (Elastix, Trixbox etc...) and as a result we get a working complex without having any knowledge of Linux
  • We install the complex ourselves, compiling from source code and manually editing many configuration files.

Each option has both advantages and disadvantages. If the first method involves almost zero preparation and makes it possible to get the result without understanding anything about how it works, then the second, on the contrary, requires extensive knowledge of Linux and is very difficult for beginners, although it provides high flexibility and scalability.

Prerequisites

In the process of introducing IP telephony in one of the companies with an extensive branch structure, both options were considered, but both were not satisfactory for a number of reasons:

  • The budget for the project did not imply the costs of attracting third-party companies to deploy the project; it was decided to deploy the entire telephony complex on our own.
  • Most of the system administrators in the branches were not familiar with Linux systems and were pure Winows administrators.
  • It was necessary to ensure high flexibility of the system for future, not yet imagined tasks.

We were faced with a dilemma: on the one hand, it is easier to set up servers and send them to the regions, but on the other hand, the entire burden of maintaining such a “black box” falls on our shoulders, and there are few of us. In general, we ourselves were not happy with this situation. The option of ordering implementation from a third-party company was immediately rejected by management for financial reasons. The option of a ready-made distribution kit also disappeared, since the project implied the need to expand the telephony functionality to suit the company’s needs, taking into account the characteristics of the branches, and this expansion had to be carried out by local employees. That is, without training in nix systems, there is no way.

Solution

We decided to take a path that was more complicated and labor-intensive for us, but cheaper for the company.
We started teaching system administrators the basics of working with Linux. The concept of the training is that an employee can independently take a standard distribution kit of Linux ubutu server 12.04 and be able to install Asterisk, FreePBX Web management and the hylafax+Avantfax web-based fax management system on it, while using real projects in their current states. In addition, to simplify deployment, the instructions had to be kept as simple and short as possible. In the end, it all came down to a simple copy-paste and installation of most packages from the repositories. The whole process was verified many times by repeated installations. We have tried to ensure the principle of minimum sufficiency. Everything that could be done without was skipped (left for employees to learn on their own). This greatly simplified the task for Win admins who were not used to the console and allowed them to feel more confident, especially when, as a result of their own actions, they received a working system in a minimum number of attempts. This is very encouraging in the early stages.

So the instructions themselves

After installing a clean ubuntu server 12.04 LTS according to these instructions, we are ready to start the installation.
For the first time, we perform ALL actions by copying and pasting without changing anything, as is!

LAMPA installation

LAMPA - (Linux,Apache,Mysql,Php,Asterisk) apt-get update apt-get install lamp-server^ libmysqlclient18 asterisk-dev \ asterisk-mysql asterisk-moh-opsound-wav php-db selinux-utils audiofile-tools \ bison libset-intspan-perl curl openssl php5-gd lame sox libxml2 subversion \ dahdi-* linux-headers-`uname -r` During the installation process, the wizard will ask you to set a password for the mysql server. We set, for example, PaSs or our own and remember. There is no need to leave your password blank!

FreePBX

Specify the password that was set when installing mysql

passwd=PaSs #Indicate the version we want to install fpbxver=2.10

Loading and creating a database

svn co https://svn.freepbx.org/freepbx/branches/$fpbxver /usr/src/freepbx cd /usr/src/freepbx mysqladmin create asterisk -p${passwd} mysqladmin create asteriskcdrdb -p${passwd} mysql asterisk < SQL/newinstall.sql -p${passwd} mysql asteriskcdrdb < SQL/cdr_mysql_table.sql -p${passwd} echo "GRANT ALL PRIVILEGES ON asterisk.* TO [email protected] IDENTIFIED BY '${passwd}'; » > /tmp/tmpfbpx echo "GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO [email protected] IDENTIFIED BY '${passwd}';" >> /tmp/tmpfbpx echo “flush privileges;” >> /tmp/tmpfbpx echo "quit" >> /tmp/tmpfbpx mysql -p${passwd} < /tmp/tmpfbpx

Installing FREEPBX

We start the installation (fill in the parameters or leave them as default): rm /var/www/index.html ./install_amp —password=${passwd} —webroot=/var/www Confirm the adduser parameters www-data asterisk /etc/init.d /apache2 restart wget https://127.0.0.1/admin/config.php# -O /dev/NULL

Preparing WEB server

Changing the apache2 configuration to work correctly with the Russian language, and also changing the www-data user on behalf of which apache2 starts to the asterisk locale-gen ru_RU user perl -pi -e 's/#AddDefaultCharset UTF-8/AddDefaultCharset UTF-8 /g' /etc/apache2/conf.d/charset perl -pi -e 's/export APACHE_RUN_USER=www-data/export APACHE_RUN_USER=asterisk/g' /etc/apache2/envvars perl -pi -e 's/export APACHE_RUN_GROUP=www-data/export APACHE_RUN_GROUP=asterisk/g' /etc/apache2/envvars /etc/init.d/apache2 restart

Downloading modules and updates

Download and install fresh modules ./setup_svn.php ./install_amp cp amp_conf/moh/*.wav /var/lib/asterisk/moh cd /etc/asterisk rm ccss.conf extensions.conf logger.conf iax.conf sip.conf features.conf sip_notify.conf chan_dahdi.conf chown asterisk:asterisk /etc/amportal.conf
At this point the basic functionality is ready, you can connect to the server at the server address, login and password: admin

Some additions and fixes

A small tweak for stable operation of the FOP panel, restarts it once every 10 minutes chmod 770 -R /var/www/admin/modules/fw_fop echo “*/10 * * * * root amportal 2 > /dev/NULL”>>/etc /crontab Fixing jambs with sound storage paths cp -r /var/lib/asterisk/sounds/ /usr/share/asterisk/ rm -r /var/lib/asterisk/sounds/ ln -s /usr/share/asterisk/sounds /var/lib/asterisk/ chown -R asterisk:asterisk /var/lib/asterisk/sounds/ chown -R asterisk:asterisk /var/lib/asterisk/sounds/custom/ Voice
Russification

paths=/usr/share/asterisk/sounds/ cd /tmp wget -c https://downloads.asterisk.org/pub/telephony/sounds/asterisk-core-sounds-ru-wav-current.tar.gz mkdir $ paths/ru cd $paths/ru tar zxvf /tmp/asterisk-core-sounds-ru-wav-current.tar.gz

At this stage, the basic system is considered deployed, then configuration via the WEB interface takes place.

Link to wiki with instructions

Errors in Asterisk configuration

Let's look at common mistakes when setting up a virtual PBX "Asterix" and give instructions that will help them.

  • Asterisk does not register with the server and returns a Forbidden response in debug mode.
    Reason: the password was entered incorrectly, the SIP ID or domain was specified. Check the contents of the sip.conf file.
  • Incoming calls are dropped.
    Reasons: internal user is not registered. Check the registration with the sip show registry command.
  • Outgoing calls are not received.
    Reason: the number template was specified incorrectly (the “_” character was missing before the template).
  • Sound travels only in one direction.
    Reason: You are using NAT. Enable debug and use tcpdump - this way you will see where requests and audio traffic are going.

Installing Asterisk

Installation and configuration will be simple if you follow the step-by-step instructions.

If you only need a VoIP network, then you can install only asterisk. But the best option would be to install three packages.

The dahdi driver is used for digital equipment. To exchange data with peripheral equipment, a driver is needed. The principle of setting up Asterisk is as follows:

Asterisk server<->chan_dahdi<-> Driver dahdi<-> Map <-> Phone/Switch/Phone network

The libpri library is required to use the ISDN TDM interfaces: PRI (PrimaryRateInterface) and BRI (BasicRateInterface). Libri is divided into channels by time - Time Division Multiplexing.

You might consider installing Asterisk from source. This installation method makes it possible to install Asterisk from scratch.

Important! There are several conditions for installing and configuring the program.

  • The system kernel version must be at least 2.6.
  • The presence of header files in the system is mandatory.
  • Presence of gccctermcap and openssl compiler.

After checking all these points, you can begin installation. To do this, go to the website in Download and download the following archives:

  • "asterisk"
  • "asterisk-sounds"
  • "asterisk-addons"
  • "zaptel"
  • "libpri"

After that, copy the files to the server and place them in the “/usr/src/.” folder.

Next, you need to launch a terminal in the server.

Then unpack each archive with the command “tar-xzf<name>tar.gz”.

Then go to each folder using the “cd<name>” command.

Once finished, you need to run certain commands to configure:

  • "./configure" (this will prepare the program for assembly)
  • "make" (build command)
  • “makeinstall” (program installation)

You don't need to make any special efforts to install the necessary packages. Asterisk has package automation, so this requires the install_prereq script, which can be found in the contrib/scripts subdirectory, where the source codes are.

You need to go to this subdirectory and run the script. It will install the necessary packages.

Thus, if all steps are followed, Asterisk for Dummies will be ready.

Rating
( 1 rating, average 4 out of 5 )
Did you like the article? Share with friends:
For any suggestions regarding the site: [email protected]
Для любых предложений по сайту: [email protected]