How To: Setup an Asterisk Server

Setup an Asterisk Server

Over the years, I have enjoyed playing with Asterisk. I have found Asterisk to be extremely powerful and fun to play with. There are several books and many scattered how to articles out there, but most are outdated and the information required to build Asterisk from beginning to end can be a bit daunting. I wanted to combine all the steps into a single article and share my experience with everyone. If I have left out any steps please let me know.

How to Setup Your Very Own Asterisk Server

I chose to build Asterisk from source on a CentOS 5.5 machine. I also have the optional Zapmicro TDM400 Analog Interface PCI card with 2 FXO and 2 FXS modules. My current setup includes one analog line via the zapmicro card and one line via GoogleVoice. In order to make everything work together, several packages that are not installed by default are required.

This article focuses on building your Asterisk box from scratch, there are several pre-built distributions such as AsteriskNow and trixbox which are also excellent options. I happen to like to build from scratch, the pre-built distributions require the deletion of all partitions, building from source allows you to use the latest stable version and add on to existing servers in your home or organization. I also like to do things the hard way just for the learning experience.

Warnings

  • Building from source can take quite a bit of patience and time.
  • Please do not get discouraged during the build process, remember, whatever doesn't kill you only makes you stronger (or geekier in this case)

Step 1 Setting up your base system

For all intents and purposes this article will utilize CentOS 5.x as the base system. I prefer to use CentOS since it is a rebuild of Redhat Enterprise Linux and it is well tested and found in many professional settings. You can use any distribution of your choice, but the steps may require slight modification.

I have a few spare computer laying around, and one already had a basic installation of CentOS 5.5 on it. If you are starting with a blank slate, you can obtain the ISOs for installation here. Please choose the right architecture for your machine.

Step 2 Apply all updates and install necessary packages

First things first, either login as root or a user with sudo permissions, in the terminal issue the following:

            sudo yum -y update

This will update all installed packages to the latest version.

In order for Asterisk to build properly, you will need to add several packages:

  • kernel-devel
  • gcc
  • gcc-c++
  • libxml2-devel
  • ncurses-devel
  • doxygen

These RPMs are the minimum required to ensure that Asterisk configures properly. They can be installed in one shot using the command:

            sudo yum install kernel-devel gcc gcc-c++ libxml2-devel ncurses-devel doxygen

In order to use the MySQL database features of Asterisk you will need to add the following packages:

  • unixODBC-devel
  • libtool-ltdl-devely
  • mysql-server
  • mysql-devel

These RPMs can be installed in one shot using the following command:

        sudo yum install unixODBC-devel libtool-ltdl-devel mysql-server mysql-devel

Once these are installed, we can move on to the next step.

Step 3 Add atrpms to software repository sources

In order to use GoogleVoice with Asterisk, we will need iksemel libraries which will allow us to use the Jabber/GoogleTalk interfaces. These are not available from within the default CentOS repositories, so we will have to depend upon the ATRPMS repository.

Using your favorite editor, create the file /etc/yum.repos.d/atrpms.repo

Insert the following into your newly created file:

        [atrpms]
        name=CentOS $releasever - $basearch – Atrpms
        baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable
        gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
        gpgcheck=1

Save and exit

Now, we can add the remaining dependencies:

  • iksemel-devel
  • subversion
  • mpg123-devel

These dependencies can be installed in one shot by using the command:

        sudo yum install iksemel-devel subversion mpg123-devel

Once this is complete, we can obtain the source code.

Step 4 Obtaining latest Asterisk source code

I like to keep the source code for the programs I install space permitting. Generally, most people store the source code in the /usr/src directory so it is easy to find the packages in the future if we ever need to rebuild, or add new options.

Let's start by moving to the /usr/src directory

            cd /usr/src

Then let's get the two necessary source tarballs:

wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-1.8-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz

Next, we need to extract the sources:

    tar xvzf asterisk-1.8-current.tar.gz
    tar xvzf dahdi-linux-complete-current.tar.gz

Step 5 Begin the build process

For completeness we will build the dahdi packages from source, this will ensure that even if you do not have any analog hardware installed at present, it is simply a module load away. 

The build and installation of dahdi can be completed by issuing the following commands:

    cd dahdi*
    make install

Once DAHDI is installed properly, we can continue on to the actual Asterisk build. We will want to make sure that all of the requisite dependencies have been detected before continuing. We will have to run the configure script first and then check the resultant configurations. We can begin with the following commands:

    cd .. (if you are still in the dahdi directories)
    cd asterisk-1.8*
    ./confgure
    make menuconfig

Tips

  • If at this point, the make menuconfig fails, you may be using terminal inside of the X Windows system. Please maximize your terminal and try again.

How to Setup an Asterisk Server

Once you are in the make menuconfig, it should look like this:

How to Setup an Asterisk Server

Double check the channel drivers, the result should have the chan_gtalk and chan_dahdi driver installed at the very minimum:

How to Setup an Asterisk Server

Use 's' to save and exit from the menuconfig

Next we will want to run:         
           contrib/scripts/get_mp3_source.sh
           make
           make install
           make samples
           make config
           make progdocs

Now that Asterisk is installed, we can move on to the more interesting and complicated steps. First things first, let's make sure that Asterisk will start with the system, we also want to ensure that MySQL will startup as well.

        chkconfig --levels 35 asterisk on
        chkconfig --levels 35 mysqld on

Step 6 To the configurations!

We need to at this point double check if we installed any analog cards. If you have an analog interface card installed, we will need to take a few additional steps.

Warning

  • If you are using an analog interface card such as the TDM400/P, make sure that when you connect to the publicly switched telephone network (PSTN) you only connect the line to the red FXO modules. It is stated repeatedly throughout the documentation that the green FXS modules are only designed to send voltage to the analog telephones and they may be severely damaged if they receive ring level voltages from the PSTN.

    1. Run: /usr/sbin/dahdi_genconf (this will automatically detect any analog hardware installed and create the /etc/dahdi/system.conf file)

    /etc/dahdi/system.conf should look similar to this if you have a TDM400/P card installed:

# Autogenerated by /usr/sbin/dahdi_genconf on Mon Oct 10 20:38:59 2011
# If you edit this file and execute /usr/sbin/dahdi_genconf again,
# your manual changes will be LOST.# Dahdi Configuration File
#
# This file is parsed by the Dahdi Configurator, dahdi_cfg## Span 1: WCTDM/4 "Wildcard TDM400P REV I Board 5" (MASTER)
fxoks=1
echocanceller=mg2,1
fxoks=2
echocanceller=mg2,2
fxsks=3
echocanceller=mg2,3
fxsks=4
echocanceller=mg2,4

# Global data

loadzone        = us
defaultzone     = us

Perhaps a little explanation is in order here. Channels 1 and 2 in this case contain FXS modules (green) and allow me to use analog telephones on the inside. Ports 3 and 4 are FXO modules and connect to the publicly switched telephone network (PSTN). The modules use the opposite signalling of their type designation. An FXS card uses FXO signalling because the analog phone at your location needs to think it is talking to the PSTN office. An FXO card on the other hand connects to the PSTN office, but needs to act as PSTN station (phone). The echocanceller is required per channel as stated in the dahdi documentation.

Tips

  • Per the asterisk documentation, we are told to edit the chan_dahdi.conf file, however, this seemed to be incorrect and the actual file to edit is /etc/asterisk/dahdi-channels.conf

My sample /etc/asterisk/dahdi-channels.conf looks like this:

; Autogenerated by /usr/sbin/dahdi_genconf on Mon Oct 10 20:38:59 2011
; If you edit this file and execute /usr/sbin/dahdi_genconf again,
; your manual changes will be LOST.
; Dahdi Channels Configurations (chan_dahdi.conf)
;
; This is not intended to be a complete chan_dahdi.conf. Rather, it is intended
; to be #include-d by /etc/chan_dahdi.conf that will include the global settings
;

; Span 1: WCTDM/4 "Wildcard TDM400P REV I Board 5" (MASTER)
;;; line="1 WCTDM/4/0 FXOKS"
signalling=fxo_ks
callerid="Channel 1" <4001>
mailbox=4001
group=5
context=dahdi
channel => 1
callerid=
mailbox=
group=
context=default

;;; line="2 WCTDM/4/1 FXOKS"
signalling=fxo_ks
callerid="Channel 2" <4002>
mailbox=4002
group=5
context=dahdi
channel => 2
callerid=

mailbox=
group=
context=default

;;; line="3 WCTDM/4/2 FXSKS"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 3
callerid=
group=
context=default

;;; line="4 WCTDM/4/3 FXSKS"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 4
callerid=
group=
context=default

The 'context' argument will become clear once we begin to configure the /etc/asterisk/extensions.conf file. The 'context' allows us to determine the origin of the call and what actions should be taken when someone calls into the system.

Now that the optional analog hardware has been addressed, let's go ahead and set up some SIP phones. The nice thing about the SIP protocol is that you can use free soft phone programs such as SJPhone, Ekiga, or any other soft phone that supports the SIP (session initiation protocol).

Here is a simple sip.conf file

[general]
localnet=192.168.28.0/255.255.255.0 ;this is your NAT subnet information
externip=A.B.C.D ;this is your external/public IP
context=default
srvlookup=yes

[set1]
type=friend ;options here are peer, friend, or user
secret=set1 ;password used to authenticate user
qualify=yes ;make sure there is no more than 2000ms latency
nat=yes ;phone sits in a NATted environment, useful behind residential routers
host=dynamic ;the device should register each time as IP may change
canreinvite=no
context=internal ;name of context, in this case it is 'internal'

[set2]
type=peer
secret=set2
qualify=yes
nat=yes
host=dynamic
canreinvite=no
context=internal

Now, it's time to configure GoogleTalk, I had to scour around the web and combine several answers in order to get this to work properly. There are two files, gtalk.conf and jabber.conf

gtalk.conf should look like this at the bare minimum:

[general]
context=local
allowguests=yes
;;bindaddr=0.0.0.0
;;externip=A.B.C.D

[guest]
disallow=all
allow=ulaw
context=google-voice
connection=asterisk ;;references the asterisk connection defined in jabber.conf

jabber.conf should look similar to this:

[general]
autoregister=yes
debug=yes

[asterisk]
type=client
serverhost=talk.google.com
username=username@gmail.com/Talk
secret=gmail password
port=5222
usetls=yes
usesasl=yes
statusmessage="I am an Asterisk Server"
timeout=100

At this point, we have a few SIP extensions defined, we have one incoming analog line, and 2 analog handsets connected to the network. We still need to configure extensions.conf to make this all do something useful.

Let's go ahead and fire up our favorite editor, create an /etc/asterisk/extensions.conf

[internal] ;;set up handler for calls from the internal context. This answers any dialed number,
                ;;plays "hello world" then hangs up on the caller, this is a n easy test
exten => s, 1, Answer()
exten => s, n, Playback(hello-world)
exten => s, n, Hangup()

[google-voice] ;;this handles incoming calls from the google-voice context, plays "weasels have
                        ;;eaten the phone system, then hangs up
exten => s, 1, Answer()
exten => s, n, Playback(tt-weasels)
exten => s, n, Hangup()

[dahdi] ;;handles any extensions dialed from dahdi context
exten => s, 1, Answer()
exten => s, n, Playback(all-your-base)
exten => s, n, Hangup()

[from-pstn]
exten => s, 1, Answer()
exten => s, n, Dial(DAHDI/1 | DAHDI/2) ;;let's do something different and make the analog
                                                                      ;;phones ring in our network
exten => s, n, Hangup()

Step 7 Reload Asterisk and test

Now that we have the basic configurations set up, we can issue:

    service asterisk reload

This will force Asterisk to re-read all the configuration files we just changed and now everything should work as expected.

Stay tuned for the next article on more advanced dial plan configurations.

1 Comment

I can't even begin to comprehend this.

Share Your Thoughts

  • Hot
  • Latest