使用Ubuntu 20.04/18.04/16.04&Debian 9安装Asterisk 16与FreePBX 15

时间:2020-02-23 14:44:36  来源:igfitidea点击:

本文旨在在Ubuntu 20.04/18.04/16.04和Debian 9上安装Asterisk 16,并使用FreePBX 15 GUI管理Asterisk。
Asterisk是一个开源完整的PBX系统,具有大多数商业上可获得的PBXES的功能,例如会议电话,直接向内系统访问,呼叫停车和呼叫队列以及许多其他功能。

在Ubuntu 20.04/18.04/16.04和Debian 9上安装Asterisk 16

在我们开始安装时,很好的做法是为了确保所有系统包最为期限为避免任何依赖性问题:

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

第1步:安装Asterisk 16 PBX依赖项

系统在线状态,继续为Asterisk PBX安装依赖性包。

sudo apt-get install git curl wget \
libnewt-dev libssl-dev libncurses5-dev \
subversion libsqlite3-dev build-essential \
libjansson-dev libxml2-dev  uuid-dev

如果我们在下面的Ubuntu上获得Subversion包的错误:

E: Package 'subversion' has no installation candidate

然后添加Universe存储库并从中安装Subversion:

sudo add-apt-repository universe
sudo apt update
sudo apt install subversion

第2步:下载Asterisk 16源并安装依赖项

由于Debian和Ubuntu上游存储库中没有Asterisk 15,因此安装将从源代码完成。

$sudo apt policy asterisk
asterisk:
  Installed: (none)
  Candidate: 1:13.14.1~dfsg-2+deb9u3
  Version table:
     1:13.14.1~dfsg-2+deb9u3 500
...
$sudo apt policy asterisk
asterisk:
  Installed: (none)
  Candidate: 1:13.18.3~dfsg-1ubuntu4

将最新版本的Asterisk 15下载到本地系统进行安装。

sudo su 
cd /usr/src/
curl -O http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz

然后提取文件:

tar xvf asterisk-16-current.tar.gz
cd asterisk-16*/

.RUN以下命令将MP3解码器库下载到源树中。

# sudo contrib/scripts/get_mp3_source.sh
A addons/mp3/decode_ntom.c
A addons/mp3/interface.c
A addons/mp3/MPGLIB_README
A addons/mp3/common.c
A addons/mp3/huffman.h
A addons/mp3/tabinit.c
A addons/mp3/Makefile
A addons/mp3/README
A addons/mp3/decode_i386.c
A addons/mp3/dct64_i386.c
A addons/mp3/MPGLIB_TODO
A addons/mp3/mpg123.h
A addons/mp3/layer3.c
A addons/mp3/mpglib.h
Exported revision 202.

确保解决所有依赖项:

sudo contrib/scripts/install_prereq install

这可能需要一些时间根据互联网速度。
确保最终获得成功信息:

#############################################
## install completed successfully
#############################################

第3步:从源版构建和安装Asterisk

安装所有依赖性包时,我们已准备好从源代码构建Asterisk PBX系统。

我们需要首先运行Configure脚本,该脚本负责确保构建和安装过程的所有依赖项可用。
它还发现了什么使用这些依赖项。

./configure

成功应具有如下所示的

configure: Menuselect build configuration successfully completed
               .$$$$$$$$$$$$$$$=..      
            ...          .7$:.    
          .$$:.                 ,.7   
        ..     7$$$$          .$  
     ..$$.       $$$$$           .$$ 
    ..7$  .?.   $$$$$  .?.       7$$$.
   $.$.   .$$. $$$ .7$$$.      .$$$.
 .777.   .$$$$$$$$$$$.      $$$,
 $$$~      .7$$$$$$$$$$$$.       .$$$.
.$          .7$$$$$$:          ?$$$.
$$$         ?7$$$$$$$$$$I        .$$ 
$$$      .7$$$$$$$$$$$$$$$$     :$$$. 
$$$      $$$$$$$$$$$$$$$$$   .$$$.  
$$$       $$$  7$$  .$$$   .$$$.   
$$$$            $$$         .$$$.    
7$$            7$$$$       7$$$     
 $$$$$                       $$$      
  $$$.                       $$ (TM)     
   $$$$$$$.           .7$$$$$$ $$     
     $$$$$$$$$$$$$$$$$$$$.$$$$$$     
       $$$$$$$$$$$$$$$$.                
configure: Package configured for: 
configure: OS type  : linux-gnu
configure: Host CPU : x86_64
configure: build-cpu:vendor:os: x86_64 : pc : linux-gnu :
configure: host-cpu:vendor:os: x86_64 : pc : linux-gnu :

通过运行以下命令设置菜单选项:

make menuselect

使用箭头键导航,然后输入键以选择。

在添加组件上选择 chan_ooh323format_mp3如下所示

在核心声音包上,选择如下所示的音频数据包格式

有关音乐,请选择以下最小模块

在额外的声音包中选择如下所示:

我们可以更改我们认为适合的其他配置。
完成后,保存和退出然后使用所选模块安装Asterisk:

make
make install
make samples
make config
ldconfig

make命令

Building Documentation For: third-party channels pbx apps codecs formats cdr cel bridges funcs tests main res addons 
 +--------- Asterisk Build Complete ---------+
 + Asterisk has successfully been built, and +
 + can be installed by running:              +
 +                                           +
 +                make install               +
 +-------------------------------------------+

成功的 make install

make[1]: Leaving directory '/usr/src/asterisk-16.9.0/sounds'
find rest-api -name "*.json" | while read x; do \
	/usr/bin/install -c -m 644 $x "/var/lib/asterisk/rest-api" ; \
done
 +---- Asterisk Installation Complete -------+
 +                                           +
 +    YOU MUST READ THE SECURITY DOCUMENT    +
 +                                           +
 + Asterisk has successfully been installed. +
 + If you would like to install the sample   +
 + configuration files (overwriting any      +
 + existing config files), run:              +
 +                                           +
 + For generic reference documentation:      +
 +    make samples                           +
 +                                           +
 + For a sample basic PBX:                   +
 +    make basic-pbx                         +
 +                                           +
 +                                           +
 +-----------------  or ---------------------+
 +                                           +
 + You can go ahead and install the asterisk +
 + program documentation now or later run:   +
 +                                           +
 +               make progdocs               +
 +                                           +
 + **Note** This requires that you have      +
 + doxygen installed on your local system    +
 +-------------------------------------------+

创建单独的用户和组以运行Asterisk服务,并分配正确的权限:

sudo groupadd asterisk
sudo useradd -r -d /var/lib/asterisk -g asterisk asterisk
sudo usermod -aG audio,dialout asterisk
sudo chown -R asterisk.asterisk /etc/asterisk
sudo chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk
sudo chown -R asterisk.asterisk /usr/lib/asterisk

将Asterisk默认用户设置为星号:

$sudo vim /etc/default/asterisk
AST_USER="asterisk"
AST_GROUP="asterisk"
$sudo vim /etc/asterisk/asterisk.conf
runuser = asterisk ; The user to run as.
rungroup = asterisk ; The group to run as.

进行更改后重新启动Asterisk服务:

sudo systemctl restart asterisk

启用服务以启动启动:

$sudo systemctl enable asterisk
Executing: /lib/systemd/systemd-sysv-install enable asterisk

服务应返回运行状态。

$systemctl status asterisk.service 
● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/init.d/asterisk; generated)
     Active: active (running) since Wed 2017-04-29 17:15:14 UTC; 2min 44s ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 69 (limit: 2344)
     Memory: 44.5M
     CGroup: /system.slice/asterisk.service
             └─47094 /usr/sbin/asterisk -U asterisk -G asterisk
Apr 29 17:15:14 ubuntu20 systemd[1]: Starting LSB: Asterisk PBX...
Apr 29 17:15:14 ubuntu20 asterisk[47066]:  * Starting Asterisk PBX: asterisk
Apr 29 17:15:14 ubuntu20 asterisk[47066]:    ...done.
Apr 29 17:15:14 ubuntu20 systemd[1]: Started LSB: Asterisk PBX.

测试查看我们是否可以连接到Asterisk CLI:

$sudo asterisk -rvv
Asterisk 16.9.0, Copyright (C) 1999 - 2016, Digium, Inc. and others.
Created by Mark Spencer Hyman@theitroad
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
Running as user 'asterisk'
Running under group 'asterisk'
Connected to Asterisk 16.9.0 currently running on ubuntu20 (pid = 47094)
ubuntu20*CLI>

第3步:在Ubuntu 20.04/18.04/16.04和Debian 9上安装FreePBX 15

FreePBX是一种基于Web的开源GUI(图形用户界面),可控制和管理星号(PBX)。
现在我们有星号愉快地运行,让我们安装FreePBX。

第1步:安装MariaDB数据库服务器:

sudo apt install mariadb-server

第2步:安装和配置Apache

从APT安装Apache2包:

sudo apt-get install apache2

然后在下面设置选项:

sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig
sudo sed -i 's/^\(User\|Group\).*/ asterisk/' /etc/apache2/apache2.conf
sudo sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf

第3步:安装PHP

FreePBX依赖于安装PHP,运行以下命令以安装PHP和所需的模块。

sudo apt-get -y install wget libapache2-mod-php php php-{pear,cgi,common,curl,mbstring,gd,gettext,mysql,bcmath,zip,xml,imap,json,snmp,fpm}

第4步:更改PHP最大文件上传大小:

对于Debian 9:

sudo sed -i 's/\(^upload_max_filesize = \).*/0M/' /etc/php/7.0/cli/php.ini
sudo sed -i 's/\(^upload_max_filesize = \).*/0M/' /etc/php/7.0/fpm/php.ini

对于Ubuntu 20.04:

sudo sed -i 's/\(^upload_max_filesize = \).*/0M/' /etc/php/7.4/apache2/php.ini
sudo sed -i 's/\(^upload_max_filesize = \).*/0M/' /etc/php/7.4/cli/php.ini

对于Ubuntu 18.04:

sudo sed -i 's/\(^upload_max_filesize = \).*/0M/' /etc/php/7.2/apache2/php.ini
sudo sed -i 's/\(^upload_max_filesize = \).*/0M/' /etc/php/7.2/cli/php.ini

第5步:下载并安装FreePBX

使用WGET下载最新版本的FreePBX - 14,因为这款写作:

cd /usr/src
sudo wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-15.0-latest.tgz
sudo tar xfz freepbx-15.0-latest.tgz
sudo rm -f freepbx-15.0-latest.tgz
cd freepbx
sudo ./start_asterisk start
sudo apt install nodejs
sudo ./install -n

示例

Done. All modules installed.
Updating Hooks...Done
Done installing modules
Taking too long? Customize the chown command, See http://wiki.freepbx.org/display/FOP/FreePBX+Chown+Conf
Setting Permissions...
Setting base permissions...Done
Setting specific permissions...
32451 [============================]
Finished setting permissions
Generating default configurations...
Finished generating default configurations
You have successfully installed FreePBX

如果我们遇到如下所示:

Unable to read /etc/asterisk/asterisk.conf or it was missing a directories section

然后编辑 /etc/asterisk/asterisk.conf并在第一行删除(!)。
改变

[directories](!) to [directories]

注意:在安装FreePBX后,将行恢复为目录否则星号将无法启动。

启用Apache重写引擎并重新启动Apache2.

sudo a2enmod rewrite
sudo systemctl restart apache2

如果我们有一个Active UFW防火墙,请打开HTTP端口和端口5060,5061

sudo ufw enable
sudo ufw allow 5060
sudo ufw allow 5061