Install Asterisk under Debian
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
Installing Asterisk-GUI
Asterisk-GUI is not an essential part of an Asterisk installation, but in some respects it can make life much easier for you. On the other hand, installing it is NOT as easy as with other Debian packages - because it's not available as a Debian package. Thus, we'll have to compile the Asterisk-GUI from source.
First obtain the latest version of the asterisk-gui package; it can be downloaded from the download section of the Asterisk site; most likely at this place. Then extract it in some logical place, like /usr/src/:
tar xzvf asterisk-gui-2.0.2.tar.gz /usr/src
This creates the directory /usr/src/asterisk-gui-2.0.2, in which the source for Asterisk-GUI can be found. cd to this directory, confiure, and compile the software:
cd /usr/src/asterisk-gui-2.0.2 ./configure make make install
These three commands should complete successfully. They all give pretty clear output when everything runs fine (we haven't seen them fail, so we can't tell what that would look like, or what to do then).
OK, so we now need to do some configuration on Asterisk-GUI. It's main configuration files are /etc/asterisk/http.conf, where the Asterisk-GUI itself is configured, and /etc/asterisk/manager.conf, which is part of the Asterisk Manager Interface (AMI), over which Asterisk-GUI makes its moves. So first we put the necessary extra info in manager.conf. The Debian setup for AMI has a line that includes all *.conf files in /etc/asterisk/manager.d, so we only need to include manager-specific information in manager.conf. This means only the following line in the section [general]:
webenabled = yes
Now we go to /etc/asterisk/manager.d, and create asterisk-gui.conf. In this, we can put the Asterisk-GUI specific lines - which really only define Asterisk-GUI users, with their passwords and their rights:
[asterisk-admin] secret = nOguess1ng read = system,call,log,verbose,command,agent,user,config write = system,call,log,verbose,command,agent,user,config
Note that this file contains user information (well, it contains Asterisk-GUI user info) with a password, so you might want to secure this file /etc/asterisk/manager.d/asterisk-gui.conf by changing the owner to asterisk:asterisk, and remove the world-readable attribute
chown asterisk:asterisk /etc/asterisk/manager.d/asterisk-gui.conf chmod o= /etc/asterisk/manager.d/asterisk-gui.conf
Furthermore, we need to edit the /etc/asterisk/http.conf file that our Asterisk-GUI installation has created, so that it contains at least the following information (comments stripped):
[general] enabled=yes enablestatic=yes bindaddr=127.0.0.1 bindport=8088 prefix=asterisk
This enables Asterisk-GUI, so that asterisk-admin can both issue AMI commands and view HTML pages, as long as a browser on the server itself is used. You could also change the bind address to that of an internal NIC on your server, which is convenient for admins, but less secure. Keep in mind though, that you can also use the iceditch firewall to limit access to port 8088 to certain subnets and/or IP numbers.
Finally, we must work around a little Asterisk-GUI bug, by removing the (empty) directory static-http from /usr/share/asterisk, and create a link there to the (non-empty) directory /var/lib/asterisk/static-http:
cd /usr/share/asterisk rmdir static-http ln -s /var/lib/asterisk/static-http static-http
When all is said and done (well, done, specifically), restart Asterisk. Asterisk-GUI should now be reachable on http://127.0.0.1:8088/asterisk/config/cfgbasic.html. Logging in there will make Asterisk-GUI configure itself and Asterisk.
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.