📜 ⬆️ ⬇️

Ubuntu 14.04 + Asterisk 11 + CDR-Stats

I offer a step-by-step guide to installing and configuring the Ubuntu server, the Asterisk telephone exchange and the CDR-STATS call processing and analytics system.

Install Ubuntu


We install Ubuntu server 14.04 (LTS) by downloading the distribution from the official site. During installation, I specified SSH + LAMP + SAMBA in order to avoid the lengthy installation process of the necessary components.

Login to the server. First of all, I set up a midnight commander (I love the DOS interface, and it's convenient):
')
sudo apt-get install mc -y 

You can skip the next step if you do not need a server GUI.

For more convenience and in view of some features of the future server, I rolled up the GUI:

 sudo apt-get install --no-install-recommends lubuntu-desktop 

After installation:

 sudo reboot 

When the download is complete, we see the classic graphical user interface.

We configure all necessary network interfaces, server names and its Alias. (I will not give examples of settings in order not to mislead people).

The next step is to install webmin on the server. I used the official documentation from webmin.com :
Using the Webmin APT repository
If you like to install and update the webmin via APT, edit the / etc / apt / sources.list file and add the lines:

 deb http://download.webmin.com/download/repository sarge contrib deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib 

You must also be able to get it.

 cd /root wget http://www.webmin.com/jcameron-key.asc apt-key add jcameron-key.asc 

You may need to run this command as root.

 sudo apt-key add jcameron-key.asc 

You will now be able to install with the commands:

 sudo apt-get update sudo apt-get install webmin 

All dependencies should be resolved automatically.

After completing all the steps webmin will be available at: your-server-ip-or-name : 10000

It is time to configure the rules for iptables. On the network, I found a very good article on how to protect the Asterisk server using iptables. Source: blog.ls20.com/securing-your-asterisk-voip-server-with-iptables . The article is in English, but everything is simple enough to understand.

Now a very important point! Do not import rules to iptables in the standard way! It will not work:

 iptables-restore < filename 

It will not work.

You must perform the following steps:

Find the file /etc/iptables.up.rules and copy it somewhere (make a backup, so to speak), and replace the file etc / iptables.up.rules with the one you received as a result of the previous steps.
If you did everything correctly, then in the webmin Networking / Linux Firewall you will see all the necessary rules. I put available updates for installed components:

 sudo apt-get update && sudo apt-get upgrade –y && sudo reboot 

So, the server is installed, configured and updated.

Install Asterisk

It is time to install asterisk. In the current configuration I will use Asterisk 11:

 cd /usr/src wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz 

Unpack it all:

 tar -zxvf asterisk-11-current.tar.gz tar -zxvf dahdi-linux-complete-current.tar.gz tar -zxvf libpri-1.4-current.tar.gz 

Let's put some packages, if any have not been installed before:

 sudo apt-get install build-essential libncurses5-dev openssl libxml2-dev 

Then there are two ways:

1st path:

run the installation script of dependent packages for the operation of the Asterisk server:

 sudo /usr/src/asterisk-11.12.0/contrib/scripts/install_prereq install 

The script puts all the necessary dependencies and packages, but a lot of unnecessary.

2nd way:

Installation from source
Before this action, I made a checkpoint on my hyper-v server, to avoid saying so:

 sudo apt-get install libncurses5-dev openssl libssl-dev zlib1g zlib1g-dev mpg123 linux-headers-`uname -r` build-essential mysql-server libmysqlclient15-dev php5 php5-cli php5-mysql php5-gd php-pear apache2 curl sox bison flex cpp g++ gcc make libauthen-pam-perl libio-pty-perl libnet-ssleay-perl libxml2 libxml2-dev libaudiofile-dev subversion libsqlite3-dev 

OK. packages installed. Now it's time to figure out how to install Asterisk itself.

We put DAHDI:

 cd /usr/src/dahdi-linux-complete-2.10.0+2.10.0 sudo make all sudo make install sudo make config 

We put LibPRI:

 cd /usr/src/libpri-1.4.15 sudo make sudo make install 

Well, Asterisk itself:

 cd /usr/src/asterisk-11.12.0 ./configure sudo make menuselect 

We select the necessary components. Since I am going to store the CDR in the MySQL database and fasten the CDR-STATS web interface, I note that I have included the format_mp3 , app_mysql , cdr_mysql and res_config_mysql modules .

For the rest, with the exception of sounds (and I need en, en-gb and ru), everything remains standard:

 sudo make install 

During the installation process, when choosing format_mp3, you need to run:

 contrib/scripts/get_mp3_source.sh 

We continue the installation:

 sudo make install 

Here can be your advertising. We drink coffee, tea, cookies and wait for the end of the installation process.

Next step is samples and config. Test configs:

 sudo make samples 

For the non-compilation of the autorun script:

 sudo make config 

Ffuuhh! Put. We start:

 sudo asterisk start 

Connect:

 sudo rasterisk 

Check the version of DAHDI:

 *CLI>dahdi show version 

Check the version of LibPRI:

 *CLI>pri show version *CLI>exit 

So, set, looked. Currently, asterisk runs as root, which, however, is not comme il faut. Therefore, we do the following:

 sudo service asterisk stop 

Create an asterisk user and add it to the asterisk group:

 sudo adduser --system --group --home /var/lib/asterisk --no-create-home --gecos "Asterisk PBX" asterisk 

Created, we change the rights to the necessary directories:

 sudo chown -R asterisk:asterisk /var/lib/asterisk sudo chown -R asterisk:asterisk /var/log/asterisk sudo chown -R asterisk:asterisk /var/run/asterisk sudo chown -R asterisk:asterisk /var/spool/asterisk sudo chown -R asterisk:asterisk /usr/lib/asterisk sudo chown -R asterisk:asterisk /dev/dahdi sudo chmod -R u=rwX,g=rX,o= /var/lib/asterisk sudo chmod -R u=rwX,g=rX,o= /var/log/asterisk sudo chmod -R u=rwX,g=rX,o= /var/run/asterisk sudo chmod -R u=rwX,g=rX,o= /var/spool/asterisk sudo chmod -R u=rwX,g=rX,o= /usr/lib/asterisk sudo chmod -R u=rwX,g=rX,o= /dev/dahdi sudo chown -R root:asterisk /etc/asterisk sudo chmod -R u=rwX,g=rX,o= /etc/asterisk 

In the / etc / default / asterisk file we uncomment two lines:

 AST_USER=«asterisk» AST_GROUP=«asterisk» 

Run asterisk:

 sudo service asterisk start 

We look, from what user Asterisk was started:

 ps aux|grep aster 

And you should see something like this:
asterisk 2793 3.0 0.8 2539536 26540? Ssl 20:21 0:00 / usr / sbin / asterisk -U asterisk -G asterisk

Saw? So everything is ok. Now we will teach asterisk to write CDR in MySQL.

We put to start:

 sudo apt-get install mysql-client 

Login to mysql:

 sudo mysql -p 

Enter password:
Welcome to the MySQL monitor. Commands end with; or \ g.
mysql>

Create a database:

 mysql> create database asteriskcdrdb; 

We create a table “cdr” in the “asteriskcdrdb” database, with the following structure:

 mysql> use asteriskcdrdb; mysql>CREATE TABLE `cdr` ( `acctid` int(11) NOT NULL AUTO_INCREMENT, `src` varchar(80) DEFAULT NULL, `dst` varchar(80) DEFAULT NULL, `calldate` datetime NOT NULL, `clid` varchar(80) DEFAULT NULL, `dcontext` varchar(80) DEFAULT NULL, `channel` varchar(80) DEFAULT NULL, `dstchannel` varchar(80) DEFAULT NULL, `lastapp` varchar(80) DEFAULT NULL, `lastdata` varchar(80) DEFAULT NULL, `duration` int(10) unsigned DEFAULT NULL, `billsec` int(10) unsigned DEFAULT NULL, `disposition` varchar(80) NOT NULL DEFAULT '', `amaflags` varchar(80) DEFAULT NULL, `accountcode` int(10) unsigned DEFAULT NULL, `uniqueid` varchar(32) DEFAULT NULL, `userfield` varchar(80) DEFAULT NULL, `import_cdr` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`acctid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

Create an asterisk user with the password 'asterisk':

 mysql> CREATE USER asterisk_user IDENTIFIED BY 'asterisk_password'; 

Now we give access for the user “asterisk” with the password “asterisk ″ to the database“ asteriskcdrdb ”only from localhost:

 mysql> grant all on asteriskcdrdb.* to 'asterisk'@'localhost' identified by 'asterisk'; mysql> flush privileges; 

Now we will tell our Asterisk to write CDR to the database. To do this, in the file “/etc/asterisk/cdr_mysql.conf” we uncomment and change the lines:

 [global] hostname=localhost dbname=asteriskcdrdb table=cdr password=asterisk user=asterisk sock=/var/lib/mysqld/mysqld.sock 

To apply the changes, reload the cdr_mysql.so module:

 sudo rasterisk *CLI>module unload cdr_mysql.so 

 Unloaded cdr_mysql.so == Unregistered 'mysql' CDR backend 

 *CLI> module load cdr_mysql.so 

 Loaded cdr_mysql.so == Parsing '/etc/asterisk/cdr_mysql.conf': Found -- Found alias start for column calldate Loaded cdr_mysql.so => (MySQL CDR Backend) 

To make sure that we did everything correctly, in the Asterisk console enter:

 *CLI> cdr mysql status 

 Connected to asterisk on socket file /var/lib/mysql/mysql.sock using table cdr for 0 hours, 2 minutes, 7 seconds. Wrote 0 records since last restart. 

If you have the same message, then everything is set up correctly.

Installing CDR-STATS

We use the instructions . Everything would seem simple:

 wget –no-check-certificate https://raw.github.com/Star2Billing/cdr-stats/master/install/install-cdr-stats-asterisk.sh -O install-cdr-stats-asterisk.sh bash ./install-cdr-stats-asterisk.sh 

But, the devil, as usual, is in the details. You will not be able to install CDR-stats in this way, because the script will crash with the following error:

 bash ./install-cdr-stats-asterisk.sh ./install-cdr-stats-asterisk.sh: line 1: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 2: !DOCTYPE: No such file or directory ./install-cdr-stats-asterisk.sh: line 3: html: No such file or directory ./install-cdr-stats-asterisk.sh: line 4: head: No such file or directory ./install-cdr-stats-asterisk.sh: line 5: title: No such file or directory ./install-cdr-stats-asterisk.sh: line 6: meta: No such file or directory ./install-cdr-stats-asterisk.sh: line 7: meta: No such file or directory ./install-cdr-stats-asterisk.sh: line 8: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 9: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 10: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 11: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 12: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 13: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 14: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 15: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 16: $'\r': command not found ./install-cdr-stats-asterisk.sh: line 17: meta: No such file or directory ./install-cdr-stats-asterisk.sh: line 18: meta: No such file or directory ./install-cdr-stats-asterisk.sh: line 19: meta: No such file or directory ./install-cdr-stats-asterisk.sh: line 20: base: No such file or directory ./install-cdr-stats-asterisk.sh: line 21: link: No such file or directory ./install-cdr-stats-asterisk.sh: line 22: link: No such file or directory ./install-cdr-stats-asterisk.sh: line 23: link: No such file or directory ./install-cdr-stats-asterisk.sh: line 24: meta: No such file or directory ./install-cdr-stats-asterisk.sh: line 25: meta: No such file or directory ./install-cdr-stats-asterisk.sh: line 26: link: No such file or directory ./install-cdr-stats-asterisk.sh: line 27: syntax error near unexpected token `<' ./install-cdr-stats-asterisk.sh: line 27: ` 

As we can see, the above text contains stupid things like! DOCTYPE. I opened this script and saw a different incomprehensible. But at the end the script itself is purposeful. We cut out all unnecessary, leaving only the body of the script. Here is the text:

Do not alter the text below to avoid problems!

 #!/bin/bash # # CDR-Stats License # http://www.cdr-stats.org # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. # # Copyright (C) 2011-2012 Star2Billing SL # # The Initial Developer of the Original Code is # Arezqui Belaid <info@star2billing.com> # # To download and run the script on your server : # cd /usr/src/ ; rm install-cdr-stats-asterisk.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/cdr-stats/master/install/install-cdr-stats-asterisk.sh -O install-cdr-stats-asterisk.sh; bash install-cdr-stats-asterisk.sh # BRANCH='master' INSTALL_DIR='/usr/share/cdr_stats' #INSTALL TYPE (ASTERISK or FREESWITCH) INSTALL_TYPE='ASTERISK' INSTALLMODE='GENTLE' # Set to FULL to update Selinux, Firewall, etc if not Set to GENTLE echo "" echo "" echo "> > > This is only to be installed on a fresh new installation of CentOS 6.2 or Ubuntu LTS 10.04 / 12.04! < < <" echo "" echo "It will install CDR-Stats on your server" echo "Press Enter to continue or CTRL-C to exit" echo "" read TEMP #Get Scripts dependencies cd /usr/src/ wget --no-check-certificate https://raw.github.com/Star2Billing/cdr-stats/$BRANCH/install/bash-common-functions.sh -O bash-common-functions.sh wget --no-check-certificate https://raw.github.com/Star2Billing/cdr-stats/$BRANCH/install/cdr-stats-functions.sh -O cdr-stats-functions.sh #Include general functions source bash-common-functions.sh source cdr-stats-functions.sh #Identify the OS func_identify_os #Request the user to accept the license func_accept_license_mplv2 #run install menu run_menu_cdr_stats_install 

Run:

 bash install-cdr-stats-asterisk.sh 

The script again fails with the error:
This script is only intended to run on Ubuntu LTS 10.04 / 12.04 or CentOS 6.X

Tinkering the Internet for a second did not bring me closer to solving this issue, so I went the other way. Thoughtful smoking of a script and substances (coffee and cigarettes) led me to the following solution:

 cd /etc/ 

Open the lsb-release file and see:
DISTRIB_CODENAME = trusty

Memorized. Now:

 cd /usr/src/ 

Open the file bash-common-functions.sh. And in it we look at the function:

 func_identify_os() { if [ -f /etc/debian_version ] ; then DIST='DEBIAN' if [ "$(lsb_release -cs)" != "lucid" ] && [ "$(lsb_release -cs)" != "precise" ]; then echo "This script is only intended to run on Ubuntu LTS 10.04 / 12.04 or CentOS 6.X" exit 255 

We see two options: lucid and precise. I chose precise (Ubuntu 12.04 LTS). And do the following:

In file:
/ etc / lsb-release change trusty to precise

Further:

 cd /usr/src bash install-cdr-stats.sh 

It will install CDR-Stats on your server
Press Enter to continue or CTRL-C to exit

Hit Enter
To the question:
- [YES / NO]

We speak:

 YES 

The installer starts.
> CDR-Stats Installation Menu
=====================================
1) Install All
2) Install CDR-Stats Web Frontend
3) Install CDR-Stats Backend / CDR-Stats-Celery
4) Install MongoDB
0) Quit
(0-4): 1

Select the menu item number 1. And wait until it is established. The installation process will install mongodb and postgresql. Next, we will be asked to configure a connection to MySQL:

Enter database settings for Asterisk ...
ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: YES)
Configure Mysql Settings to connect to the Asterisk CDR database ...
Enter Mysql hostname (default: localhost)
localhost
Enter Mysql port (default: 3306)
3306
Enter Mysql Username (default: root)
asterisk
Enter Mysql Password (default: password)
asterisk
Enter Database name (default: asteriskcdrdb)
asteriskcdrdb
We will now add a CD to your CDR database.
We advice you to first backup your database prior

Next you will be asked to create a super admin for cdr-stats:
Create a super admin user ...
Username (leave blank to use 'root'):
E-mail address: your-email@server.com
Password:
Password (again):
Superuser created successfully.

Finish the installation with the button 0. And hurray!
your-server-ip-or-name : 8008
Available. We go and admire.

The following error may occur:
No data can be found in your collections, please make sure that the data is working correctly.

What are we doing? Stop the CDR-stats:

 sudo service cdr-stats-celeryd stop 

Go to mongo:

 mongo 

Perform the following actions:

 use cdr-stats; db.monthly_analytic.remove({}); db.daily_analytic.remove({}); db.aggregate_world_report.remove({}); db.aggregate_result_cdr_view.remove({}); db.aggregate_hourly_country_report.remove({}); db.cdr_common.remove({}); 

Exit: Ctrl + D
Go to mysql:

 sudo mysql -p 

 mysql> use asteriskcdrdb; mysql> update cdr SET import_cdr = 0; 

Query OK, 0 rows affected (0.24 sec)
Rows matched: 3 Changed: 0 Warnings: 0

I currently have 3 entries in the CDR. Exit mysql: Ctrl + C

 cd /usr/share/cdr-stats 

Open the file settings_local.py and look for the line:

 LOCAL_SWITCH_IP = " " 

Change it to 'localhost':

 LOCAL_SWITCH_IP = 'localhost' 

Save the changes and run cdr-stats:

 sudo service cdr-stats-celeryd start 

your-server-ip-or-name : 8008

And everything starts to work.

Another important point! If you have several telephony providers or you use non-standard prefixes for accessing a local or international line, you need to specify them in the cdr-stats. This is done here:

 /usr/share/cdr-stats/setting_local.py 

Line:
PREFIX_TO_IGNORE = "+, 00,000,0000,00000,011,55555,99999"

Do not change the current values, leave as is, and add yours to the end of the line.
For example, like this:

 PREFIX_TO_IGNORE = "+,00,000,0000,00000,011,55555,99999,8,810,9,910" 

Save the changes to the file and restart cdr-stats:

 sudo service cdr-stats-celeryd restart 

Now CDR-STATS will correctly handle all calls, as you can see by visiting the appropriate menu item.

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


All Articles