How to Install Asterisk on CentOS 7

How To Install Asterisk On CentOS 7

This tutorial will guide you through the steps required to install Asterisk 15 on CentOS 7.

 

Disable Selinux

If SELinux is set to enforcing mode, Asterisk will not function correctly.

To disable SELinux security features, open the /etc/selinux/config file and set SELINUX=disabled

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#       targeted - Targeted processes are protected,
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted

Save the file and reboot your CentOS system with:

sudo shutdown -r now

Once the machine boots up, make sure that the getenforce command returns Disabled:

getenforce
Disabled

 

Download Asterisk

We are going to download Asterisk source in the /usr/src directory which is the common location to place source files.

Change to the /usr/src directory by typing:

cd /usr/src/

Download the latest version of Asterisk 15 with the following wget command:

sudo wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-15-current.tar.gz

Once the download is completed, extract the downloaded file using the following command:

sudo tar zxf asterisk-15-current.tar.gz

Before continuing with the next steps, make sure you change to the Asterisk source directory by typing:

cd asterisk-15.*/

 

Install Asterisk Dependencies

Download the MP3 sources which are required to build the MP3 module and use MP3 files on Asterisk:

sudo contrib/scripts/get_mp3_source.sh

Next install all missing dependencies with the install_prereq script:

sudo contrib/scripts/install_prereq install

The script will install all necessary packages and upon successful completion, it will print the following message:

#############################################
## install completed successfully
#############################################

 

Install Asterisk

The configure script will perform a number of checks to make sure all of the dependencies that are required by the build and install process are present, start the script by typing:

sudo ./configure --libdir=/usr/lib64

The next step is to select the modules you want to compile and install.

Most of the modules are already enabled. Access the Menuselect system, by typing:

sudo make menuselect

Start the compilation process using the make command:

sudo make -j2

The next step is to install Asterisk and its modules by typing:

sudo make install

Install either the generic configuration files with reference documentation by typing:

sudo make samples

Or install the basic PBX configuration files:

sudo make basic-pbx

The last step is to install the Asterisk init script by typing:

sudo make config

Finally run ldconfig to update the shared libraries cache:

sudo ldconfig

 

Create Asterisk User

By default Asterisk runs as a root user. For security reasons we will create a new system user and configure Asterisk to run as the newly created user.

To create a new system user named asterisk run the following command:

sudo adduser --system --user-group --home-dir /var/lib/asterisk --no-create-home asterisk

To configure Asterisk to run as asterisk user, open the /etc/sysconfig/asterisk file and uncomment the following two lines:

AST_USER="asterisk"
AST_GROUP="asterisk"

Add the asterisk user to the dialout and audio groups:

sudo usermod -a -G dialout,audio asterisk

We also need to change the ownership and permissions of all asterisk files and directories so the user asterisk can access those files:

sudo chown -R asterisk: /var/{lib,log,run,spool}/asterisk /usr/lib64/asterisk /etc/asterisksudo chmod -R 750 /var/{lib,log,run,spool}/asterisk /usr/lib64/asterisk /etc/asterisk

 

Start Asterisk

Now that we are all set up, we can start the Asterisk service with the following command:

sudo systemctl start asterisk

To verify that Asterisk is running, connect to the Asterisk command line interface (CLI) by typing:

sudo asterisk -vvvr

 

Adjust the Firewall Rules

Now that Asterisk is installed and running you need to configure your firewall to allow traffic on Asterisk specific ports.

If you don’t have firewall enabled on your system, you can skip this section.

Open your text editor of choice and create the following Firewalld service:

<?xml version="1.0" encoding="utf-8"?>
<service version="1.0">
  <short>asterisk</short>
  <description>Asterisk is a software implementation of a telephone private branch exchange (PBX).</description>
  <port protocol="udp" port="10000-10100"/>
  <port protocol="udp" port="4569"/>
  <port protocol="udp" port="2727"/>
  <port protocol="udp" port="5060-5061"/>
</service>

 

Save the file and apply the new firewall rules by typing:

sudo firewall-cmd --add-service=asterisk --permanentsudo firewall-cmd --reload

Finally check if the new firewall rules are applied successfully with:

sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: ssh dhcpv6-client asterisk
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

Feel free to adjust the firewall according to your need.

 

Conclusion

In this guide we have shown you how to install the latest Asterisk version from source on your CentOS system.