How to Install Asterisk 20 + on CentOS 7/8/9

Introduction

Before we begin talking about how to install Asterisk on CentOS 7, let’s briefly understand – What Asterisk is?

Asterisk is a very famous and open-source PBX platform that powers IP PBX systems, conference servers, and VoIP gateways. It is being used worldwide by small businesses to huge enterprises.

It has many useful features like music on hold, call queuing, interactive voice response, conference calling, and voicemail.

In this tutorial, you will install Asterisk 20 on CentOS 7. We will also address some FAQs related to the Flask installation.

Here are some benefits of using Asterisk:

  1. Cost-effective: Asterisk is open-source, which means it’s free to use and can be modified to fit specific needs. This can make it an affordable alternative to commercial communication solutions.
  2. Flexibility: Asterisk can be integrated with a variety of technologies and programming languages, including PHP, Python, and Perl. This means developers can build a wide range of communication applications tailored to their specific needs.
  3. Customizability: Asterisk is highly customizable and can be configured to work with almost any type of telephony hardware or software. This makes it easy to integrate existing systems with new applications.

Prerequisites

  • You have to be logged in as a user with sudo privileges.
  • You also have to update CentOS 7 and install the development tools as they will be helpful in compiling the Asterisk source code:
sudo yum update
sudo yum groupinstall core base "Development Tools"

Step 1 – Disable SELinux

Asterisk doesn’t function properly if SELinux is set to the enforcing mode.

In order to make Asterisk work, you’ll have to open /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 above file and reboot the system.

sudo shutdown -r now

On completion of the reboot, make sure getenforce command returns Disabled:

getenforce
Output

Disabled

Step 2 – Download Asterisk

1) We’ll start by downloading Asterisk in the /usr/src directory, which is a common place to keep source files.

2) Next, you need to change the /usr/src directory by using the following command:

cd /usr/src/

3) With the following wget command download the latest version of Asterisk:

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

4) Next, extract the downloaded file with the following command:

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

5) Before continuing, change the Asterisk source directory with the help of the commands given below:

cd asterisk-20.*/

Step 3 – Install Asterisk Dependencies

1) Now, you’ve to download the Mp3 sources, required to build the Mp3 module and use the Mp3 files on Asterisk:

sudo contrib/scripts/get_mp3_source.sh

2) After that, you need to install all the missing dependencies with the help of install_prereq  script;

sudo contrib/scripts/install_prereq install

3) Once all the necessary packages are installed, the following output will be printed:

Output

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

Step 4 – Install Asterisk

This will be followed by the configure script performing a number of checks to make sure all the dependencies needed for the build and install process are present, use the following command:

1) Use the configure script as it will check if all the dependencies required by the build and install process are present or not, use the following command:

sudo ./configure --libdir=/usr/lib64 --with-jansson-bundled

On completion, you should be able to see the following output:

Asterisk Configuration Output

2) Now you’ve to select the modules you want to compile and install.

3) Majority of the modules have already been enabled, you can access the Menuselect with the following command:

sudo make menuselect

Since all Mp3 files have already been downloaded, you need to instruct Asterisk to build the Mp3 module by selecting format_mp3:

Asterisk Mp3 Directory

4) Now hit F12 to save and exit, or simply switch to the Save and Exit button then press Enter.

5) Use the make command to commence the compilation process:

sudo make -j2

👉

The build might take some time to finish, based on your system, you can modify the -j flag as per the number of your processor cores.

6) On completion, you will be presented with the following output:

Asterisk Final Output

7) Now, you need to install Asterisk and its module with the following command:

sudo make install

8) When the installation is complete, you’ll see a similar output as below:

Asterisk Installation Output

9) Now that Asterisk has been installed, you need to install the sample configuration files.

10) You can install the generic configuration files with the help of the following command:

sudo make samples

11) Alternatively, you can use the basic PBX configuration files:

sudo make basic-pbx

12) Install the Asterisk init script by typing the following command:

sudo make config

13) Now, run ldconfig to update the shared libraries cache

sudo ldconfig

Step 5 – Creating Asterisk User

Asterisk runs as a root user but for security reasons, you will be creating a new system user and configuring Asterisk to run as the newly created user.

1) Use the command given below to create a new user named asterisk

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

2) In order to make the asterisk run as asterisk user, open the /etc/sysconfig/asterisk then simply uncomment the following two lines:

AST_USER="asterisk"
AST_GROUP="asterisk"

3) Next, you have to add asterisk user to the dialout and audio groups

sudo usermod -a -G dialout,audio asterisk

4) Now, change the ownership and permissions of all asterisk files and directories so that the user asterisk can access those files.

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

Step 6 – Start Asterisk

1) Now, you can start Asterisk with the following command:

sudo systemctl start asterisk

2) Connect to Asterisk Command Line Interface (CLI) in order to check for its proper functioning

sudo asterisk -vvvr

3) This is how the Asterisk CLI prompt will look like:

Asterisk CLI Prompt

4) Now, enable the Asterisk service to start on boot with the following command:

sudo systemctl enable asterisk

Step 7 – Adjust the Firewall

Once Asterisk is installed successfully, configure the firewall to allow the traffic on specific ports.

Note: If the firewall is disabled on your system, you may skip this section.

2) Create the following Firewalld service by opening your text editor:

<?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>

3) With the next set of commands, Save and Apply the firewall rules:

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

3) Next, check whether the new firewall settings have been saved properly:

sudo firewall-cmd --list-all
Output

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:

FAQs to Install Asterisk on CentOS 7\

Is it possible to run Asterisk without special hardware?

Leave a Reply

Your email address will not be published. Required fields are marked *