Install Asterisk under Debian

From SaruWiki
Revision as of 22:31, 6 October 2008 by Saruman! (talk | contribs) (→‎Configuring and testing Asterisk: added testing FXO/.FXS)
Jump to navigation Jump to search

Installing Asterisk

Once the hardware configuration part is completed, we can start the installation of Asterisk itself. Using aptitude or apt-get, install package asterisk. On Debian 5.0 "Lenny", it should be Asterisk 1.4.21.2. With apt-get, the command is simply

apt-get install asterisk

Note: many, many dependencies bring a lot of extra packages to your server when you install Asterisk. On a test machine, I counted 24 extra packages (for a total of 11.4MB to be downloaded).

If you have telephony hardware, you've likely already configured it in the preceding sections. However, when Asterisk itself is installed, you can run the genzaptelconf command again, and it will not only re-configure your zaptel.conf, but also it will generate /etc/asterisk/zapata-channels.conf

genzaptelconf -svdM -c nl

Now, as the command suggests, include the zapata-channels.conf file in /etc/asterisk/zapata.conf, either by running

echo '#include zapata-channels.conf' >>/etc/asterisk/zapata.conf

or by opening zapata.conf in your favourite text editor and pasting the line "#include zapata-channels.conf" (including the hash sign) somewhere near the end of the file.

When you've rerun genzaptelconf, Asterisk will have started at the end of the command. Your adaptation of zapata.conf is not yet noticed by Asterisk. Please reload or restart asterisk, e.g. by running

/etc/init.d/asterisk restart

Configuring and testing Asterisk

If you've done nothing more than the previously described hardware installation and configuration, and the default Asterisk installation given above, then you can already do one very simple test: plug a standard analogue telephone in one of your FXS-ports, and see if you get a dialtone. (Ofcourse, if you've only got FXO-ports or no hardware at all, then this won't help you.)
Furthermore, you could just look at the back of your Linux machine; the small LEDs next to all ports should be lit green (not including those ports for which you haven't installed a module, ofcourse). A port with a module installed, but without a burning LED, signifies no driver loaded.
Other tests and status reports can be obtained from the following commands:

  • lszaptel should show your hardware, with all installed ports (all denoted "in use"); non-installed ports may be shown as FXO-ports. Note: be aware of the neverending confusion surrounding the port name (e.g. FXS) and what signalling it runs (e.g. FXO); remember that those two are always opposed: FXO-ports run FXS signaling, FXS-ports run FXO-signaling. Thus, a non-installed port is shown as running FXS-signaling.
  • ztcfg -vv should show a channel map, with for each hardware channel the channel number and the signaling protocol.
  • asterisk -r should give you an Asterisk console (if Asterisk is in fact running).

If the above tests succeed, then it's time for our initial Asterisk configuration.

In the first configuration test, we'll configure both an FXS and an FXO channel - since that's what's in asterisk, TFOTF. This configuration comes in three parts:
First, we make sure our FXS and FXO channels are defined in /etc/zaptel.conf - as we've already ensured previously. For this configuration test, we confirm that zaptel.conf contains something like

# Span 1: WCTDM/0 "Wildcard TDM410P Board 1" (MASTER)
fxoks=1
fxsks=3
# Global data
loadzone        = nl
defaultzone     = nl

Next up, we check /etc/asterisk/zapata.conf. When we filter that file through grep -v ^\; | grep -v ^$ (thus removing lines beginning with ";" and empty lines), AND we insert the contents of zapata-channels.conf at the place of the insert statement, then we get something like

[trunkgroups]
[channels]
context=default
switchtype=national
signalling=fxo_ls
rxwink=300
usecallerid=yes
hidecallerid=no
callwaiting=yes
usecallingpres=yes
callwaitingcallerid=yes
threewaycalling=yes
transfer=yes
canpark=yes
cancallforward=yes
callreturn=yes
echocancel=yes
echocancelwhenbridged=yes
rxgain=0.0
txgain=0.0
group=1
callgroup=1
pickupgroup=1
immediate=no
; from here it's all zapata_channel.conf:
signalling=fxo_ks
callerid="Channel 1" <6001>
mailbox=6001
group=5
context=from-internal
channel => 1
callerid=
mailbox=
group=
context=default
signalling=fxo_ks
callerid="Channel 2" <6002>
mailbox=6002
group=5
context=from-internal
channel => 2
callerid=
mailbox=
group=
context=default
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 3
context=default

Well that's all nice and dandy, but for testing we'll temporarily replace this zapata.conf with a much more dressed down one:

[trunkgroups]
[channels]
usecallerid=yes
hidecallerid=no
callwaiting=no
threewaycalling=yes
transfer=yes
echocancel=yes
echotraining=yes
switchtype=national
; from here it's all zapata_channel.conf:
; the internal phone on module 1/port 1
context=phones
signalling=fxo_ks
channel => 1
; the incoming line on module 3/port 3
context=incoming
signalling=fxs_ks
channel => 3

The third configuration file we're going to change, is the file containing the "dialplan", which is /etc/asterisk/extensions.conf. We'll use the example from the TFOTF book:

[globals]

[general]

[default]
exten => s,1,Verbose(1|Unrouted call handler)
exten => s,n,Answer()
exten => s,n,Wait(1)
exten => s,n,Playback(tt-weasels)
exten => s,n,Hangup()

[incoming_calls]

[internal]
exten => 500,1,Verbose(1|Echo test application)
exten => 500,n,Echo()
exten => 500,n,Hangup()

[phones]
include => internal

[incoming]
exten => s,1,Answer()
exten => s,n,Echo()

With all config files changed (and their owner still asterisk:asterisk), we can reload the necessary files. First we connect an outside line to the FXO port. Now we stop asterisk, then unload the Zaptel drivers, then reload them all (so they'll definately read their config files) (note: our example is for a Digium TDM410P, with driver wctdm24xxp; adapt to your own driver):

/etc/init.d/asterisk stop
rmmod wctdm24xxp
rmmod zaptel
modprobe zaptel
modprobe wctdm24xxp
/etc/init.d/asterisk start

For demonstration purposes, start up an Asterisk console (asterisk -f). Now we can call the outside line attached to the FXO port (e.g. with a cell phone), and we should see in our Asterisk console something like

[Oct  8 09:06:12] NOTICE[5640]: chan_zap.c:6562 ss_thread: Got event 18 (Ring Begin)...
[Oct  8 09:06:14] NOTICE[5640]: chan_zap.c:6562 ss_thread: Got event 2 (Ring/Answered)...

Furthermore, if you speak into your phone, you should hear an echo. The other test is grabbing the phone that's connected to the FXS port, and dial 500. This also should deliver an echo, albeit much quicker.