1. 程式人生 > >在Debian 8上安裝ASTPP計費系統

在Debian 8上安裝ASTPP計費系統

遇到 post data start setup sendmai fix unixodbc sym

之前把ASTPP安裝在了CentOS 7上,結果測試發現不支持視頻通話,查詢Freeswitch文檔後得知是CentOS 7沒有相關的程序包來支持編譯Freeswitch的視頻模塊。還是只能回到Debian 8上來安裝。官方其實也是推薦用Debian 8的,畢竟Freeswitch是在它上面開發和測試的。
和上次一樣找來ASTPP的安裝文檔,發現依然有坑。
http://astpp.readthedocs.io/en/v3.6/Installation/debian8_installation.html

#Install base packages

apt-get -o Acquire::Check-Valid-Until=false update

apt-get install -y git wget curl
useradd -G freeswitch -------文檔裏沒有加這個用戶名,不加無法使用啟動腳本啟動freeswitch

#Install Freeswitch

  1. Install Freeswitch pre-requisite packages

#Add freeswitch source list
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/ jessie main" > /etc/apt/sources.list.d/freeswitch.list

#Add php7.0 source list
echo "deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all" > /etc/apt/sources.list.d/php7.list
curl https://www.dotdeb.org/dotdeb.gpg | apt-key add -

#Install dependencies
apt-get -o Acquire::Check-Valid-Until=false update && apt-get install -y --force-yes freeswitch-video-deps-most

apt-get install -y autoconf automake devscripts gawk chkconfig dnsutils sendmail-bin sensible-mda ntpdate ntp g++ \
git-core curl libjpeg62-turbo-dev libncurses5-dev make python-dev pkg-config libgdbm-dev libyuv-dev libdb-\
dev libvpx2-dev gettext sudo lua5.1 php7.0 php7.0-dev php7.0-common php7.0-cli php7.0-gd php-pear \
php7.0-apc php7.0-curl libxml2 libxml2-dev openssl libcurl4-openssl-dev gettext gcc libldns-dev \
libpcre3-dev build-essential libssl-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev libldns-dev libpq-dev bc

#Install mysql server
apt-get install -y mysql-server php7.0-mysql

  1. Download latest freeswitch version

cd /usr/local/src
git config --global pull.rebase true

#Clone freeswitch version 1.6 from git
git clone -b v1.6.19 https://freeswitch.org/stash/scm/fs/freeswitch.git
cd freeswitch
./bootstrap.sh -j

  1. Edit modules.conf

#Enabling mod_xml_curl, mod_json_cdr, mod_db
sed -i "s##xml_int/mod_xml_curl#xml_int/mod_xml_curl#g" /usr/local/src/freeswitch/modules.conf
sed -i "s##mod_db#mod_db#g" /usr/local/src/freeswitch/modules.conf
sed -i "s##applications/mod_voicemail#applications/mod_voicemail#g" /usr/local/src/freeswitch/modules.conf
sed -i "s##event_handlers/mod_json_cdr#event_handlers/mod_json_cdr#g" /usr/local/src/freeswitch/modules.conf

  1. Compile the Source

./configure -C

  1. Install Freeswitch with sound files

make all install cd-sounds-install cd-moh-install
make && make install
chown -Rf freeswitch.daemon /usr/local/freeswitch -------不加這一句,啟動freeswitch時會遇到權限不足,無法啟動。

  1. Set right time in server

ntpdate pool.ntp.org
systemctl restart ntp
chkconfig ntp on

  1. Create symbolic links for Freeswitch executables

ln -s /usr/local/freeswitch/bin/freeswitch /usr/local/bin/freeswitch
ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/fs_cli

ASTPP Install

  1. Download ASTPP

cd /usr/src
git clone -b v3.6 https://github.com/iNextrix/ASTPP

  1. Change Apache working scenario

systemctl stop apache2
systemctl disable apache2
apt-get remove -y apache2 ----------ASTPP 3.6已經不支持apache2了,必須卸載並安裝Nginx。

  1. Install ASTPP pre-requisite packages

apt-get -o Acquire::Check-Valid-Until=false update

apt-get install -y curl libyuv-dev libvpx2-dev nginx php7.0-fpm php7.0 php7.0-mcrypt libmyodbc unixodbc-bin php7.0-dev \
php7.0-common php7.0-cli php7.0-gd php-pear php7.0-cli php7.0-apc php7.0-curl libxml2 libxml2-dev openssl libcurl4-openssl-\
dev gettext gcc g++

  1. Normalize ASTPP

#Create access & error log files.
touch /var/log/nginx/astpp_access_log
touch /var/log/nginx/astpp_error_log
touch /var/log/nginx/fs_access_log
touch /var/log/nginx/fs_error_log
systemctl restart php7.0-fpm
service nginx reload

ASTPP using FreeSWITCH (if you want to use ASTPP with FreeSWITCH)

  1. Configure freeswitch startup script

cp /usr/src/ASTPP/freeswitch/init/freeswitch.debian.init /etc/init.d/freeswitch --------最大的坑就是這個啟動腳本,用它無法啟動freeswitch。

chmod 755 /etc/init.d/freeswitch
chmod +x /etc/init.d/freeswitch
update-rc.d freeswitch defaults
chkconfig --add freeswitch
chkconfig --level 345 freeswitch on

  1. Configure ASTPP with freeswitch

#Create directory structure for ASTPP
mkdir -p /var/lib/astpp/
mkdir -p /var/log/astpp/
mkdir -p /usr/local/astpp/
mkdir -p /var/www/

#Setting permisssion
chown -Rf root.root /var/lib/astpp/
chown -Rf www-data.www-data /var/log/astpp/
chown -Rf root.root /usr/local/astpp/
chown -Rf www-data.www-data /var/www/

#Setting up Scripts and Sounds for fs
cp -rf /usr/src/ASTPP/freeswitch/scripts/ /usr/local/freeswitch/scripts/
cp -rf /usr/src/ASTPP/freeswitch/fs /var/www/html/
cp -rf /usr/src/ASTPP/freeswitch/sounds/
.wav /usr/local/freeswitch/sounds/en/us/callie/
chmod -Rf 777 /usr/local/freeswitch/sounds/en/us/callie/
rm -rf /usr/local/freeswitch/conf/dialplan/
touch /usr/local/freeswitch/conf/dialplan/astpp.xml
rm -rf /usr/local/freeswitch/conf/directory/

touch /usr/local/freeswitch/conf/directory/astpp.xml
rm -rf /usr/local/freeswitch/conf/sip_profiles/*
touch /usr/local/freeswitch/conf/sip_profiles/astpp.xml

Install ASTPP web interface

mkdir -p /var/lib/astpp
cp /usr/src/ASTPP/config/* /var/lib/astpp/

#Setup web interface for ASTPP
mkdir -p /var/www/html/astpp
cp -rf /usr/src/ASTPP/web_interface/astpp/ /var/www/html/astpp/
chown -Rf www-data.www-data /var/www/html/astpp
cp /usr/src/ASTPP/webinterface/nginx/deb
/etc/nginx/conf.d/

chmod -Rf 755 /var/www/html/astpp
touch /var/log/astpp/astpp.log
chown -Rf www-data.www-data /var/log/astpp/astpp.log

Install ASTPP Database

#Restart mysql service
systemctl restart mysql
mysql -uroot -e "UPDATE mysql.user SET password=PASSWORD(‘<MYSQL_ROOT_PASSWORD>‘) WHERE user=‘root‘; FLUSH PRIVILEGES;"

#Create database astpp
mysql -uroot -p<MYSQL_ROOT_PASSWORD> -e "create database astpp;"
mysql -uroot -p<MYSQL_ROOT_PASSWORD> -e "CREATE USER ‘astppuser‘@‘localhost‘ IDENTIFIED BY ‘<ASTPP_USER_PASSWORD>‘;"
mysql -uroot -p<MYSQL_ROOT_PASSWORD> -e "GRANT ALL PRIVILEGES ON `astpp` . * TO ‘astppuser‘@‘localhost‘ WITH
GRANT OPTION;FLUSH PRIVILEGES;"
mysql -uroot -p<MYSQL_ROOT_PASSWORD> astpp < /usr/src/ASTPP/database/astpp-3.0.sql
mysql -uroot -p<MYSQL_ROOT_PASSWORD> astpp < /usr/src/ASTPP/database/astpp-upgrade-3.5.sql
mysql -uroot -p<MYSQL_ROOT_PASSWORD> astpp < /usr/src/ASTPP/database/astpp-upgrade-3.6.sql

#Setup ODBC Connection for mysql
cp /usr/src/ASTPP/misc/odbc/deb_odbc.ini /etc/odbc.ini
cp /usr/src/ASTPP/misc/odbc/deb_odbcinst.ini /etc/odbcinst.ini

#Update your mysql login information in odbc file
sed -i "s#PASSWORD = <PASSWORD>#PASSWORD = <MYSQL_ROOT_PASSWORD>#g" /etc/odbc.ini

Note:- Replace "<MYSQL_ROOT_PASSWORD>" with your mysql root login password and "<ASTPP_USER_PASSWORD>" is as per
your choice.
ASTPP Freeswitch Configuration

cp /usr/src/ASTPP/freeswitch/conf/autoload_configs/* /usr/local/freeswitch/conf/autoload_configs/

#Edit db password in autoload config files.
sed -i "s#dbpass = <PASSSWORD>#dbpass = <MYSQL_ROOT_PASSWORD>#g" /var/lib/astpp/astpp-config.conf
sed -i "s#DB_PASSWD=\"<PASSSWORD>\"#DB_PASSWD = \"<MYSQL_ROOT_PASSWORD>\"#g" /var/lib/astpp/astpp.lua

#Edit base URL in astpp-config
sed -i "s#base_url=http://localhost:8089/#base_url=http://<SERVER FQDN / IP ADDRESS>:8089/#g" /var/lib/astpp/
astpp-config.conf

Note:- Replace "<SERVER FQDN / IP ADDRESS>" with your server domain name or IPaddress --------如果沒有外網IP,只填內網ip,就只能從內網訪問。這裏填的是我的外網固定IP,雖然我的服務器上只配置了內網IP。

Finalize Installation & Start Services

#Open php short tag
sed -i "s#short_open_tag = Off#short_open_tag = On#g" /etc/php/7.0/fpm/php.ini
sed -i "s#;cgi.fix_pathinfo=1#cgi.fix_pathinfo=1#g" /etc/php/7.0/fpm/php.ini
sed -i "s/max_execution_time = 30/max_execution_time = 3000/" /etc/php/7.0/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/php/7.0/fpm/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 20M/" /etc/php/7.0/fpm/php.ini
sed -i "s/memory_limit = 128M/memory_limit = 512M/" /etc/php/7.0/fpm/php.ini
systemctl restart php7.0-fpm
systemctl restart nginx

#Configure services for startup
systemctl disable apache2 #If you are using it then change the port or update your configuration for nginx
otherwise your gui will not up
systemctl enable nginx
systemctl enable php7.0-fpm
systemctl start mysql
systemctl start freeswitch
chkconfig --levels 345 mariadb on
chkconfig --levels 345 freeswitch on

Note:- If you want to use iptables then configure it to allow all port used in fs and ASTPP.
Setup cron

#Generate Invoice
0 12 * cd /var/www/html/astpp/cron/ && php cron.php GenerateInvoice

#Update balance notification
0 12 * cd /var/www/html/astpp/cron/ && php cron.php UpdateBalance

#Low balance notification
0 0 * cd /var/www/html/astpp/cron/ && php cron.php LowBalance

#Update currency rate
0 0 * cd /var/www/html/astpp/cron/ && php cron.php CurrencyUpdate

#Email Broadcasting
0 0 * cd /var/www/html/astpp/cron/ && php cron.php BroadcastEmail
Finally Reboot it.

#You are almost done with your configuration so just reboot it and make sure everything is working fine.

reboot now

#Once server up and running again, check below service status.
systemctl status nginx
systemctl status mysql
systemctl status freeswitch
systemctl status php7.0-fpm

在Debian 8上安裝ASTPP計費系統