Install Asterisk (Securely) In 9 Steps

Submitted by leif.madsen on April 16, 2008 - 1:15pm.

Originally posted @ http://www.leifmadsen.com

I normally do all of this in virtual machines on a development server I use to test Asterisk, build projects, perform development -- lots of things related to Asterisk. So in doing this, I've gotten pretty good at getting a brand new, running Asterisk system up quickly. Hopefully this information helps you realize just how easy it is to install Asterisk from source and start playing yourself!

Note that these instructions assume you are running on CentOS 5.x. The reason for CentOS is that it is a derivative of RedHat Enterprise Linux (RHEL), is greatly supported, and contains a syntax familiar to many, and simple for those new to it. It is my preferred distribution, although I'm sure there are similar instructions for Debian, Mandrake, SuSE, et al.

1) Get CentOS

You can download CentOS from http://www.centos.org. At the top there is a 'mirrors' link. Select it, and download the first disk of a CentOS 5.x release (5.1 at the time of this writing). Get the ISO, and download it to a computer which has a CD burner. Burn the disk and find a computer that you can play with. You can use either the i386 or x86_64 (32-bit or 64-bit respectively), per your hardware.

2) Install CentOS

These instructions couldn't be simpler. Install using as many default configurations as you can. More than likely your network uses DHCP and configures your network for you, and your hardware is supported natively by the distribution. Leave as much as default as possible.

One section where you want to make sure you do change something is in the package selection. When you get that far, deselect everything. Make sure you select 'Customize now' as a radio button at the bottom of the group package selection screen. Verify you've deselected any default package selections.

On the next screen, scroll through each package group and make sure everything is deselected. Yes, I really mean that. You don't need much for Asterisk, and what you DO need we're going to install specifically because Asterisk needs it. This box could be suitable for production.

3) Perform An Update

As soon as the box boots up, we want to update the system. Perform the following command as root:

# yum update -y && reboot

The system will update and reboot automatically, thereby verifying you're running the latest Linux kernel.

4) Install Asterisk Dependencies

Next thing we're going to do is install the dependencies for the most common elements used in Asterisk. Future articles will explore how to build addition aspects of Asterisk based on this minimal install. Many people may never need anything in addition to what is installed here, and so is a good start. Lets install several packages now which will allow us to obtain, compile, and install Asterisk. We'll be using Subversion to get the source code, and the rest of the packages will be used to build Asterisk.

Required for Asterisk:

# yum install subversion gcc gcc-c++ unixODBC-devel libtool-ltdl-devel libtermcap-devel newt-devel ncurses-devel -y

Required for libPRI:
Nothing is required additionally for libPRI

Required for Zaptel:

# yum install kernel-devel -y

5) Add An asterisk User

We don't want to run Asterisk as root, so lets run it as its own user!

# adduser asterisk

Set the password for the 'asterisk' user as appropriate.

# passwd asterisk

And switch to the new 'asterisk' user where we'll perform all the following commands.

# su - asterisk

6) Get Asterisk, libPRI, and Zaptel

First, make a small little directory stucture to store the source code. This is useful on production systems because when you do need to perform an upgrade (after you tested on your development boxes right?!), so that you can easily revert if need be. Reverting should just require a 'make install' from the appropriate directory.

$ mkdir -p asterisk/src/1.4
$ cd asterisk/src/1.4
$ svn co http://svn.digium.com/svn/asterisk/branches/1.4 ./asterisk-1.4-branch-vanilla
$ svn co http://svn.digium.com/svn/libpri/branches/1.4 ./libpri-1.4-branch-vanilla
$ svn co http://svn.digium.com/svn/zaptel/branches/1.4 ./zaptel-1.4-branch-vanilla

Note that for a real production system you'll want to use the latest release version of Asterisk. You can also checkout the tagged (released) versions of Asterisk using a similar command:

$ svn co http://svn.digium.com/svn/asterisk/tags/1.4.19 ./asterisk-1.4.19-vanilla

You can see the valid tags by listing all the valid tags in the tags directory:

$ svn list http://svn.digium.com/svn/asterisk/tags

7) Configure, Compile, and Install

We're going to install libPRI and Zaptel before Asterisk (in that order). Before we get to Asterisk, lets compile and install libPRI.

The following will compile libPRI.

$ cd libpri-1.4-branch-vanilla
$ make

To install the libPRI libraries, we need to go back to 'root'

$ exit
# cd /home/asterisk/asterisk/src/1.4/libpri-1.4-branch-vanilla
# make install

Now lets compile Zaptel as the 'asterisk' user

# su - asterisk
$ cd asterisk/src/1.4/zaptel-1.4-branch-vanilla
$ ./configure

I don't normally install any Zaptel drivers except ztdummy because I'm usually running this in a virtual machine, but configure appropriately for your configuration:

$ make menuselect

And now lets compile Zaptel:

$ make

And now we can install the drivers as 'root'

$ exit
# cd /home/asterisk/asterisk/src/1.4/zaptel-1.4-branch-vanilla
# make install

In order to make Zaptel drivers load at bootup, run the following:

# make config

Lets configure and install Asterisk now!

# su - asterisk
$ cd asterisk-1.4-branch-vanilla
$ ./configure --prefix=$HOME/asterisk/bin --localstatedir=$HOME/asterisk/bin --sysconfdir=$HOME/asterisk/bin
$ make menuselect

Once you've entered menuselect, feel free to adapt Asterisk to suit your needs, but if you just want the default, then press 'x' to save and exit.

$ make install

If you don't have an existing configuration, you can start with the samples

$ make samples

8) Putting It All Together

In order to have some of the niceties such as having Asterisk run on startup, and putting the configuration files in a well known location, lets doing a couple things as 'root'.

$ exit
# cd /home/asterisk/asterisk/src/1.4/asterisk-1.4-branch-vanilla

We can easily start and stop Asterisk, plus make it come up automatically on startup, and cleanly shutdown on reboot or poweroff like so:

# make config

We then need to configure the init.d script

# cd /etc/init.d/
# vi asterisk

Around line 27 there are 3 variables that need to be modified

* AST_SBIN
* AST_USER
* AST_GROUP

Modify AST_SBIN to: AST_SBIN=/home/asterisk/asterisk/bin/sbin

Then uncomment AST_USER and AST_GROUP.

I also like to create a symlink to /etc/asterisk/ for the configuration files since that is a common place for them to reside, and is a little easier to type than /home/asterisk/asterisk/bin/asterisk/.

So let's create the symlink:


# ln -s /home/asterisk/asterisk/bin/asterisk /etc/asterisk

One last thing to configure as root is the /etc/sysconfig/zaptel file. Go through the file and just make sure everything is commented out (the '#' character is used to comment out lines in the file), and that the 'ztdummy' driver is uncommented. This assumes you have no hardware, so configure as appropriate.

One last thing we need to modify is the /etc/asterisk/asterisk.conf file so that we can tell Asterisk where to find many of the files it uses. Lets do this as the 'asterisk' user.


# su - asterisk
$ vim /etc/asterisk/asterisk.conf

And modify the file to look like the following:


[directories]
astetcdir => /etc/asterisk
astmoddir => /home/asterisk/asterisk/bin/lib/asterisk/modules
astvarlibdir => /home/asterisk/asterisk/bin/lib/asterisk
astdbdir => /home/asterisk/asterisk/bin/lib/asterisk
astkeydir => /home/asterisk/asterisk/bin/lib/asterisk
astdatadir => /home/asterisk/asterisk/bin/lib/asterisk
astagidir => /home/asterisk/asterisk/bin/lib/asterisk/agi-bin
astspooldir => /home/asterisk/asterisk/bin/spool/asterisk
astrundir => /home/asterisk/asterisk/bin/run
astlogdir => /home/asterisk/asterisk/bin/log/asterisk

9) Start Asterisk And Connect to the Console

Before starting Asterisk, lets start the Zaptel drivers for timing as the 'root' user:


$ exit
# service zaptel start

Now su back to your 'asterisk' user, and try connecting to the console:

# su - asterisk
$ ./asterisk/bin/sbin/asterisk -rvvv

You should now be prompted with the Asterisk command line interface!

If you want to start Asterisk up with the init.d script now that you've verified Asterisk is starting without any major errors, then you can do that now:


$ exit
# service asterisk start

Finishing Notes

And that's pretty much it, a simple set of steps you can follow to get a production ready Asterisk system running as non-root! I've tried to test these steps as I went through writing this article, but if you find any errors, please do comment so I can correct anything I missed. Thanks for reading!

Leif Madsen.

Author: desprado7 (not verified)
April 28, 2010 - 2:08am

And finally, to the purpose of the article...the bulk export of all your vcards at once. The macro Export_PAB_to_vcfs does exactly that. It exports your entire address book to a series of accuplacer vcards. Configuration: First find the line in each macro starting with "MyFolder1" and configure it to your mailbox name. It may be "Personal Folder". This matches my exchange folder name. Secondly, the location you export to. Search for acsm "myContactsVCard" and change it to the location of your choice. The caveat of this (or more specifically of Outlook) is that it only exports a version 2.1 of the vcard standard meaning it doesn't store the categories in the vcard - this act may or may not be important to you. If it is, 4Team's VSync may be for you. I use it now because of it does category export (it's vcard version 3). Identical function to this macro (albeit prettier interface, menu access - though that's possible with this macro too with 5 seconds of programming - and aepa easily adjustable folder - again, possible with the macro with 5 minutes of programming)