📜 ⬆️ ⬇️

Autospeed Cisco SPA504g and Asterisk. Part 1. Building and Configuring Asterisk + MySQL

Initial data


So, we have a desire to deploy office telephony in Asterisk.
Excellent desire, a great open-source solution.

OS: Centos 6.5 64-bit
PBX Version: The latest stable release from SVN (currently Asterisk SVN-branch-12-r409131)
Phones: Here the choice fell on the Cisco SPA504G (for the SMB segment of the market)


OS Preparation

')
As we will collect from a source code - we will prepare OS, having downloaded a necessary set of software for compilation.

[root@asterisk ~]# yum update -y [root@asterisk ~]# yum groupinstall -y "Development Tools" 


Now download the source code of Asterisk and the necessary to compile it DAHDI, LibPRI and libjansson

 [root@asterisk ~]# cd /usr/local/src/ [root@asterisk src]# svn checkout http://svn.asterisk.org/svn/asterisk/branches/12 asterisk [root@asterisk src]# git clone git://git.asterisk.org/dahdi/linux dahdi-linux [root@asterisk src]# git clone git://git.asterisk.org/dahdi/tools dahdi-tools [root@asterisk src]# svn checkout http://svn.asterisk.org/svn/libpri/branches/1.4 libpri [root@asterisk src]# wget http://www.digip.org/jansson/releases/jansson-2.5.tar.gz 


Install the packages needed to build DAHDI, LibPRI and Asterisk itself
 [root@asterisk ~]# yum install -y wget ncurses-devel openssl-devel newt-devel libxml2-devel sqlite-devel libuuid-devel unixODBC-devel libcurl-devel libogg-devel libvorbis-devel speex-devel spandsp-devel freetds-devel net-snmp-devel iksemel-devel corosynclib-devel popt-devel libtool-ltdl-devel lua-devel libsqlite3x-devel radiusclient-ng-devel portaudio-devel postgresql-devel libresample-devel neon-devel libical-devel openldap-devel gmime22-devel sqlite2-devel mysql-devel bluez-libs-devel jack-audio-connection-kit-devel gsm-devel libedit-devel jansson-devel libsrtp-devel pjproject-devel libxslt-devel 


A list of these packages can be obtained by running the script in the contrib / scripts directory in Asterisk's source code.
 [root@asterisk ~]# /usr/local/src/asterisk/contrib/scripts/install_prereq test 


Build DAHDI and LibPRI


 [root@asterisk src]# cd dahdi-linux [root@asterisk dahdi-linux]# make && make install 


If you get an error in response to the make command:
 You do not appear to have the sources for the 2.X.XX-XXX.el6.x86_64 kernel installed. 

So the OS pulled a fresh kernel with header files and wants to boot into it.
Reboot the server.

We continue to build and install
 [root@asterisk dahdi-linux]# cd ../dahdi-tools/ [root@asterisk dahdi-tools]# ./configure [root@asterisk dahdi-tools]# make && make install && make config 


With DAHDI finished. Go to LibPRI
 [root@asterisk dahdi-tools]# cd ../libpri/ [root@asterisk libpri]# make && make install 


Now it's libjansson's turn, which is not in CentOS repositories.
 [root@asterisk src]# tar -zxf jansson-2.5.tar.gz [root@asterisk src]# cd jansson-2.5 [root@asterisk jansson-2.5]# ./configure --prefix=/usr/ && make clean && make && make install && ldconfig 


Build asterisk


 [root@asterisk jansson-2.5]# cd ../asterisk [root@asterisk asterisk]# ./configure --libdir=/usr/lib64 [root@asterisk asterisk]# make menuselect 


You need to enable Add-Ons -> res_config_mysql for Asterisk Realtime Configuration to work.
Next - Save & Exit
 [root@asterisk asterisk]# make && make install 

And we go to smoke / drink coffee for 3-5-10 minutes, depending on the server's capacity, after which we turn on its autostart
 [root@asterisk asterisk]# chkconfig asterisk on [root@asterisk asterisk]# service asterisk start 


MySQL installation and database preparation



 [root@asterisk asterisk]# yum install -y mysql-server [root@asterisk asterisk]# chkconfig mysqld on [root@asterisk asterisk]# service mysqld start [root@asterisk asterisk]# /usr/bin/mysql_secure_installation [root@asterisk asterisk]# mysql -u root -p Enter password: 

Install MySQL, add its autostart on startup, set the root password, delete the test database, connect to the server as root.
 mysql> CREATE DATABASE `asterisk_db` CHARACTER SET = 'utf8' COLLATE = 'utf8_general_ci'; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON asteriskdb.* TO 'asterisk'@'localhost' IDENTIFIED BY 'mypass' WITH GRANT OPTION; mysql> FLUSH PRIVILEGES; 

Now create a table for storing SIP peers
 CREATE TABLE `tbl_sip_conf` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(80) NOT NULL DEFAULT '', `host` varchar(31) NOT NULL DEFAULT 'dynamic', `nat` varchar(5) NOT NULL DEFAULT 'no', `type` enum('user','peer','friend') NOT NULL DEFAULT 'friend', `accountcode` varchar(20) DEFAULT NULL, `amaflags` varchar(13) DEFAULT NULL, `call-limit` smallint(5) unsigned DEFAULT NULL, `callgroup` varchar(10) DEFAULT NULL, `callerid` varchar(80) DEFAULT NULL, `cancallforward` char(3) DEFAULT 'yes', `canreinvite` char(3) DEFAULT 'yes', `context` varchar(80) DEFAULT 'default', `defaultip` varchar(15) DEFAULT '0.0.0.0', `defaultuser` varchar(80) NOT NULL DEFAULT '', `dtmfmode` varchar(7) DEFAULT NULL, `fromuser` varchar(80) DEFAULT NULL, `fromdomain` varchar(80) DEFAULT NULL, `insecure` varchar(4) DEFAULT NULL, `language` char(2) DEFAULT 'ru', `macaddress` varchar(20) DEFAULT NULL, `mailbox` varchar(50) DEFAULT NULL, `md5secret` varchar(80) DEFAULT NULL, `deny` varchar(95) DEFAULT NULL, `permit` varchar(95) DEFAULT NULL, `mask` varchar(95) DEFAULT NULL, `musiconhold` varchar(100) DEFAULT NULL, `pickupgroup` varchar(10) DEFAULT NULL, `qualify` char(3) DEFAULT NULL, `regexten` varchar(80) DEFAULT NULL, `restrictcid` char(3) DEFAULT NULL, `rtptimeout` char(3) DEFAULT NULL, `rtpholdtimeout` char(3) DEFAULT NULL, `secret` varchar(80) DEFAULT NULL, `serial` varchar(20) DEFAULT NULL, `setvar` varchar(100) DEFAULT NULL, `disallow` varchar(100) DEFAULT 'all', `allow` varchar(100) DEFAULT 'ulaw;alaw;gsm', `fullcontact` varchar(80) NOT NULL DEFAULT '', `ipaddr` varchar(45) DEFAULT NULL, `port` smallint(5) unsigned NOT NULL DEFAULT '0', `regserver` varchar(100) DEFAULT NULL, `regseconds` int(11) NOT NULL DEFAULT '0', `lastms` int(11) NOT NULL DEFAULT '0', `defaultuser` varchar(80) NOT NULL DEFAULT '', `subscribecontext` varchar(80) DEFAULT NULL, `callbackextension` varchar(50) DEFAULT NULL, `useragent` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), KEY `name_2` (`name`) ) DEFAULT CHARSET=utf8; 


To work with the created asterisk database use the minimum set of configs from here

The next part of the manual will be installing Apache + PHP, preparing scripts for provisioning phones, setting up DHCP, etc.

Source: https://habr.com/ru/post/214181/


All Articles