Unlike my very first painful installs of Asterisk 1.0.9 on Fedora 4 in 2004, nowadays it is very easy to install Asterisk on almost any system. I did a brand new setup of Asterisk yesterday on CentOS, and noted down all the step both for my own reference and to help anybody who wants to do a similar install.
The setup included:
- MySQL
- PHP
- Tweaking of Apache
- Asterisk 1.4
- Asterisk-Addons 1.11
- Asterisk-MySQL Setup
- Asterisk Realtime Setup
- Munin Install and Setup
Make sure you server is connected to the Internet, as you”ll need to download stuff.
So here is how it goes:
Core Components Install
This setup assumes that you already have a CentOS 5.2 server setup. First download Asterisk and Asterisk Add-Ons to /usr/src folder
wget http://www.asterisk.org/downloads/asterisk/releases/asterisk-1.4-current.tar.gz wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-addons-1.4.11.tar.gz
Now install the following one by one, including setup MySQL:
yum install gcc yum install gcc-c++ yum install ncurses-devel yum install doxygen yum install mysql mysql-server mysql-devel mysql_secure_installation yum install php php-mysql
Finally install Asterisk. For this untar the downloaded asterisk source file, compile and install it. The steps are as follows. Note that in the following make menuselect will take you to a menu where you could select optional installation packages for Asterisk. I installed additional sounds through it. Rest of all the required stuff is already pre-selected.
cd /usr/src tar zxvf asterisk-current-tar.gz cd asterisk-1.4.35 ./configure make make menuselect make install make samples make progdocs cd .. rm asterisk-1.4.35 -fr
Now setup Asterisk Add-Ons package. You need it for Asterisk-MySQL interaction.
cd /usr/src tar zxvf asterisk-addons-1.4.11.tar.gz cd asterisk-1.4.11 ./configure make make install cd .. rm asterisk-1.4.11 -fr
This is all what is required to do the complete setup. There should be no errors faced during these steps.
Now install some more tools which you must have on your server:
Other Necessary Software and Munin
- Isn’t it a good idea to have OpenSSL installed:
yum install openssl - Install tcpdump to be able to sniff network traffic:
yum install tcpdump - Now install TFTP, you will need it for remote provisioning. Or you can ignore it if you won’t be doing any remote provisioning:
yum install tftp-server - If there is no FTP server installed, install it now:
yum install vsftpd - Sooner or later you’ll require to install perl anyways, so better install it now. Munin requires it which you’ll be installing next:
yum install perl
Isn’t it pretty much straight forward, using yum to install everything. However Munin, which is a must on any Linux server to monitor its health, is not available in CentOS repositories. There are some other repositories which include it, one of which is called dag. One option is to download Munin and install it manually, but I prefer to use yum. So setup dag repository as follows:
- Create a file named dag.repo in yum repositories folder:
vi /etc/yum.repos.d/dag.repo - Now paste the following text into it, followed by saving and exiting the file.
[dag]name=Dag RPM Repository for Red Hat Enterprise Linuxbaseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/daggpgcheck=1gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txtenabled=1
- Now install Munin simply by using yum:
yum install munin munin-node - Then there is iftop, a very useful graphical tool to see network activity:
yum install iftop
Now you have everything you need on your server, and what is left is its configuration. We’ll start with configuring Asterisk.
Configuring Asterisk
CDR
As we plan to store the CDR in a MySQL database, not in text file, so we need to first of all create a database to store it. I followed the instructions from the famous, one and only voip-info.org website (http://ilovetovoip.com/tM) and created a new MySQL user asterisk, database named `asterisk` and a table called `cdr` as follows:
CREATE DATABASE asterisk; GRANT INSERT ON asterisk.* TO asterisk@localhost IDENTIFIED BY 'asterisk'; USE asterisk; CREATE TABLE `cdr` ( `calldate` datetime NOT NULL default '0000-00-00 00:00:00', `clid` varchar(80) NOT NULL default '', `src` varchar(80) NOT NULL default '', `dst` varchar(80) NOT NULL default '', `dcontext` varchar(80) NOT NULL default '', `channel` varchar(80) NOT NULL default '', `dstchannel` varchar(80) NOT NULL default '', `lastapp` varchar(80) NOT NULL default '', `lastdata` varchar(80) NOT NULL default '', `duration` int(11) NOT NULL default '0', `billsec` int(11) NOT NULL default '0', `disposition` varchar(45) NOT NULL default '', `amaflags` int(11) NOT NULL default '0', `accountcode` varchar(20) NOT NULL default '', `userfield` varchar(255) NOT NULL default '' ); ALTER TABLE `cdr` ADD `uniqueid` VARCHAR(32) NOT NULL default ''; ALTER TABLE `cdr` ADD INDEX ( `calldate` ); ALTER TABLE `cdr` ADD INDEX ( `dst` ); ALTER TABLE `cdr` ADD INDEX ( `accountcode` );
Next is to update configuration file cdr_mysql.conf in /etc/asterisk folder, it should look like this:
[global] hostname=localhost dbname=asterisk table=cdr password=asterisk user=asterisk ;port=3306 ;sock=/tmp/mysql.sock ;userfield=1
And this is it. Your Asterisk is ready to roll. Create a dialplan in extensions.conf or extensions.ael, setup an extension in sip.conf, register a phone and test it.
ARA – Asterisk Real-Time Arhitecture
I prefer dynamic ARA over static text file architecture. Setting it up is pretty easy. All what is required is to setup tables in a MySQL database, uncomment necessary lines from the extconfig.conf file and update res_mysql.conf file.
res_mysql.conf should look like this:
[general] dbhost = 127.0.0.1 dbname = asteriskrealtime dbuser = asterisk dbpass = asterisk dbport = 3306 dbsock = /var/lib/mysql/mysql.sock ;sock=/tmp/mysql.sock
To setup tables in MySQL, first create a database, e.g. as we defined in the file above, name it `asteriskrealtime`. Once done, create all the following tables:
CREATE TABLE `asterisk`.`sip_buddies` ( `id` int(11) NOT NULL auto_increment, `name` varchar(80) NOT NULL default '', `accountcode` varchar(20) default NULL, `amaflags` varchar(7) default NULL, `callgroup` varchar(10) default NULL, `callerid` varchar(80) default NULL, `canreinvite` char(3) default 'yes', `context` varchar(80) default NULL, `defaultip` varchar(15) default NULL, `dtmfmode` varchar(7) default NULL, `fromuser` varchar(80) default NULL, `fromdomain` varchar(80) default NULL, `fullcontact` varchar(80) default NULL, `host` varchar(31) NOT NULL default '', `insecure` varchar(20) default NULL, `language` char(2) default NULL, `mailbox` varchar(50) default NULL, `md5secret` varchar(80) default NULL, `nat` varchar(5) NOT NULL default 'no', `deny` varchar(95) default NULL, `permit` varchar(95) default NULL, `mask` varchar(95) default NULL, `pickupgroup` varchar(10) default NULL, `port` varchar(5) NOT NULL default '', `qualify` char(3) default NULL, `restrictcid` char(1) default NULL, `rtptimeout` char(3) default NULL, `rtpholdtimeout` char(3) default NULL, `secret` varchar(80) default NULL, `type` varchar(6) NOT NULL default 'friend', `username` varchar(80) NOT NULL default '', `disallow` varchar(100) default 'all', `allow` varchar(100) default 'g729;ilbc;gsm;ulaw;alaw', `musiconhold` varchar(100) default NULL, `regseconds` int(11) NOT NULL default '0', `ipaddr` varchar(15) NOT NULL default '', `regexten` varchar(80) NOT NULL default '', `cancallforward` char(3) default 'yes', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), KEY `name_2` (`name`) ) ENGINE=MyISAM; CREATE TABLE `asterisk`.`extensions` ( `id` int(11) NOT NULL auto_increment, `context` varchar(20) NOT NULL default '', `exten` varchar(20) NOT NULL default '', `priority` tinyint(4) NOT NULL default '0', `app` varchar(20) NOT NULL default '', `appdata` varchar(128) NOT NULL default '', PRIMARY KEY (`context`,`exten`,`priority`), KEY `id` (`id`) ) ENGINE=MyISAM; CREATE TABLE `asterisk`.`voicemessages` ( `id` int(11) NOT NULL auto_increment, `msgnum` int(11) NOT NULL default '0', `dir` varchar(80) default '', `context` varchar(80) default '', `macrocontext` varchar(80) default '', `callerid` varchar(40) default '', `origtime` varchar(40) default '', `duration` varchar(20) default '', `mailboxuser` varchar(80) default '', `mailboxcontext` varchar(80) default '', `recording` longblob, PRIMARY KEY (`id`), KEY `dir` (`dir`) ) ENGINE=MyISAM; CREATE TABLE `asterisk`.`queues` ( `name` varchar(128) NOT NULL, `musiconhold` varchar(128) default NULL, `announce` varchar(128) default NULL, `context` varchar(128) default NULL, `timeout` int(11) default NULL, `monitor_type` varchar(50) NOT NULL, `monitor_format` varchar(128) default NULL, `queue_youarenext` varchar(128) default NULL, `queue_thereare` varchar(128) default NULL, `queue_callswaiting` varchar(128) default NULL, `queue_holdtime` varchar(128) default NULL, `queue_minutes` varchar(128) default NULL, `queue_seconds` varchar(128) default NULL, `queue_lessthan` varchar(128) default NULL, `queue_thankyou` varchar(128) default NULL, `queue_reporthold` varchar(128) default NULL, `announce_frequency` int(11) default NULL, `announce_round_seconds` int(11) default NULL, `announce_holdtime` varchar(128) default NULL, `retry` int(11) default NULL, `wrapuptime` int(11) default NULL, `maxlen` int(11) default NULL, `servicelevel` int(11) default NULL, `strategy` varchar(128) default NULL, `joinempty` varchar(128) default NULL, `leavewhenempty` varchar(128) default NULL, `eventmemberstatus` varchar(4) default NULL, `eventwhencalled` varchar(4) default NULL, `reportholdtime` tinyint(1) default NULL, `memberdelay` int(11) default NULL, `weight` int(11) default NULL, `timeoutrestart` tinyint(1) default NULL, `periodic_announce` varchar(50) default NULL, `periodic_announce_frequency` int(11) default NULL, `ringinuse` tinyint(1) default NULL, PRIMARY KEY (`name`) ) ENGINE=MyISAM CREATE TABLE `asterisk`.`queue_members` ( `uniqueid` int(10) unsigned NOT NULL auto_increment, `membername` varchar(40) default NULL, `queue_name` varchar(128) default NULL, `interface` varchar(128) default NULL, `penalty` int(11) default NULL, `paused` tinyint(1) default NULL, PRIMARY KEY (`uniqueid`), UNIQUE KEY `queue_interface` (`queue_name`,`interface`) ) ENGINE=MyISAM
Once the tables are created, you can open extconfig.conf file and uncomment the lines which refer to `sip_buddies`, `extensions` and any other tables you would be using in your setup. Usually sip_buddies and `voicemail_users` are the only table you will be using.
Now you can restart asterisk, and it is ready to use ARA.
MUNIN
Munin comes in pretty much pre-configured, but the only problem is that it doesn’t create the folder where it stores its graphs. That part you can do manually by first editing the /etc/munin.conf file and setting up the html folder to /var/www/html/munin and then doing the following:
cd /var/www/html mkdir munin rmdir /var/www/munin chown munin.munin service munin-node restart
Here you’d also need to update the /etc/
This is all what is required for Munin. In a few minutes you’ll have Munin graphs generated. You can see them through a web browser pointed to <your server’s IP address>/munin.



Zeeshan,
I would be better if you can update the tutorial for Asterisk 1.8.
The fact is that rock solid version of Asterisk is only 1.4, and that’s why its the one most widely deployed. Installing and configuring it on almost any system with all the well known packages is a breeze.
I stayed away from 1.6, and some time ago tried to migrate to 1.8, and had tons of issues. It wasted almost my whole day and I couldn’t make it work. I run production systems and can’t rely on 1.8 at this stage. So maybe one day I’ll write a tutorial for it, or some other version, but not at this stage.
Even I was of the same opinion.
But I have tried 1.8 for one of my productions and it seems to be working fine for the last 2 months. Not a single issue has been raised!
It has following features,
IVR,Queue, Call recording,Outbound,Mysql through ODBC, Transfer, AMI.
I have one more request for you to tell us hardware configurations and features for your already done deployments so that we can get some idea about scaling.
So many different configurations, I don’t even remember.
Have you also used the real-time architecture?
Yes, but it was only for Realtime Queue.
I asked for hardware configuration only because being not so good at asterisk dimensioning I have/had no idea what it would take to have around 200 Agents, 200 simultaneous calls(Dahdi 2 SIP), every call getting recorded, around 200 queues in an asterisk system.
BTW, let me tell you, you have been doing great job on your site as well as on Asterisk-users group.
Hi Zeeshan
you have syntax mistake in your Sql query for ARA … You forget semicolon at the end of lines number 109 and 121
Regards
Thanks for pointing this out, however where I copied this text from, didn’t have semicolons either. Plus I use the wonderful SQLyog to deal with MySQL databases, which also works just fine without semicolons. So I guess where they are required, the respective editors will throw an error and and user should be able to understand what went wrong. This type of installation is for those who already know these basics.
Dear Zeeshan,
It has been a long time since your last post on blog… It will be great if you start writing again .
I have been really busy lately. What you would like to read about?
Unfortunately I have no experience with FreeSwitch yet.
I would really love, if you can also write a scratch install for FreeSWITCH as well.
Thanks.