This article will describe how to install the open source communication software Asterisk on RHEL 8 / CentOS 8; due to the fact that Asterisk and other important dependencies are not available as RPM packages from the repositories, it is needed to compile them from sources.

In this tutorial you will learn:
  • Which are the pre-requisites to install Asterisk
  • How to compile Asterisk from sources
  • How to start Asterisk
  • How to reconfigure or remove Asterisk
  • How to access Asterisk command line interface
Asterisk systemd service startup output
Asterisk systemd service startup output on RHEL 8 / CentOS 8

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software Asterisk, pjsip, libedit
Other local or remote repositories configured; correct system date and timezone.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Introduction

Asterisk is an open source private branch exchange (PBX) software, and as such its main purpose is to establish and control telephone calls between various systems, through traditional PSTN lines or modern VoIP endpoints. In this guide we will make sure it will be installed in RHEL 8 / CentOS 8 along with common components.

Installing Asterisk on RHEL 8 / CentOS 8 - step by step.

We will put the last version - the 16.3.0 at the time of writing this tutorial.

  1. Pre-requisites
    We need to install the below packages including systemd-devel if we want to start Asterisk as a systemd service.
    # dnf -y install wget bzip2 tar sqlite-devel ncurses-devel systemd-devel 
    

    SUBSCRIBE TO NEWSLETTER
    Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


    And to develop from sources:
    # dnf -y install binutils gcc gcc-c++ kernel-devel autoconf automake libtool 
    
    From now on we need to install everything from sources so let's do it from a common folder
    # mkdir -p /root/src && cd /root/src

    First we are going to compile libedit, a replacement or alternative to the GNU readline command-line editing.
    # cd /root/src
    # wget http://thrysoee.dk/editline/libedit-20190324-3.1.tar.gz
    # tar xzvf libedit-20190324-3.1.tar.gz
    # cd libedit-20190324-3.1
    # ./configure && make && make install
    
  2. Installing optional components
    The following components are optional, but in a real scenario are very often needed. DAHDI (Digium/Asterisk Hardware Device Interface): it is a framework for interfacing with digital telephony cards in Asterisk. Let's install it.
    # cd /root/src
    # wget https://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
    # tar zxvf dahdi-linux-complete-current.tar.gz && cd dahdi-linux-complete-3.0.0+3.0.0
    # make all && make install && make install-config
    # cd /etc/dahdi && cp system.conf.sample system.conf
    # systemctl enable dahdi && systemctl start dahdi
    # modprobe dahdi
    # modprobe dahdi_transcode
    


    LibPRI is a library that adds support for ISDN (PRI and BRI), basically is needed if installing an ISDN card to communicate with legacy systems. To install it:
    # cd /root/src/
    # wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.6.0.tar.gz     
    # tar xzvf libpri-1.6.0 && cd libpri-1.6.0
    # make && make install
    
  3. Installing Asterisk
    Now it's time to compile the main application from sources - as mentioned.
    This will install also the SIP library pjsip into the system.
    # cd /root/src/
    # wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16.3.0.tar.gz
    # tar xzvf asterisk-16.3.0.tar.gz
    # wget https://raw.githubusercontent.com/asterisk/third-party/master/pjproject/2.8/pjproject-2.8.tar.bz2
    # mv pjproject-2.8.tar.bz2 /tmp
    # cd asterisk-16.3.0
    # ./configure 
    # make && make install && make install-logrotate
    
    With make install-logrotate we make sure the application log files will be rotated.
  4. Configuring Asterisk
    In Asterisk there are many configuration files, the main is asterisk.conf; to install a default version of all of them we need to run:
    # cd /root/src/asterisk-16.3.0/
    # make samples
    
    At this point, since some modules or features requires further configuration or dependencies, it is better to disable them. However, this is not mandatory, they are not essential components preventing Asterisk from starting.
    #cd /etc/asterisk
    
    # cp modules.conf modules.conf.org
    # echo "noload => res_config_ldap.so"               >>modules.conf
    # echo "noload => res_pjsip_transport_websocket.so" >>modules.conf
    # echo "noload => cdr_sqlite3_custom.so"            >>modules.conf
    # echo "noload => cel_sqlite3_custom.so"            >>modules.conf
    # echo "noload => res_config_sqlite3.so"            >>modules.conf
    # echo "noload => cdr_pgsql.so"                     >>modules.conf
    # echo "noload => cel_pgsql.so"                     >>modules.conf
    # echo "noload => res_config_pgsql.so"              >>modules.conf
    
    sed -i.org 's/enabled = yes/enabled = no/' ari.conf 
    


    Afterwards it`s time to prepare the systemd service files:
    # cd /root/src/asterisk-16.3.0/contrib/systemd
    # cp asterisk* /usr/lib/systemd/system
    
    The Asterisk service should run as a normal user, for security reasons, so we need to add a service ID that will be called asterisk as specified in the systemd config file.
    # useradd -m -c "asterisk user"
    
    
    Then let's change some permissions:
    chown -R asterisk:asterisk /var/log/asterisk/*
    chown  asterisk:asterisk /var/log/asterisk/.
    
  5. Starting Asterisk
    SELinux will prevent Asterisk from starting, so we are putting it in permissive mode for the sake of simplicity.
    # setenforce 0
    # sed -i.org 's/enforcing/permissive/' /etc/sysconfig/selinux
    
    Finally we can start Asterisk
    # systemctl enable asterisk
    # systemctl start asterisk
    
    You can also run Asterisk directly without systemd by issuing:
    # /usr/sbin/asterisk -mqf -C /etc/asterisk/asterisk.conf
    or better
    # asterisk -vvvc
    to get verbose info.
    Asterisk output when launched directly
    Asterisk output when launched directly


  6. SUBSCRIBE TO NEWSLETTER
    Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  7. Reconfiguring Asterisk
    It is possible at any time to reconfigure Astering by removing or (re-)adding any feature.
    Just stop the service, change to the source folder and run make menuselect.

    Asterisk menuselect
    Asterisk menu select
    # systemctl stop asterisk
    # cd /root/src/asterisk-16.3.0/
    # make menuselect
    
    If you have made any change you need to save the configuration before exiting from the menu-select menu.
    After is necessary to re-compile again Asterisk as explained above. It is better to make any change in a test environment first.

  8. Removing Asterik
    If you ever need to remove Asterisk from the system - including Dahdi and libpri - here are the steps:
    # systemctl stop dahdi
    # systemctl stop asterisk
    # cd /root/src/asterisk-16.3.0
    # make uninstall-all
    cd /root/src/libpri-1.6.0 && make uninstall
    
  9. Accessing Asterisk CLI
    This software has also its shell, in order to access it - once Asterisk is started - we need to type:
    # asterisk -r 
    Asterisk CLI
    Asterisk CLI

Conclusion

We have successfully compiled Asterisk from sources and started it, however it is not enough to get a working environment; typically after installation you will add your SIP endpoints by editing the configuration file sip.conf - or through the CLI mentioned - and configure any extension in the file extensions.conf. Both files are in /etc/asterisk.

ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.