Asterisk, the installation of which will be discussed in this material, is a software for organizing the so-called office telephone exchange or IP-PBX (eng. Private Branch eXchange, PBX). It combines all the phones in the office into one information network, on the basis of which a variety of voice services work. Asterisk runs on Linux, BSD, OS X, and Windows using an emulator.
Asterisk can transmit voice over four different VoIP protocols and communicate with almost all standardized telephones (including mobile) using relatively inexpensive equipment. Asterisk implements a variety of voicemail features, including a telephone directory, conference calling, interactive voice response and call queues.
In this article, we will consider the process of installing Asterisk on Linux, in particular, on the popular CentOS and Debian distributions, as well as the basic procedures for setting up a voicemail server.
Install Asterisk server from source
To begin, consider the algorithm for installing an IP-telephony server, which is available on absolutely any Linux distribution, namely the assembly and installation of software from the source code. This method allows you to install Asterisk from scratch.
Before installing the IP telephony server, a number of conditions must be provided in the system. Asterisk must be installed on a system running on a kernel version no lower than 2.6, while the system must have header files in order for the program to compile successfully. Asterisk is written in C, so the gcc compiler with related libraries such as termcap and openssl must be installed on the system to build. Asterisk add-on builds also require pre-installed libraries and the mysql client, as well as their corresponding header files.
When the system is prepared for installation, you will need to go to the Download section on the official website and download the following archives from it:
asterisk.
asterisk-sounds.
asterisk-addons.
zaptel.
libpri.
Files must be copied to the server, which will perform the functions of the PBX. Place them in the / usr / src / folder .
After that, run the terminal on the server. Go to the directory with the archives and unzip each of them with the command:
tar-xzf<_>tar.gz
Archives will be unpacked into folders with names that match the names of archives. Go to each folder sequentially with the command:
cd<_>
And execute the following commands in each folder.
1. Preparation for assembly:
./configure
2. Assembly:
make
3. Installation:
make install
If the above commands complete with a successful result, you will build and install Asterisk on your server.
The installation procedure from the source is the same for all Linux distributions, but not familiar to everyone. Typically, most users prefer the installation methods offered by a particular distribution.
In this regard, we will consider the procedures for installing Asterisk on two popular platforms for creating office PBXs: CentOS and Debian GNU / Linux.
Install Asterisk on CentOS
As part of this example, we will install Asterisk 13. We will install Asterisk on CentOS 7.
It is assumed that the installation will be performed in text console mode on behalf of the superuser (root).
First you need to install all the necessary prerequisites. Make sure that all the packages listed below are present on the system. There are a lot of them:
As a result, the system will contain all the dependencies required to successfully build the Asterisk telephony server.
The next step should be to disable SELinux. The CentOS Security-Enhanced Linux security system is enabled by default and very often interferes with the normal functioning of Asterisk. Therefore, for successful setup and operation of the server, you must disable it.
Check the activity status of the SELinux system with the following command:
sestatus
If the system reports that SELinux is turned on, perform the shutdown procedure. To do this, you need to make changes to the configuration file in the / etc / selinux folder by setting the appropriate flag.
sed -i 's/\(^SELINUX=\).*/\SELINUX=DISABLED/' config
Next, you need to check the system time settings and, in particular, select the correct time zone. To select, you need to use commands that will allow you to define and set the current belt:
tzselect
timedatectl set-timezone <_>
(e.g. America/Los_Angeles
)
In order to check if the time zone has been set, you can use the following command:
timedatectl status
After that, you will need to reboot the system to activate the changes. To do this, use the reboot
command.
Now let's proceed directly to the installation of Asterisk.
In fact, installing Asterisk on CentOS comes down to the same build from the sources that we met in the previous section. Here we look at the build process, taking into account the features of a particular Linux distribution, namely CentOS 7.
First, download and install the IP-telephony server itself.
Download the archive from Asterisk 13 from the Downloads section on the product’s official website and save it in the / usr / src folder. Unpack the archive with the command:
tar zxvf <_>
Go to the folder with the unpacked archive and execute the commands below.
make distclean
./configure --libdir=/usr/lib64 --with-pjproject-bundled
This sequence of commands will prepare the source for the assembly.
Next, set the compilation settings:
make menuselect.makeopts
After setting compilation options, complete the following steps:
1. Create a separate user account for the IP telephony server.
adduser asterisk -s /sbin/nologin -c "Asterisk User"
2. Build and install the server.
make && make install
3. Set Asterisk permissions for the newly created user.
chown -R asterisk. /var/lib/asterisk
As a result, the Asterisk core server will be built and installed.
In addition to Asterisk itself, in a similar way on CentOS you can install useful additions to the server. Read about it below.
Freepbx
FreePBX is a full-featured Web-based graphical interface designed to configure and manage an office PBX. Installing Asterisk with FreePBX is as follows.
Run the database:
systemctl start mariadb
Download from the GitHub website to the / usr / src folder the FreePBX source code:
git clone -b release/13.0 https://github.com/FreePBX/framework.git freepbx
Next, execute the following installation commands in the folder:
./start_asterisk start
./install -n
And a number of commands to configure FreePBX:
DAHDI
DAHDI is a driver that enables Asterisk to communicate with various telephony equipment. He is responsible for the operation of telephony interface cards installed directly on the server running Asterisk. The DAHDI installation procedure is described below.
Download the driver archive in the / usr / src directory, unzip it and go to the unzipped folder. In it, execute the commands:
Pjsip
PJSIP is a C library that is responsible for supporting various IP telephony protocols. From Asterisk version 13.8 inclusive, the PJSIP library can be installed separately. However, if Asterisk compiles with the --with-pjproject-bundled flag (which we did in the previous section), the PJSIP library will be installed directly when compiling the server.
In order to install PJSIP separately, the following procedure is required.
Download the archive with the driver from the pjsip.org website to the / usr / src directory, unzip it and go to the unzipped folder. In it, execute the commands:
Post-Installation Procedures
Upon completion of the installation of Asterisk, you need to perform a number of additional steps. These procedures are mandatory.
1. Set protection for the database server:
mysql_secure_installation
To complete the procedure, simply answer Y to all questions.
2. Change web server settings:
3. Open access to services and ports necessary for Asterisk to work:
firewall-cmd --permanent --zone=public --add-service={http,https}
--add-port=5060-5061/tcp
--add-port=5060-5061/udp
--add-port=10000-20000/udp
4. Configure database autoload:
systemctl enable mariadb
5. Configure the loading of the web server at system startup:
systemctl enable httpd
6. Configure FreePBX autorun at system startup:
nano /etc/systemd/system/freepbx.service
systemctl enable freepbx
7. Set up a database connection through ODBC. If the obsolete cdr_mysql.so module is installed, this item is optional, but still recommended:
nano /etc/odbc.ini
To test ODBC communications, use the following command:
isql -v asteriskcdrdb <username> <password>
8. Reboot the system to apply the changes:
reboot
Install Asterisk 13 on Debian
In this section, we will look at the installation procedure on another popular platform - Debian. Good news for users: it is relatively simple, despite the fact that it also includes assembly from source. As an example, we will install Asterisk on Debian 8.
Installation is performed on behalf of the superuser (root). Open the terminal, get the appropriate rights, after which you can proceed with the installation.
First download Asterisk 13 from the official website and unzip the downloaded archive. Go to the folder with the unpacked source.
Now install the necessary dependencies. The most important - the gcc compiler - is already in Debian. So just load the rest:
After all the dependencies have been downloaded and installed, run the following command in the folder with the unpacked Asterisk archive:
./configure
The command should complete without errors. If the result is a message that some dependencies are missing, install them.
Before compiling Asterisk, you can enable or disable individual modules:
make menuselect
A console application with a list of modules will open. By moving the keys up and down the list, you can enable and disable them. Some add-on modules require dependency installation. This can be done using apt-get.
Now let's start compiling Asterisk. Enter the familiar commands in the console:
1. Assembly of source codes:
make
2. Installation in system directories:
make install
When the compilation completes without errors, you need to run the command:
make samples
This completes the installation. Asterisk has been successfully installed on your server. The following command will call the Asterisk management console:
asterisk -vvvvvvgc
Configure Asterisk
Now consider the basic procedures for setting up an Asterisk telephony server. They are fundamentally the same for all Linux distributions.
First, add the following text to the sip.conf file :
Thus, we will create five accounts that can be used by any SIP client (Cisco SIP Phone, xlite, ATA and the like). All users will be registered in Asterisk. If this configuration does not work, try disabling the firewall before completing the software setup.
Creating the first numbering plan
The number plan (dialplan) provides a formalized description of the processing of telephone calls. Dialplan tells the system in detail what to do with outgoing and incoming calls. For example, Asterisk can redirect them, answer them using an answering machine, and so on.
Open the extension.conf file in the / etc / asterisk folder and add the line to it:
exten=> _XXXX,1,Dial(SIP/${EXTEN})
Now all configured SIP clients will be able to receive and send calls. Due to the ease of setting up the dialplan, Asterisk is one of the friendliest IP telephony platforms. Not so many skills are required to raise an office PBX.
Create the first SIP trunk
Asterisk can make outgoing and incoming calls. For outgoing calls, we need a provider that will redirect calls to our system, as well as a public IP address.
To do this, you need to configure the SIP-trunk - a virtual communication channel between the client equipment and the telephone operator. If our server with Asterisk will act as the client’s equipment, setting up the trunk will allow you to connect any number of landline phone numbers via SIP
To create a trunk, add the following code to the sip.conf file :
After that, you will need to add another line to extension.conf :
exten => _XXXXXXX.,1,Dial(SIP/trunk1/${EXTEN})
This will allow you to establish communication with the provider for outgoing calls.
Conclusion
Setting up a full-fledged office exchange based on Asterisk, the installation of which was discussed in this article, includes much more procedures than described above. Detailed information on the telephony server and its capabilities is presented in the official documentation for Asterisk.