Today marks a couple of changes in our excellent Asterisk series. Up until now we've focused on Asterisk@Home. Asterisk@Home is great implementation, and plenty tough and feature-ful enough for even the most demanding enterprise. It's great for getting up and running quickly and learning the ins and outs of VoIPas well as integrating useful monitoring and management tools. However, the remainder of this series will cover the "real" Asterisk, because it is time to get under the hood and learn Asterisk's internals. It's important to understand Asterisk's configuration files, terminology, and protocols, because if you don't it will remain a mystery and things won't work right.
(Note: Asterisk@Home is undergoing a few changes as well. The name has changed to Trixbox and the project has moved to Trixbox.org. Everything you learned on Asterisk@Home still applies. There is one particularly noteworthy improvement, which was introduced in Asterisk@Home 2.8: an updating script. Previous versions required a complete rebuild to upgrade to a new version. Now upgrading is as easy as running the trixbox-update.sh command.)
Fire up the Linux system of your choice. Debian users have it easy, just run
# apt-get install asterisk
Just like Asterisk@Home/Trixbox, I'm using CentOS, which means a little more work to install Asterisk. Start with four tarballs; these are the current stable versions:
# tar zxvf asterisk-188.8.131.52.tar.gz
# tar zxvf asterisk-sounds-1.2.1.tar.gz
# tar zxvf zaptel-1.2.6.tar.gz
# tar zxvf libpri-1.2.3.tar.gz
Then review the various README files, and especially the SECURITY file in asterisk-184.108.40.206.
Now make sure you have the necessary programs installed for building applications from source code. On CentOS (and Red Hat and Fedora) install these packages:
# yum install gcc.i386 kernel-headers glibc-devel ncurses-devel openssl-devel zlib-devel
Install the Zaptel drivers first. Change to the zaptel-1.2.6 directory and run the make commands:
# cd /usr/src/zaptel-1.2.6
# make install
Now change to the libpri-1.2.3 source directory and run the make commands:
# cd /usr/src/libpri-1.2.3
# make install
Now change to the asterisk-220.127.116.11 source directory and run the make commands:
# cd /usr/src/asterisk-18.104.22.168
# make install
# make config
# make samples
For asterisk-sounds, just run make install.
If you run into problems and have to re-run make, be sure to run make clean first to clean up leftover object files.
Root user basics
You're going to be using two different command shells: the Linux Bash shell, and the Asterisk CLI (command-line interface.)
When you log into Linux, you can either log in as root directly, or log in as an ordinary user, then su to root. When you use su, add the - [hyphen] flag:
$ su -
This puts you into the root environment, with root's path and other environment variables. When you leave off the hyphen, you have rootly powers but the original user's environment, which means you have to type the entire command path- /usr/sbin/asterisk- instead of just asterisk. This happens because by default Red Hat does not put /usr/sbin in the path of non-root users. Run echo $PATH to see what your path is. This can be changed; just Google for "linux path" to learn how.
If you're still learning your way around Linux, remember this most basic safety principle: do nothing as root, except what you absolutely have to. This enchances security and saves you from your own mistakes.
Start up Asterisk
Fire up Asterisk this way:
# asterisk -cv
All kinds of output will come flying by, then it will stop at the Asterisk CLI (command-line interface.)
Type in the dial command, and if your machine has a soundcard, you'll get a pleasant tutorial on using Asterisk. Type help to see a list of commands. You can play around with them without hurting anything. The list is probably too long for your screen, so you can page up and down by holding down the Shift key and pressing Page Up/Page Down. Type help [commandname] to get information on specific commands.
You can run Linux shell commands from the Asterisk CLI without exiting; just prefix them with !, like this example shows:
Wed Jun 7 22:07:23 PDT 2006
Shutdown Asterisk with this command:
*CLI> shutdown gracefully
Just like in Linux's Bash shell, you can scroll to previously-entered commands with the up and down arrow keys.
Starting Asterisk at boot
The "make config" command installed a startup script, /etc/init.d/asterisk, so Asterisk will automatically start up at boot. You may also use this script to control Asterisk from the Linux command line:
# /etc/init.d/asterisk start # /etc/init.d/asterisk restart # /etc/init.d/asterisk stop # /etc/init.d/asterisk status
Starting Asterisk this way does not open the Asterisk CLI. Use asterisk -r to start it on a running Asterisk session, then type exit to get back to the Linux command line.
Next time, we'll dive into the basic Asterisk configuration files. Don't be scared by the number of them (take a peek in /etc/asterisk), as there are only a few we need to use. Come back next week to start learning how to be the master of Asterisk.
Check out the man pages for the various Linux and Asterisk commands, like man asterisk
The make and init scripts are in plain text; read them to learn more options
Asterisk Documentation Project has a downloadable free copy of the book "Asterisk: The Future of Telephony." It can also be purchased at the usual outlets. (Hint: supporting authors financially is a splendid thing to do.) This book is an essential reference, and contains all the Asterisk commands and configuration options.