版本配置:
-
FreePBX 17(最新)
-
Asterisk 20(最新Asterisk 22,但是FreePBX 17最新只支持Asterisk 21,但是21非LTS版本,所以选择Asterisk 20)
-
PHP 8.2
-
Maria DB (v10.11)
-
Node JS (v18.16)
-
阿里云 ubuntu24.04 美国.弗吉尼亚 (墙外搭建很方便,国内环境各种报错)
-
时间20250110
所有命令都应以 root 用户身份运行,方法是直接以 root 身份登录或使用 sudo su -
初始化系统依懒项
apt-get update
apt-get upgrade
apt -y install build-essential git curl wget libnewt-dev libssl-dev libncurses5-dev subversion libsqlite3-dev libjansson-dev libxml2-dev uuid-dev default-libmysqlclient-dev htop sngrep lame ffmpeg mpg123
apt -y install git vim curl wget libnewt-dev libssl-dev libncurses5-dev subversion libsqlite3-dev build-essential libjansson-dev libxml2-dev uuid-dev expect
PHP 8.2 安装
FreePBX 17 仅支持 PHP 8.2,因此如果您正在运行旧版 PHP 或新版 PHP,请删除该版本并安装 PHP 8.2 版本
# 更新 APT 源并添加 PHP 8.2 仓库
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update# 安装 PHP 8.2 及其扩展
sudo apt-get install -y php8.2 php8.2-curl php8.2-cli php8.2-common php8.2-mysql php8.2-gd php8.2-mbstring php8.2-intl php8.2-xml php8.2-soap# 安装其他依赖项
sudo apt-get install -y build-essential linux-headers-$(uname -r) openssh-server apache2 mariadb-server mariadb-client bison flex curl sox libncurses-dev libssl-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf git unixodbc-dev uuid uuid-dev libasound2-dev libogg-dev libvorbis-dev libicu-dev libcurl4-openssl-dev odbc-mariadb libical-dev libneon27-dev libsrtp2-dev libspandsp-dev sudo subversion libtool-bin python3-dev vim wget libjansson-dev software-properties-common nodejs npm ipset iptables fail2ban
Asterisk 安装
下载 Asterisk并编译
cd /usr/local/src
wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20.11.1.tar.gz
tar -zxvf asterisk-20.11.1.tar.gz
cd /usr/local/src/asterisk-20.11.1
contrib/scripts/get_mp3_source.sh
contrib/scripts/install_prereq install
./configure --libdir=/usr/lib64 --with-pjproject-bundled --with-jansson-bundled#选择配置模块
make menuselect#编译安装
make
make install
make samples
make config
ldconfig
创建Asterisk用户并授予权限
groupadd asterisk
useradd -r -d /var/lib/asterisk -g asterisk asterisk
usermod -aG audio,dialout asterisk
chown -R asterisk:asterisk /etc/asterisk
chown -R asterisk:asterisk /var/{lib,log,spool}/asterisk
chown -R asterisk:asterisk /usr/lib64/asterisksed -i 's|#AST_USER|AST_USER|' /etc/default/asterisk
sed -i 's|#AST_GROUP|AST_GROUP|' /etc/default/asterisk
sed -i 's|;runuser|runuser|' /etc/asterisk/asterisk.conf
sed -i 's|;rungroup|rungroup|' /etc/asterisk/asterisk.conf
echo "/usr/lib64" >> /etc/ld.so.conf.d/x86_64-linux-gnu.conf
ldconfig
配置 Apache Web 服务器
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/8.2/apache2/php.ini
sed -i 's/\(^memory_limit = \).*/\1256M/' /etc/php/8.2/apache2/php.ini
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
a2enmod rewrite
systemctl restart apache2
rm /var/www/html/index.html
配置 ODBC
cat <<EOF > /etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL (MariaDB)
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so
FileUsage = 1
EOF
cat <<EOF > /etc/odbc.ini
[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
安装 FreePBX
cd /usr/local/src
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-17.0-latest-EDGE.tgz
tar zxvf freepbx-17.0-latest-EDGE.tgz
cd /usr/local/src/freepbx/
./start_asterisk start
./install -n
获取其余模块
这步是安装所有模块,也可以跳过,后续选择需要的单个模块安装
fwconsole ma installall
fwconsole reload
fwconsole restart
设置 systemd(启动脚本)
cat <<EOF > /etc/systemd/system/freepbx.service
[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
EOF
systemctl daemon-reload
systemctl enable freepbx
打开端口网关
ufw allow proto tcp from any to any port 80,443
云服务器相关安全组放开相应端口
登录管理界面