📜 ⬆️ ⬇️

VoIP server for a small company (FreePBX 14, Asterisk 15, Ubuntu 16.04) part 1

Good afternoon, evening or night, it all depends on the time of day in which you happened to read my article. Start over. In our company, thinking about the transition to SIP and the question arose? how to implement it.

Initial data:


Several options were considered:
')

As a result, they decided to implement their VoIP server.

What we have:


A small digression, on points:

Ubuntu 16.04 here is a corporate standard, Ubuntu Server 16.04, as a working OS Ubuntu Desktop 16.04. The main server is based on Zentyal 5.0. Servers and working PCs are installed over the network via TFTP. If it is interesting I will describe all the nuances of installing Zentyal (and their decent amount).

Devices decided not to buy, each employee has a cell either on Android or iOS, so that there are no problems with clients, employees have access to a Wi-FI desktop. SIP clients also stand on working PCs. There is also access to SIP via the Internet, security is also taken into account, connection ports are changed, SIP passwords are rather complicated.

We turn to the essence. There is a lot of documentation on installing FreePBX 13 on Ubuntu 16.04, but there is no way to install FreePBX 14, even the official wiki FreePBX is only for CentOS 7 and Debian 8.8, but there was a great desire and desire to make it.

1. I will not describe the installation of Ubuntu Server 16.04, it's easy even for a beginner.

1.1. I did all the manipulations as root sudo su

2. Upgrade the system: apt update && apt upgrade -y , if a reboot is required, reboot.

3. Let's do PHP, PHP 5.6 is required for FreePBX 14, by default PHP 7.0 is running in Ubunty 16.04

Delete all PHP if it is in the system:

sudo apt purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`

Install the PHP 5.6 repository:

sudo add-apt-repository ppa:ondrej/php

Update and install PHP:

sudo apt update
sudo apt install php5.6


4. Mysql that goes to the repository is not compatible with FreePBX 14, we need MariaDB, we add it to the repository:

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.mephi.ru/mariadb/repo/10.2/ubuntu xenial main'


5. We also need nodejs:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt install -y nodejs


6. Install now everything you need:

sudo apt install -y build-essential linux-headers-`uname -r` openssh-server apache2 mariadb-server mysql-client bison flex sox libncurses5-dev libssl-dev libmysqlclient-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf git subversion unixodbc-dev uuid uuid-dev libasound2-dev libogg-dev libvorbis-dev libcurl4-openssl-dev libical-dev libneon27-dev libsrtp0-dev libspandsp-dev libopus-dev opus-tools libiksemel-dev libiksemel-utils libiksemel3 xmlstarlet

sudo apt install -y php5.6 php5.6-curl php5.6-cli php5.6-mysql php5.6-odbc php5.6-db php5.6-gd php5.6-xml curl libapache2-mod-php5.6 php5.6-mbstring

apt install -y php-pear

6.1. The libmyodbc package is no longer in the Ubuntu repositories since the Xenial version.

Download the desired connector:

wget https://downloads.mariadb.com/Connectors/odbc/connector-odbc-3.0.2/mariadb-connector-odbc-3.0.2-ga-debian-x86_64.tar.gz

Unpack:
tar -zxvf mariadb-connector-odbc-3.0.2-ga-debian-x86_64.tar.gz

And copy it to the / usr / lib / x86_64-linux-gnu / odbc / directory:

cd mariadb-connector-odbc-3.0.2-ga-debian-x86_64/lib
cp libmaodbc.so /usr/lib/x86_64-linux-gnu/odbc/

7. Now, according to the recommendations of FreePBX, you need to reboot, I did not do this.

8. Make sure mod_rewrite is enabled to avoid possible attacks.

a2enmod rewrite
service apache2 restart


9. Enable Console_Getopt support

pear install Console_Getopt

10. Go to the installation of Asterisk 15 (in fact, this is part of the wiki with FreePBX for Debina 8.8):

Download the source:

cd /usr/src
wget http://sourceforge.net/projects/lame/files/lame/3.98.4/lame-3.98.4.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-current.tar.gz &&
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-15-current.tar.gz &&
git clone https://github.com/akheron/jansson.git &&
wget http://www.pjsip.org/release/2.5.5/pjproject-2.5.5.tar.bz2


Compile and install Lame (mp3):

cd /usr/src &&
tar zxvf lame-3.98.4.tar.gz &&
cd lame-3.98.4 &&
./configure &&
make &&
make install


Let's compile and install DAHDI and LibPRI (We do not use boards, but who knows what we want later):

cd /usr/src &&
tar xvfz dahdi-linux-complete-current.tar.gz &&
tar xvfz libpri-current.tar.gz &&
rm -f dahdi-linux-complete-current.tar.gz libpri-current.tar.gz &&
cd dahdi-linux-complete-* &&
make all &&
make install &&
make config &&
cd /usr/src/libpri-* &&
make &&
make install


Compile and install pjproject:

cd /usr/src &&
tar -xjvf pjproject-2.*.*.tar.bz2 &&
cd pjproject-* &&
CFLAGS='-DPJ_HAS_IPV6=1' ./configure --prefix=/usr --enable-shared --disable-sound\
--disable-resample --disable-video --disable-opencore-amr &&
make dep &&
make &&
make install


Compile and install jansson:

cd /usr/src/jansson &&
autoreconf -i &&
./configure &&
make &&
make install


If you want to use the Opus codec, you need to install xmlstarlet before compiling Asterisk:

sudo apt install xmlstarlet

Compile and install Asterisk:

cd /usr/src &&
tar xvfz asterisk-15-current.tar.gz &&
rm -f asterisk-15-current.tar.gz &&
cd asterisk-* &&
./contrib/scripts/install_prereq install &&
./configure --with-pjproject-bundled --with-crypto --with-ssl=ssl --with-srtp &&
contrib/scripts/get_mp3_source.sh &&
make menuselect


For myself, I chose 'format_mp3' and 'res_config_mysql', as well as included 'codec_opus'

Save the changes and continue the installation:

make &&
make install &&
make config &&
ldconfig
update-rc.d -f asterisk remove


While everything was going, I managed to pour myself a cup of coffee and continued.

Configure the launch as user 'Asterisk'

Uncomment in / etc / default / asterisk:

AST_USER="asterisk"
AST_GROUP="asterisk"


Create an Asterisk user and set user rights:

useradd -m asterisk &&
chown asterisk. /var/run/asterisk &&
chown -R asterisk. /etc/asterisk &&
chown -R asterisk. /var/{lib,log,spool}/asterisk &&
chown -R asterisk. /usr/lib/asterisk


11. Go to FreePBX 14

Configure Apache:

sed -i 's/\(^upload_max_filesize = \).*/\256M/' /etc/php/5.6/apache2/php.ini &&
sed -ie 's/\;date\.timezone\ \=/date\.timezone\ \=\ "Asia\/Yekaterinburg"/g' /etc/php/5.6/apache2/php.ini &&
cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig &&
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf &&
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf &&
systemctl restart apache2


Configure ODBC:

cat >> /etc/odbcinst.ini << EOF
[MySQL]
Driver=/usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so
UsageCount=2

EOF


cat >> /etc/odbc.ini << EOF
[MySQL-asteriskcdrdb]
Description=MySQL connection to 'asteriskcdrdb' database
driver=MySQL
server=localhost
database=asteriskcdrdb
Port=3306
Socket=/var/run/mysqld/mysqld.sock
option=3

EOF


Download and install FreePBX:

cd /usr/src
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-14.0-latest.tgz
tar vxfz freepbx-14.0-latest.tgz
rm -f freepbx-14.0-latest.tgz
cd freepbx
touch /etc/asterisk/ari.conf
./start_asterisk start
./install -n


11.1. To Russify FreePBX, the ru_RU.UTF-8 locale is needed:

echo "russian ru_RU.UTF-8" >> /etc/locale.alias
locale-gen ru_RU
systemctl restart apache2

12. Create a startup script for systemd:

Insert into the /etc/systemd/system/freepbx.service file:

[Unit]
Description=FreePBX VoIP Server
After=mariadb.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/fwconsole start -q
ExecStop=/usr/sbin/fwconsole stop -q

[Install]
WantedBy=multi-user.target


Activate the service:

systemctl enable freepbx.service

Epilogue.

This completes the installation and initial setup. There will be questions, always ready to answer.

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


All Articles