Nhảy đến nội dung chính

Lab triển khai tổng đài FreePBX 17 trên Debian 12

Chuẩn bị

  • Debian v12 (Bookworm), x64 minimal install
  • Asterisk v20
  • Freepbx v17
  • PHP v8.2

Cập nhập hệ thống và các cài các gói cơ bản

timedatectl set-timezone Aisa/Ho_Chi_Minh
apt update && apt -y upgrade && reboot
apt -y install locales sngrep build-essential net-tools aptitude openssh-server apache2 mariadb-server mariadb-client odbc-mariadb bison doxygen flex curl sox libncurses5-dev libssl-dev libmariadb-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool-bin autoconf git subversion uuid uuid-dev libiksemel-dev postfix mailutils nano ntp libspandsp-dev libcurl4-openssl-dev libical-dev libneon27-dev libasound2-dev libogg-dev libvorbis-dev libicu-dev libsrtp*-dev unixodbc unixodbc-dev xinetd e2fsprogs dbus sudo xmlstarlet lame ffmpeg dirmngr linux-headers-`uname -r` gnupg2 nodejs npm ipset incron

Cài PHP

apt -y install php8.2 php8.2-curl php8.2-cli php8.2-mysql php8.2-mbstring php8.2-gd php8.2-xml php8.2-intl php-pear libapache2-mod-php

Tạo cấu hình ODBC

cat > /etc/odbcinst.ini << EOF
[MySQL]
Description = ODBC for MariaDB
Driver = libmaodbc.so
FileUsage = 1
EOF
cat > /etc/odbc.ini << EOF
[MySQL-asteriskcdrdb]
Description = MariaDB connection to 'asteriskcdrdb' database
driver = MySQL
server = localhost
database = asteriskcdrdb
Port = 3306
Socket = /var/run/mysqld/mysqld.sock
option = 3
EOF

Cài đặt Asterisk

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20-current.tar.gz
tar zxvf asterisk-20-current.tar.gz
cd /usr/src/asterisk-20*/
./contrib/scripts/get_mp3_source.sh 
./contrib/scripts/install_prereq install
make distclean
./configure --with-jansson-bundled
cd /usr/src/asterisk-20*/
make menuselect 

Chọn app_macrochan_sip.

adduser asterisk --disabled-password --gecos "Asterisk User"
make && make install && chown -R asterisk:asterisk /var/lib/asterisk
make samples

Cài FreePBX

cd /usr/src
git clone -b release/17.0 --single-branch https://github.com/freepbx/framework.git freepbx
cd /usr/src/freepbx
./start_asterisk start
./install -n

fwconsole ma installall
fwconsole chown
fwconsole restart

Thiết lập Freepbx để khi khởi động hệ thống tự start

cat >> /etc/systemd/system/freepbx.service << EOF
[Unit]
Description=Freepbx
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 enable freepbx

Cấu hình Apache

Thêm cấu hình sau để web đọc trực tiếp từ .htaccess

cat >> /etc/apache2/conf-available/allowoverride.conf << EOF 
<Directory /var/www/html>
    AllowOverride All
    </Directory>
EOF
a2enconf allowoverride
sed -i 's/\(APACHE_RUN_USER=\)\(.*\)/\1asterisk/g' /etc/apache2/envvars
sed -i 's/\(APACHE_RUN_GROUP=\)\(.*\)/\1asterisk/g' /etc/apache2/envvars
chown asterisk:asterisk /run/lock/apache2
mv /var/www/html/index.html /var/www/html/index.html.disable
a2enmod rewrite
systemctl restart apache2

Truy cập UI

Truy cập Freepbx GUI qua http://yourserverIP và thiết lập user để đăng nhập.

Cài đặt Log File Rotation

nano /etc/logrotate.d/asterisk
/var/spool/mail/asterisk
/var/log/asterisk/full
/var/log/asterisk/dtmf
/var/log/asterisk/fail2ban
/var/log/asterisk/freepbx.log
/var/log/asterisk/freepbx_security.log 
/var/log/asterisk/freepbx_debug {
        size 50M
        missingok
        rotate 5
        #compress
        notifempty
        sharedscripts
        create 0640 asterisk asterisk
        postrotate
        /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null || true
        endscript
        su root root
}

Cài đặt php memory limit và upload max file size

sed -i 's/memory_limit = .*/memory_limit = 256M/g' /etc/php/8.2/apache2/php.ini
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 20M/g' /etc/php/8.2/apache2/php.ini
systemctl restart apache2

Mời cà phê

Nếu cảm thấy blog mang đến những thông tin hữu ích cho công việc, cuộc sống, đam mê của bạn, đừng ngại ủng hộ một ly cà phê để mình có thêm động lực chia sẻ thêm nhiều kinh nghiệm, kiến thức nhé.

Bạn có thể ủng hộ mình qua:

Ví MoMo

image.png

Ví MoMo

Paypal

Hỗ trợ qua Paypal

Cám ơn mọi người!