Installing Asterisk VoIP Server from Sources
The mission is to install and configure corporate VoIP server with a few E1 flows, to store logs in a MySQL base, to configure the calls statistics and fax-machines pool.
I tryed to realize it with a lot of platforms: FreeBSD, CentOS, Trixbox, AsteriskNOW, Elastix, Akozia... but there were something wrong in each case.
Finally I chose the Ubuntu Server.
1. Asterisk
Install Asterisk with LAMP and OpenSSH, then upgrade it and install all basic software.
# aptitude update
# aptitude upgrade
# aptitude install make gcc cpp g++ linux-headers-`uname -r` bison ncurses-dev mysql-client libmysqlclient-dev libnewt-dev php5-gd libxml2 libxml2-dev mc htop
Usually I install asterisk & dahdi from source codes in spite of repository installation, because it's most flexible variant.
# wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-l...
# wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-1...
# wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-a...
# wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4.10.2.tar.gz
Unpack files to /usr/src and than compile them.
Libpri:
# cd /usr/src/libpri-1.4.10.2/
# make
# make install
Dahdi:
# cd /usr/src/dahdi-linux-complete-2.2.1-rc2+2.2.1-rc2/
# make all
# make install
# make config
Asterisk:
# cd /usr/src/asterisk-1.6.2.0/
# ./configure
# make menuselect
# make
# make install
It's optional:
# make samples
But it's necessary:
# make configure
Asterisk addons:
# ./configure
# make menuselect
# make
# make install
Let's configure Dahdi:
# dahdi_genconf
# cat /etc/dahdi/system.conf
span=1,1,0,ccs,hdb3,crc4
bchan=1-15
echocanceller=mg2,1-15
dchan=16
bchan=17-21
echocanceller=mg2,17-21
loadzone = us
defaultzone=us
span=2,0,0,ccs,hdb3
bchan=32-46
dchan=47
echocanceller=mg2,32-46
# nano /etc/asterisk/chan_dahdi.conf
[channels]
switchtype=euroisdn
pridialplan=unknown
prilocaldialplan=national
resetinterval = 100000000
facilityenable = yes
signalling=pri_cpe
rxwink=300
usecallerid=yes
cidsignalling=bell
cidstart=ring
hidecallerid=no
callwaiting=yes
usecallingpres=yes
sendcalleridafter=1
callwaitingcallerid=yes
threewaycalling=yes
transfer=yes
canpark=yes
cancallforward=yes
callreturn=yes
echocancel=yes
echocancelwhenbridged=yes
echotraining=800
relaxdtmf=yes
rxgain=0.0
txgain=0.0
group=1
context=from_prov1
immediate=no
channel=>1-15,17-21
mohsuggest=default
group=2
context=from_prov2
immediate=no
channel=>32-46
mohsuggest=default
Configure Your type of Digium card (comment unused cards).
# nano /etc/dahdi/modules
wct4xxp
# /etc/init.d/dahdi restart
# /etc/init.d/asterisk restart
or
# reboot
Than check if dahdi has loaded correctly:
# lsmod | sort
crc_ccitt 2336 1 dahdi
dahdi 214768 126 dahdi_echocan_mg2,wct4xxp
dahdi_echocan_mg2 6952 64
...
wct4xxp 253984 62
Another checks:
# dahdi_cfg -vvvvvv
# dahdi_scan
Now you need to configure main asterisk files: sip.conf & extensions.conf.
If you don't know how to do it, you should read The Future of Telephony book.
Start asterisk and check if it works correctly:
# /etc/init.d/asterisk start
# ps aux | grep asterisk
root 11277 2.7 0.9 669468 29000 ? Ssl Mar12 277:25 /usr/sbin/asterisk
# asterisk -r
2. Fax
Let's install a fax bundle:
# aptitude install hylafax-serveк hylafax-client iaxmodem
Make a few modems:
# nano /etc/iaxmodem/ttyIAX0
device /dev/ttyIAX0
owner uucp:uucp
mode 660
port 4570
refresh 50
server 127.0.0.1
peername iaxmodem
secret password
codec alaw
cidname Company
cidnumber +7(812)1111111
Do required number of times:
# cd /etc/iaxmodem
# cp ttyIAX0 ttyIAX1
....
Start iaxmodem:
# /etc/init.d/iaxmodem start
Chesk the virtual modems:
# ls /dev | grep ttyIAX
ttyIAX0
ttyIAX1
....
Configure an interaction with Hylafax:
# faxsetup
Do it for every virtual modem:
# faxaddmodem
Configure Asterisk:
# nano /etc/asterisk/iax.conf
[general]
bindport = 4569
bindaddr = 0.0.0.0
disallow=all
allow=ulaw
allow=alaw
[iaxmodem]
type=friend
secret=password
port=4570
host=dynamic
context=office
disallow=all
allow=alaw
[iaxmodem1]
type=friend
secret=password
port=4580
host=dynamic
context=sklad
disallow=all
allow=alaw
# cat /etc/asterisk/sip.conf
...
[111]
type=friend
context=main
secret=111
callerid="FAX-Office"<111>
nat=yes
host=dynamic
qualify=yes
[222]
type=friend
context=branch
secret=222
callerid="FAX-Sklad"<222>
nat=yes
host=dynamic
qualify=yes
....
# cat /etc/asterisk/extensions.conf
exten => 111,1,Dial(IAX2/iaxmodem)
exten => 222,1,Dial(IAX2/iaxmodem1)
....
For e-mail fax sending:
# cat /etc/hylafax/FaxDispatch
case "$DEVICE" in
ttyIAX0) SENDTO=main@comp.spb.ru; FILETYPE=tif;;
ttyIAX1) SENDTO=branch@comp.spb.ru; FILETYPE=tif;;
esac
You can send faxes from Windows by Winprint Hylafax.
3. Statistics
Configure Asterisk for store logs in MySQL:
# cat /etc/asterisk/cdr_mysql.conf
[global]
hostname=localhost
dbname=asterisk
table=cdr
password=password
user=asteriskuser
port=3306
sock=/var/run/mysqld/mysqld.sock
userfield=1
Make a base:
# mysql -p
> CREATE DATABASE asterisk;
> GRANT ALL ON asterisk.* TO asteriskuser IDENTIFIED BY 'password';
> 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` );
Restart Asterisk and check mysql logging:
# /etc/init.d/asterisk restart
# asterisk -r
> cdr mysql status
Connected to asterisk@localhost, port 3306 using table cdr for 6 days, 23 hours, 32 minutes, 29 seconds.
Wrote 45770 records since last restart.
Install Web Interface:
# wget http://areski.net/asterisk-stat-v2/asterisk-stat-v2_0_1.tar.gz
Unpack files into /var/www or another folder and edit configuration files ./lib/defaults.php и ./lib/DB-modules/phplib_mysql.php
Configure Apache as You need. Make a link from index.php to cdr.php.
# apache2ctl restart
Open page in Your preferred Internet Browser and enjoy it.
