Hướng dẫn cài FusionPBX v4.4 Freeswitch v1.6 Debian v8 PostgreSQL Nginx
Fusionpbx là một giao diện quản lí đầy đủ tính năng cho Freeswitch. Hướng dẫn này bao gồm việc cài đặt Fusionpbx và Freeswitch® với PostgreSQL và Apache trên Debian v8.
1.Chuẩn bị
Debian v8 (Jessie) x64
Freeswitch v1.6
FusionPBX v4
Nginx v1.6
PHP v7.1
PostgreSQL v9.4
2.Cài đặt
Chỉnh bảng mã về UTF-8
# Select en_US.UTF-8 UTF-8
dpkg-reconfigure locales
Kiểm tra lại
locale
Cài đặt packages cần thiết.
apt update && apt upgrade -y && apt -y remove apache2
apt -y install git nano dbus sudo nginx curl lsb-release memcached sqlite3 postgresql-9.4 postgresql-client-9.4 haveged ghostscript libtiff5-dev libtiff-tools at tftpd ssl-cert fail2ban
- PHP
apt -y install apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt update && apt -y install php7.1 php7.1-cli php7.1-common php7.1-curl php7.1-mcrypt php7.1-pgsql php7.1-sqlite3 php7.1-odbc php7.1-xml php7.1-imap php7.1-fpm
- Tắt Selinux
KIểm tra lại
sestatus
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config
- Tắt Firewall
systemctl disable firewalld
systemctl disable iptables
systemctl stop firewalld
systemctl stop iptables
- Set Timezone
tzselect
timedatectl set-timezone Asia/Ho_Chi_Minh
timedatectl status
systemctl restart rsyslog
- Cài đặt
Freeswitch
curl https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -
echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ $(lsb_release -sc) main" > \
/etc/apt/sources.list.d/freeswitch.list
apt update && apt -y install freeswitch-all freeswitch-all-dbg freeswitch-sounds* freeswitch-music* gdb
Database
Kiểm tra kết nối với database.
nano +92 /etc/postgresql/9.4/main/pg_hba.conf
host all all 127.0.0.1/32 trust
systemctl restart postgresql
Kiểm tra PostgreSQL locale
sudo -u postgres psql -l
Nếu không phải UTF8
set lại
sudo -u postgres psql
update pg_database set encoding = 6, datcollate = 'en_US.UTF8', datctype = 'en_US.UTF8' where datname = 'template0';
update pg_database set encoding = 6, datcollate = 'en_US.UTF8', datctype = 'en_US.UTF8' where datname = 'template1';
Tạo databases và user
cd /tmp
# Đặt DB password.
password=somepassword
sudo -u postgres psql -c "CREATE DATABASE fusionpbx;"
sudo -u postgres psql -c "CREATE DATABASE freeswitch;"
sudo -u postgres psql -c "CREATE ROLE fusionpbx WITH SUPERUSER LOGIN PASSWORD '$password';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE fusionpbx to fusionpbx;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE freeswitch to fusionpbx;"
Fusionpbx
mkdir -p /etc/fusionpbx
mkdir -p /var/www/fusionpbx
git clone -b 4.4 https://github.com/powerpbx/fusionpbx.git /var/www/fusionpbx
mv /etc/freeswitch /etc/freeswitch.orig
mkdir /etc/freeswitch
cp -R /var/www/fusionpbx/resources/templates/conf/* /etc/freeswitch
Copy music vào thư mục.
mkdir -p /usr/share/freeswitch/sounds/music/default
mv /usr/share/freeswitch/sounds/music/*000/ /usr/share/freeswitch/sounds/music/default/
Php-fpm config
sed 's#post_max_size = .*#post_max_size = 80M#g' -i /etc/php/7.1/fpm/php.ini
sed 's#upload_max_filesize = .*#upload_max_filesize = 80M#g' -i /etc/php/7.1/fpm/php.ini
systemctl restart php7.1-fpm
Nginx config
mkdir -p /etc/nginx/ssl
cd /etc/nginx/sites-available
wget https://raw.githubusercontent.com/powerpbx/fusionpbx-install.sh/master/debian/resources/nginx/fusionpbx
sed -i /etc/nginx/sites-available/fusionpbx -e 's#unix:.*;#unix:/var/run/php/php7.1-fpm.sock;#g'
ln -s /etc/nginx/sites-available/fusionpbx /etc/nginx/sites-enabled/fusionpbx
rm /etc/nginx/sites-enabled/default
# link to self signed certificate
ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/nginx.key
ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/nginx.crt
Dùng letsencrypt
mkdir -p /var/www/letsencrypt/
systemctl restart nginx
Systemd
Tạo config để freeswitch khở động cùng hệ thống.
systemctl stop freeswitch
rm -r /run/freeswitch
nano /etc/systemd/system/freeswitch.service
[Unit]
Description=freeswitch
After=syslog.target network.target local-fs.target postgresql.service
[Service]
Type=forking
RuntimeDirectory=freeswitch
PIDFile=/run/freeswitch/freeswitch.pid
Environment="DAEMON_OPTS=-ncwait -nonat"
EnvironmentFile=-/etc/default/freeswitch
ExecStart=/usr/bin/freeswitch $DAEMON_OPTS
TimeoutSec=45s
Restart=always
User=www-data
Group=www-data
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=60000
LimitSTACK=250000
LimitRTPRIO=infinity
LimitRTTIME=infinity
IOSchedulingClass=realtime
IOSchedulingPriority=2
CPUSchedulingPriority=89
UMask=0007
; Comment this out if using OpenVZ
CPUSchedulingPolicy=rr
[Install]
WantedBy=multi-user.target
Tạo file biến môi trường.
cat >> /etc/default/freeswitch << EOF
# Uncommented variables will override variables in unit file
# User=""
# Group=""
# DAEMON_OPTS=""
EOF
Set ownership and permissions
# Set ownership
chown -R www-data. /etc/freeswitch /etc/fusionpbx /var/lib/freeswitch \
/var/log/freeswitch /usr/share/freeswitch /var/www/fusionpbx /var/run/freeswitch
## Set directory permissions to 755 (u=rwx,g=rx,o='rx')
find /etc/freeswitch -type d -exec chmod 755 {} \;
find /etc/fusionpbx -type d -exec chmod 755 {} \;
find /var/lib/freeswitch -type d -exec chmod 755 {} \;
find /var/log/freeswitch -type d -exec chmod 755 {} \;
find /usr/share/freeswitch -type d -exec chmod 755 {} \;
find /var/www/html -type d -exec chmod 755 {} \;
## Set file permissions to 664 (u=rw,g=rw,o=r)
find /etc/freeswitch -type f -exec chmod 664 {} \;
find /etc/fusionpbx -type f -exec chmod 664 {} \;
find /var/lib/freeswitch -type f -exec chmod 664 {} \;
find /var/log/freeswitch -type f -exec chmod 664 {} \;
find /usr/share/freeswitch -type f -exec chmod 664 {} \;
find /var/www/html -type f -exec chmod 664 {} \;
## Set misc permissions to 755 (u=rwx,g=rx,o='rx')
chmod -R 755 /var/www/fusionpbx/secure
## These two files do not yet exist on a fresh install
chmod 755 /etc/cron.daily/fusionpbx-backup.sh
chmod 755 /etc/cron.daily/fusionpbx-maintenance.sh
Enable services
systemctl daemon-reload
systemctl enable freeswitch
systemctl restart freeswitch
Vào trình duyệt và đăng nhập ip và cài đặt tiếp theo
http://xx.xx.xx.xx
Hoàn thành các bước bên dưới:
Username: superadmin
Password: somesuperadminpassword
Database Name: fusionpbx
Database Username: fusionpbx
Database Password: somepassword
(The database user password created earlier)
Create Database Options: uncheck
Create Database Username:
Create Database Password :
Quá trình cài đặt khoảng 2 phút.
Login vào: Advanced > Default Settings > Adminer(auto_login) > Enabled = True
Reload lại Advanced > Adminer
.
Mở kết nối freeswitch với database
Mặc định Freeswitch kết nối sqlite.
nano +147 /etc/freeswitch/autoload_configs/switch.conf.xml
<param name="core-db-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=fusionpbx password='somepassword'" />
systemctl restart freeswitch
Cấu hình Firewall
apt -y install firewalld
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --permanent --zone=public --add-service={http,https}
firewall-cmd --permanent --zone=public --add-port={5060,5061,5080,5081}/tcp
firewall-cmd --permanent --zone=public --add-port={5060,5061,5080,5081}/udp
firewall-cmd --permanent --zone=public --add-port=16384-32768/udp
firewall-cmd --reload
firewall-cmd --list-all
Tạo script Backup theo ngày.
Backup script
nano /etc/cron.daily/fusionpbx-backup
#!/bin/sh
db_host=127.0.0.1
db_port=5432
now=$(date +%Y-%m-%d)
mkdir -p /var/backups/fusionpbx/postgresql
# Delete postgres backups if older than 4 days
find /var/backups/fusionpbx/postgresql/fusionpbx_pgsql* -mtime +4 -exec rm {} \;
# Delete the main backup if older than 4 days
find /var/backups/fusionpbx/*.tgz -mtime +4 -exec rm {} \;
# Create database backup
pg_dump --verbose -Fc --host=${db_host} --port=${db_port} -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_${now}.sql
# Combine and compress to create the main backup
tar -zvcf /var/backups/fusionpbx/backup_${now}.tgz /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_${now}.sql \
/var/www/fusionpbx /usr/share/freeswitch/scripts /var/lib/freeswitch/storage \
/var/lib/freeswitch/recordings /etc/fusionpbx /etc/freeswitch
chmod 755 /etc/cron.daily/fusionpbx-backup
Housekeeping script
nano /etc/cron.daily/fusionpbx-maintenance
#!/bin/sh
# Delete freeswitch logs older than 7 days
find /var/log/freeswitch/freeswitch.log.* -mtime +7 -exec rm {} \;
## Uncomment to delete call recordings older than 90 days
#find /var/lib/freeswitch/recordings/*/archive/* -name '*.wav' -mtime +90 -exec rm {} \;
#find /var/lib/freeswitch/recordings/*/archive/* -name '*.mp3' -mtime +90 -exec rm {} \;
## Uncomment to delete faxes older than 90 days
#find /var/lib/freeswitch/storage/fax/* -name '*.tif' -mtime +90 -exec rm {} \;
#find /var/lib/freeswitch/storage/fax/* -name '*.pdf' -mtime +90 -exec rm {} \;
## Uncomment to delete voicemails older than 90 days
#find /var/lib/freeswitch/storage/voicemail/default/* -name 'msg_*.wav' -mtime +90 -exec rm {} \;
#find /var/lib/freeswitch/storage/voicemail/default/* -name 'msg_*.mp3' -mtime +90 -exec rm {} \;
#psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_voicemail_messages WHERE to_timestamp(created_epoch) < NOW() - INTERVAL '90 days'"
## Uncomment to delete call detail records older 90 days
#psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_xml_cdr WHERE start_stamp < NOW() - INTERVAL '90 days'"
chmod 755 /etc/cron.daily/fusionpbx-maintenance
Hỗ trợ Dialplan
nano /usr/share/freeswitch/scripts/resources/config.lua
## Change debug options from false to true to see lua generated output in fs_cli
debug["params"] = true;
debug["sql"] = true;
debug["xml_request"] = true;
debug["xml_string"] = true;
debug["cache"] = true;
Như vậy là chúng ta đã hoàn thành việc cài Freeswitch thông qua Fusionpbx để quản lí tổng đài.
Chúc các bạn thành công!
Tham khảo:https://docs.fusionpbx.com/en/latest/getting_started/quick_install.html