Installing asterisk 10 realtime
2012-09-04 11:28 by Ian
Pre-requisites and forward
This is a brief guide to setting up asterisk on a generic linux host. This particular guide was written using CentOS 6. The process and configuration have been checked for accuracy on CentOS 6, Debian, and Gentoo. I have tried to indicate steps where such differences are relevant,- A resonably recent linux installation.
- Depending on several factors, your hardware requirements will vary. I have implemented similarly-configured builds of asterisk on hardware as limited as a Raspberry Pi with good results.
- About 3 hours, depending on how fast your box can compile.
Helpful resources:
Asterisk can be an intimidating package. It helps to have read some introductory material first. O'Reilly Media has delivered, and made freely-available Asterisk™: The Definitive Guide. It is worth the time you spend to read it cover-to-cover.
Once you have the basics under control, there is The Asterisk Documentation. When in doubt, those pages are canon.
Installation
Initial System Setup
Be advised… You will need to adjust this command to your distro. Debian has a very similar tool called apt-get, arch uses pacman, and gentoo uses portage.
Also, for CentOS users: if you are on a Xen VM, you will need to fetch kernel-xen-devel, rather than kernel-devel.
Also, for CentOS users: if you are compiling on x86_64, you will probably need to soft-link your MySQL libraries to /usr/lib/mysql. CentOS is somewhat dumb about which libs get installed. Usually it will install both i386 and x86_64 unless you specify which you want. LD is somewhat dumb about which libs to use if both are present. So make sure the only ones that get installed are the ones that match your architecture. I have not encountered this problem on any other distribution.
Also, for CentOS users: if you are on a Xen VM, you will need to fetch kernel-xen-devel, rather than kernel-devel.
Also, for CentOS users: if you are compiling on x86_64, you will probably need to soft-link your MySQL libraries to /usr/lib/mysql. CentOS is somewhat dumb about which libs get installed. Usually it will install both i386 and x86_64 unless you specify which you want. LD is somewhat dumb about which libs to use if both are present. So make sure the only ones that get installed are the ones that match your architecture. I have not encountered this problem on any other distribution.
Some of this is my personal taste. If your server is going to be exposed to the internet, I would strongly recommend fail2ban, for instance. You know what's best for your box, but HDD is cheap these days, so rock on...
yum install mysql mysql-server mysql-devel curl curl-devel kernel-headers openssl openssl-devel speex speex-devel php php-bcmath php-gd php-imap php-mbstring php-mcrypt php-mysql php-odbc mysql-connector-odbc unixODBC-devel unixODBC flac libvorbis libvorbis-devel alsa-lib-devel alsa-lib alsa-utils httpd kernel-devel gcc make gcc-c++ libxml2 libxml2-devel bzip2-devel bzip2 perl ncurses-devel libtool-ltdl-devel libao-devel libao monit vsftpd subversion fail2ban sqlite-devel sqlite mlocate mod_ssl
That about covers the software that is typically available from baseline repositories. For CentOS (and I'm sure other distros) there exist binary repositories aimed at asterisk users. That being said, there are numerous advantages to building your own binaries, and I will continue assuming you are doing this.
Building the non-repo software
Using a telco interface card? Not without DAHDI, you aren't:
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/releases/dahdi-linux-complete-2.6.1+2.6.1.tar.gz tar zxvf dahdi-linux-* cd dahdi-linux-* make make install cd ..
Note that the MeetMe conferance bridge also requires DAHDI, but asterisk 10 has deprecated MeetMe in favor of a new conferance bridge that takes better advantage of the extended media system. The new bridge does not require DAHDI.
Most casual users of VoIP don't understand that it is not simply SIP. SIP is the control and session-initiation channel. The actual stream that carries the voice (or video) is actually called RTP (Realtime Transport Protocol). If you want your communication to be encrypted, you will need to install the SRTP library...
wget http://srtp.sourceforge.net/srtp-1.4.2.tgz tar zxvf srtp-1.4.2.tgz cd srtp ./configure make CFLAGS=-fPIC make install cd ..
Jabber support (and arbitrary handset-to-handset messages) needs a special XML library:
wget http://iksemel.googlecode.com/files/iksemel-1.4.tar.gz tar zxvf iksemel-1.4.tar.gz cd iksemel-1.4 ./configure make make install cd ..
The speex codec was split into two packages for the 1.2 release. If you want to compile Asterisk against it, you will need to download the source from xiph.org and install it yourself…
wget http://downloads.xiph.org/releases/speex/speex-1.2rc1.tar.gz tar zxvf speex-1* cd speex-1* ./configure
Optionally, setup vsftpd and disable anonymous login…
vi /etc/vsftpd/vsftpd.conf
If you are going to be using FTP to upload to the new server, you will need to disable SELinux...
vi /etc/selinux/config
Change this line…
SELINUX=enforcingTo this…
SELINUX=permissive
Add our basic services to the group of services to be launched on startup…
chkconfig monit on chkconfig mysqld on chkconfig vsftpd on chkconfig httpd on
Configure asterisk
The first step is to download asterisk. While you are there, have a look at their other packages and decide if you need any of them.
Once you have the tarball, extract it and enter the directory.
I will usually run the script to download the third-party mp3 CODEC at this point.
cd asterisk* ./configure contrib/scripts/get_mp3_source.sh make menuconfig
There are numerous configuration options for the build. If you want database-driven configuration, CDR, and Voicemail, you will need to select those things at this step. Also, you can opt to download sound-packages. Once you have finished choosing the particulars of your build, compile asterisk. If you have a multicore CPU, I would highly recommend the "-j
make -j4
If that worked with no complaints, you can now install asterisk with....
make install
If you are doing this for the first time, you might want to...
make samples...to build the example configuration files. We will be replacing most of these later, but the samples have lots of excellent documentation in them. They will also give you an idea about possibilities that you may not have imagined before.
If you want SILK support, go here and select the binary that most-closely matches your architecture, and copy it into your asterisk module directory.
At this point I also configure monit to keep the service alive.
Create a new file….
vi /etc/monit.d/asterisk.monit…and into it, paste this…
check process asterisk with pidfile /var/run/asterisk/asterisk.pid start program = "/usr/sbin/asterisk_start" stop program = "/usr/sbin/asterisk_stop"
Now, create the wrapper scripts that are referenced in the above monit define…
The startup script...
touch /usr/sbin/asterisk_start chmod +x /usr/sbin/asterisk_start vi /usr/sbin/asterisk_start
#!/bin/bash nohup asterisk 2>&1 &
And my corresponding shutdown script...
touch /usr/sbin/asterisk_stop chmod +x /usr/sbin/asterisk_stop vi /usr/sbin/asterisk_stop
#!/bin/bash asterisk -rx "core stop now"
Configuring asterisk
A brief aside on how I have configured asterisk
There is much documentation and many forum posts over the past 8 years and 5 major asterisk versions. The most reliable documentation I've found has been the extensive commentary present in many of the configuration files for the version in question. Most of the options in the config files seem to be transposable into the database (at least, those that I have tried thus far). For the purposes of this page, I have built asterisk to store VoiceMail, CDR (Call Detail Records), and SIP users in the database. The database definition for the SIP users was arrived at via a great deal of trial and error. It is known to be compatible with asterisk 1.8, and there appears to be leniency with respect to the number of fields from sip.conf that are reflected in the DB. Any fields defined in the table must have the same name as the field in sip.conf. The sip.conf file is still loaded and used, but any of the fields that are also defined in the database will override the values given in the conf file.
All of that being said, my database definition is given here (ast_table_defs.sql). If you wish to replicate my configuration, you will need this file later.
My sip.conf file reads thusly (/etc/asterisk/sip.conf):
[general] context=default ; Default context for incoming calls allowguest=no ; Allow or reject guest calls (default is yes) allowoverlap=no ; Disable overlap dialing support. (Default is yes) tcpenable=yes ; Enable server for incoming TCP connections (default is no) udpbindaddr=0.0.0.0 ; IP address to bind UDP listen socket to (0.0.0.0 binds to all) tcpbindaddr=0.0.0.0 ; IP address for TCP server to bind to (0.0.0.0 binds to all interfaces) bindport=5060 srvlookup=yes ; Enable DNS SRV lookups on outbound calls engine=asterisk ; RTP engine to use when communicating with the device
If you downloaded the SILK module earlier, you should make sure that something to this effect resides in your codecs.conf file (/etc/asterisk/codecs.conf):
[silk8] type=silk samprate=8000 fec=true packetloss_percentage=10 maxbitrate=20000 dtx=false [silk12] type=silk samprate=12000 fec=true packetloss_percentage=10 maxbitrate=25000 dtx=false [silk16] samprate=16000 fec=true packetloss_percentage=10 maxbitrate=30000 dtx=false [silk24] samprate=24000 fec=true packetloss_percentage=10 maxbitrate=40000 dtx=false
Creating the database
First we should start the mysql service and set a password. Typically, we will also want the DB to start on boot.
service mysqld start mysqladmin -u root password 'change_this_to_your_password' chkconfig --level 2345 mysqld on
Now we need to open the MySQL console and create users, DB's, and permissions.
mysql -u root -p
Once logged into the mysql server, we need to define our DB. I usually....
source ast_table_defs.sql...where ast_table_defs.sql is the file you may have downloaded earlier. I decline to paste this file text here, because it is too large to paste into an SSH window for most clients.
Add yourself a user, and also one for the local asterisk user.
Depending on your MySQL version, these queries may fail because they contain the wrong number of fields for the user table. If anyone explains why, I can fix the queries and remove this box. :-)
USE mysql; insert into user values ('localhost','asterisk',PASSWORD('PLAINTEXT_PASSWORD'),'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0), ('%','asterisk',PASSWORD('PLAINTEXT_PASSWORD'),'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0); insert into db values ('localhost','ast_db','asterisk','Y','Y','Y','Y','Y','N','N','Y','Y','Y','Y','Y','Y','Y','N','N','N','N','N'), ('%','ast_db','asterisk','Y','Y','Y','Y','Y','N','N','Y','Y','Y','Y','Y','Y','Y','N','N','N','N','N'); FLUSH PRIVILEGES;
Configure ODBC
Next, we need to setup ODBC so that Asterisk can use MySQL…
This is written with CentOS 6 in mind. Gentoo does the ODBC dance a little differently. I recommend that if these instructions do not work on your gentoo build, review This section of the ODBC documentation, and verify that your odbc.ini and odbcinst.ini files are being read from /etc/, and not /etc/unixODBC. If the latter, adjust your paths appropriately. Also verfiy that the driver name in your DSN matches the MySQL driver's name in odbcinst.ini.
vi /etc/odbc.ini
[asterisk] Description=Asterisk config and log. Driver=MySQL Server=localhost Database=ast_db User=asterisk Password=PLAINTEXT_PASSWORD Port=3306 Option=3
Next, we need to tell Asterisk which data it should look for in the DB, and the names of the tables in which it is stored…
vi /etc/asterisk/extconfig.conf
[settings] sipusers => odbc,asterisk,sipfriends sippeers => odbc,asterisk,sipfriends voicemail => odbc,asterisk,voiceboxes
OBDC Resource config file…
vi /etc/asterisk/res_odbc.conf
[ENV] [asterisk] enabled => yes dsn => asterisk username => asterisk password => PLAINTEXT_PASSWORD pre-connect => yes sanitysql => select 1 idlecheck => 3600 share_connections => yes backslash_is_escape => no
MySQL Config File…
vi /etc/asterisk/res_config_mysql.conf
[general] dbhost = 127.0.0.1 dbname = ast_db dbuser = asterisk dbpass = PLAINTEXT_PASSWORD dbport = 3306 dbsock = /tmp/mysql.sock dbcharset = latin1
Add a few users...
All of this work will be completely useless without users. Let's add 4 of them for now. Log back into MySQL and run this query to insert 4 users...
USE ast_db; INSERT INTO `voiceboxes` VALUES (4,'103','default','103','1234',NULL,NULL,NULL,'central','yes','yes',NULL,NULL,'no','no','no','no',1,'no','no','yes','no','no','yes','2012-01-26 20:27:01'), (3,'102','default','102','1234',NULL,NULL,NULL,'central','yes','yes',NULL,NULL,'no','no','no','no',1,'no','no','yes','no','no','yes','2012-01-26 20:27:01'), (2,'101','default','101','1234',NULL,NULL,NULL,'central','yes','yes',NULL,NULL,'no','no','no','no',1,'no','no','yes','no','no','yes','2012-01-26 20:27:01'), (1,'100','default','100','1234',NULL,NULL,NULL,'central','yes','yes',NULL,NULL,'no','no','no','no',1,'no','no','yes','no','no','yes','2012-01-26 20:27:01'); INSERT INTO `sipfriends` VALUES (1,'100','',0,'100',NULL,NULL,'',0,'dynamic','peer','users',NULL,NULL,'PASS0',NULL,NULL,NULL,'inband','no','comedia',NULL,NULL,'en','gsm;speex;ulaw;alaw;ilbc;speex16',NULL,NULL,'no',NULL,NULL,NULL,NULL,NULL,'Ext 100',NULL,NULL,NULL,'no',NULL,NULL,NULL,NULL,'100@novoicemail.com',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'no',NULL,30,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'no','no',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,5,NULL,NULL,NULL,NULL,NULL,'yes'), (2,'101','',0,'101',NULL,NULL,'',0,'dynamic','peer','users',NULL,NULL,'PASS1',NULL,NULL,NULL,'inband','no','comedia',NULL,NULL,'en','gsm;speex;ulaw;alaw;ilbc;speex16',NULL,NULL,'no',NULL,NULL,NULL,NULL,NULL,'Ext 101',NULL,NULL,NULL,'no',NULL,NULL,NULL,NULL,'101@novoicemail.com',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'no',NULL,30,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'no','no',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,5,NULL,NULL,NULL,NULL,NULL,'yes'), (3,'102','',0,'102',NULL,NULL,'',0,'dynamic','peer','users',NULL,NULL,'PASS2',NULL,NULL,NULL,'inband','no','comedia',NULL,NULL,'en','gsm;speex;ulaw;alaw;ilbc;speex16',NULL,NULL,'no',NULL,NULL,NULL,NULL,NULL,'Ext 102',NULL,NULL,NULL,'no',NULL,NULL,NULL,NULL,'102@novoicemail.com',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'no',NULL,30,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'no','no',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,5,NULL,NULL,NULL,NULL,NULL,'yes'), (4,'103','',0,'103',NULL,NULL,'',0,'dynamic','peer','users',NULL,NULL,'PASS3',NULL,NULL,NULL,'inband','no','comedia',NULL,NULL,'en','gsm;speex;ulaw;alaw;ilbc;speex16',NULL,NULL,'no',NULL,NULL,NULL,NULL,NULL,'Ext 103',NULL,NULL,NULL,'no',NULL,NULL,NULL,NULL,'103@novoicemail.com',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'no',NULL,30,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'no','no',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,5,NULL,NULL,NULL,NULL,NULL,'yes');
Define a simple dial-plan...
The dial-plan (/etc/asterisk/extensions.conf) on one of my test machines reads like this:
[stations] exten => _1XX,1,Wait(2) exten => _1XX,n,Set(DIALEDEXT=${EXTEN}) exten => _1XX,n,Dial(SIP/${DIALEDEXT},20) exten => _1XX,n,Goto(${DIALSTATUS},1) exten => _1XX,n,Hangup exten => ANSWER,1,Hangup() exten => CANCEL,1,Hangup() exten => NOANSWER,1,Voicemail(${DIALEDEXT}@default,u) exten => NOANSWER,n,Hangup() exten => BUSY,1,Voicemail(${DIALEDEXT}@default,b) exten => BUSY,n,Hangup() exten => CONGESTION,1,Voicemail(${DIALEDEXT}@default,u) exten => CONGESTION,n,Hangup() exten => CHANUNAVAIL,1,Voicemail(${DIALEDEXT}@default,u) exten => CHANUNAVAIL,n,Hangup() [voicemail] exten => 000,1,Wait(1) exten => 000,n,VoicemailMain(${CALLERID(num)}@default,a) exten => 000,n,Hangup [users] include => voicemail include => stations
The setup is simple. Four SIP users with voice mail. No conference rooms. No trunking. Whole applications can be written here, and this topic will be covered here in the future. But not now.
Test the installation
Run asterisk in (5)very verbose mode:
asterisk -cvvvvv
Examine the output for WARNING tags. If your scrollback buffer isn't large enough, the same output will be appended to the asterisk log file, which can be tailed in this way:
tail -f /var/log/asterisk/messages
Some general tips and a command cheat sheet:
core show translation
Performance notes:
ARM6 (Raspberry Pi)
core show translation Translation times between formats (in microseconds) for one second of data Source Format (Rows) Destination Format (Columns) gsm ulaw alaw g726 adpcm slin lpc10 speex speex16 ilbc g726aal2 g722 slin16 testlaw speex32 slin12 slin24 slin32 slin44 slin48 slin96 slin192 gsm - 15000 15000 15000 15000 9000 15000 15000 23000 15000 15000 17250 17000 15000 23000 17000 17000 17000 17000 17000 17000 17000 ulaw 15000 - 9150 15000 15000 9000 15000 15000 23000 15000 15000 17250 17000 15000 23000 17000 17000 17000 17000 17000 17000 17000 alaw 15000 9150 - 15000 15000 9000 15000 15000 23000 15000 15000 17250 17000 15000 23000 17000 17000 17000 17000 17000 17000 17000 g726 15000 15000 15000 - 15000 9000 15000 15000 23000 15000 15000 17250 17000 15000 23000 17000 17000 17000 17000 17000 17000 17000 adpcm 15000 15000 15000 15000 - 9000 15000 15000 23000 15000 15000 17250 17000 15000 23000 17000 17000 17000 17000 17000 17000 17000 slin 6000 6000 6000 6000 6000 - 6000 6000 14000 6000 6000 8250 8000 6000 14000 8000 8000 8000 8000 8000 8000 8000 lpc10 15000 15000 15000 15000 15000 9000 - 15000 23000 15000 15000 17250 17000 15000 23000 17000 17000 17000 17000 17000 17000 17000 speex 15000 15000 15000 15000 15000 9000 15000 - 23000 15000 15000 17250 17000 15000 23000 17000 17000 17000 17000 17000 17000 17000 speex16 23500 23500 23500 23500 23500 17500 23500 23500 - 23500 23500 15000 9000 23500 23000 17500 17000 17000 17000 17000 17000 17000 ilbc 15000 15000 15000 15000 15000 9000 15000 15000 23000 - 15000 17250 17000 15000 23000 17000 17000 17000 17000 17000 17000 17000 g726aal2 15000 15000 15000 15000 15000 9000 15000 15000 23000 15000 - 17250 17000 15000 23000 17000 17000 17000 17000 17000 17000 17000 g722 15600 15600 15600 15600 15600 9600 15600 15600 15000 15600 15600 - 9000 15600 23000 17500 17000 17000 17000 17000 17000 17000 slin16 14500 14500 14500 14500 14500 8500 14500 14500 6000 14500 14500 6000 - 14500 14000 8500 8000 8000 8000 8000 8000 8000 testlaw 15000 15000 15000 15000 15000 9000 15000 15000 23000 15000 15000 17250 17000 - 23000 17000 17000 17000 17000 17000 17000 17000 speex32 23500 23500 23500 23500 23500 17500 23500 23500 23500 23500 23500 23500 17500 23500 - 17500 17500 9000 17000 17000 17000 17000 slin12 14500 14500 14500 14500 14500 8500 14500 14500 14000 14500 14500 14000 8000 14500 14000 - 8000 8000 8000 8000 8000 8000 slin24 14500 14500 14500 14500 14500 8500 14500 14500 14500 14500 14500 14500 8500 14500 14000 8500 - 8000 8000 8000 8000 8000 slin32 14500 14500 14500 14500 14500 8500 14500 14500 14500 14500 14500 14500 8500 14500 6000 8500 8500 - 8000 8000 8000 8000 slin44 14500 14500 14500 14500 14500 8500 14500 14500 14500 14500 14500 14500 8500 14500 14500 8500 8500 8500 - 8000 8000 8000 slin48 14500 14500 14500 14500 14500 8500 14500 14500 14500 14500 14500 14500 8500 14500 14500 8500 8500 8500 8500 - 8000 8000 slin96 14500 14500 14500 14500 14500 8500 14500 14500 14500 14500 14500 14500 8500 14500 14500 8500 8500 8500 8500 8500 - 8000 slin192 14500 14500 14500 14500 14500 8500 14500 14500 14500 14500 14500 14500 8500 14500 14500 8500 8500 8500 8500 8500 8500 -
Previous: Automotive Isolation Box
Next: Building a FIPS capable OpenSSL (Gentoo)