Installing And Configuring Asterisk 1.6 + PostgreSQL To Manage CDR & RealTime Config On Debian

Want to support HowtoForge? Become a subscriber!
 
Submitted by Coto (Contact Author) (Forums) on Wed, 2009-04-08 16:48. :: Debian

Installing And Configuring Asterisk 1.6 + PostgreSQL To Manage CDR & RealTime Config On Debian

In this tutorial, I will describe how to install and configure Asterisk 1.6 on a Debian system to work with PostgreSQL in order to manage CDR (Call Detail Records) and real-time configuration.

For this we will use a clean and up-to-date Debian Etch/Lenny system; the first step is to reconfigure the kernel with some new parameters so that it supports Asterisk optimally.

apt-get install kernel-package libncurses5-dev fakeroot wget bzip2 build-essential

cd /usr/src

Download the kernel source, I will use 2.6.26:

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.8.tar.gz

tar xfv linux-2.6.26.8.tar.gz

ln -s /usr/src/linux-2.6.26.8 /usr/src/linux

cd /usr/src/linux

make clean && make mrproper

cp /boot/config-`uname -r` ./.config

make menuconfig

Now in the kernel configuration, we select this:

Processor type and features >> [*]IRQ balancing
Processor type and features >> Timer frequency = 1000 Hz.
Processor type and features >> [*]High Resolution Timer Option
Processor type and features >> [*]HPET Timer Support
Device Drivers >> Character Devices >> [*]Enchanced Real Time Clock Support
Library Routines >> [*]CONFIG_CRC_CCITT

Now compile and make a .deb package for the kernel:

make-kpkg clean

fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers

We can now install the kernel as follows:

cd /usr/src

dpkg -i *.deb

Now we need to reboot:

reboot -t now!

Ok, now we have the system fully optimized for best performance with VoIP. Now we prepare the machine for compiling Asterisk from the sources:

apt-get install build-essential libcurl3-dev libvorbis-dev libspeex-dev unixodbc unixodbc-dev libiksemel-dev

apt-get install flex xsltproc odbc-postgresql libusb-dev libnewt-dev libxml2-dev bison

apt-get install linux-headers-`uname -r` g++ libncurses5-dev libnewt-dev libusb-dev subversion git-core

apt-get install postgresql-8.1 postgresql-contrib-8.1 postgresql-client-8.1 postgresql-dev

Our system is ready, now download the Asterisk sources from the svn repo. In Asterisk 1.6 Zaptel is renamed to DAHDI, and we add mISDN for ISDN trunks:

cd /usr/src

mkdir asterisk

cd asterisk

svn co http://svn.digium.com/svn/asterisk/trunk asterisk

svn co http://svn.digium.com/svn/asterisk-addons/trunk asterisk-addons

svn co http://svn.digium.com/svn/dahdi/linux/trunk dahdi-linux

svn co http://svn.digium.com/svn/dahdi/tools/trunk dahdi-tools

svn co http://svn.digium.com/svn/libpri/branches/1.4 libpri

git-clone git://git.misdn.org/git/mISDN.git/

git-clone git://git.misdn.org/git/mISDNuser.git/

Now we start compiling the DAHDI modules, for managing and controlling Digium devices and others:

cd /usr/src/asterisk/dahdi-linux

make && make install

Now the DAHDI tools

cd /usr/src/asterisk/dahdi-tools

./configure

make menuselect

make

make install

make config

To optimize boot time, we unload unnecesary modules, therefore edit /etc/dahdi/modules and comment out all modules, except that one you will use, for example, I have a Digium TDM400P, so I uncomment wctdm.

Now we build libpri:

cd /usr/src/asterisk/libpri

make && make install

Now only if you have the ISDN trunk. This step is

**OPTIONAL**

cd /usr/src/asterisk/mISDN

make

make install

cd /usr/src/asterisk/mISDNuser

make && make install

mISDN scan

mISDN config

mISDN start

misdnportinfo

/usr/sbin/update-rc.d mISDN defaults 15 30

**END OPTIONAL**

Now we compile Asterisk itself:

cd /usr/src/asterisk/asterisk

./configure

make menuconfig

make

make install

make samples

make config

asterisk -vvvc

Ctrl+C for exit

So, we have an ordinary Asterisk 1.6 just like any other, but now we make it unique and configure it to work in realtime.

First we need the DB schema, Asterisk has one, but it is bugged, so I use my own DB.

cd /usr/src/asterisk

wget http://coto.debianchile.cl/files/realtime_pgsql.sql

su - postgres

createuser -s -D -R -l -P -e asterisk

createdb -O asterisk -e asteriskDB

pgsql -U asterisk -h localhost -d asteriskDB < /usr/src/asterisk/realtime_pgsql.sql

Allow asterisk to connect to PostgreSQL:

echo "local asteriskDB asterisk md5" >> /etc/postgresql/8.1/pg_hba.conf

Now we prepare the configuration files in Asterisk:

nano /etc/asterisk/cdr_pgsql.conf

[global]
hostname=localhost
port=5432
dbname=asteriskDB
password=password
user=asterisk
table=cdr 

nano /etc/asterisk/extconfig.conf

[settings]
extensions => pgsql,asteriskDB,extensions_conf
sipuser => pgsql,asteriskDB,sip_conf
sippeers => pgsql,asteriskDB,sip_conf
sipregs => pgsql,asteriskDB,sip_conf
voicemail => pgsql,asteriskDB,voicemail_users
queues => pgsql,asteriskDB,queue_table
queue_members => pgsql,asteriskDB,queue_member_table 

nano /etc/asterisk/res_pgsql.conf

[general]
dbhost=127.0.0.1
dbport=5432
dbname=asteriskDB
dbuser=asterisk
dbpass=password
requirements=warn

All set... we are ready, now just restart Asterisk. Congratulations!

/etc/init.d/asterisk restart

HOW-TO IS OUTDATED... UpGrade in progress in http://coto.debianchile.cl/asterisk/asterisk-postgresql/ This is in Spanish, very soon English version, only here.. in HowToForge! Cheers, Coto Cisternas
Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Sat, 2011-07-16 16:11.
thank you for the tutorial !!
Submitted by Maziar (not registered) on Fri, 2013-01-18 15:27.
sql file not found
Submitted by Grayson Peddie (not registered) on Sun, 2009-11-01 05:49.

If this the one contained inside realtime_pgsql.sql file? The website with the file in the URL does not have it. Here's the one:

 http://www.koders.com/sql/fid78E5D8568A9C3119A00F9BCCEEDEDF3AF7B6976E.aspx?s=asterisk#L122

Submitted by Coto (registered user) on Tue, 2010-01-19 21:48.

Upgraded... ty, i change my domain and my hosting... :P btw... this TUTO is very OutUpdate... but check out in http://coto.debianchile.cl/asterisk/asterisk-postgresql/

Im working in a Upgrade, but is in Spanish... very soon i will translate and republish right here.. in How To Forge!

 

Cheers,

Coto Cisternas

Submitted by Allan (not registered) on Sat, 2009-04-11 00:17.

The line:

<code>

pgsql -U asterisk -h localhost -d asteriskDB < /usr/src/asterisk/realtime_pgsql.sql

</code>

 

Should be:

<code>

psql -U asterisk -h localhost -d asteriskDB < /usr/src/asterisk/realtime_pgsql.sql

</code>

 

At least on my Debian Lenny installation.

 

Cheers,

Allan