如何为asterCC系统配置多台PHP服务器

系统详情

  • CTI(Asterisk)、Nginx:192.168.1.62 (外网IP:110.249.148.246)
  • MySQL:192.168.1.60
  • PHP1:192.168.1.61
  • PHP2:192.168.1.70

注:做分布之前,先确保所有服务器的asterCC的版本必须是一样的,其次 安装相同的模块。

多台集群服务器,请确保除了CTI上的asterccd进程正常启动外其它服务器该进程停止运行,且设置chkconfig关闭asterccd开机自动启动。mysql上crontab -e内设置的astercc定时任务全部用“#”号注释掉。

1.对系统进行分布配置前,首先需要将CTI机器上的数据库备份。

 mysqldump -uroot -p密码 astercc10 > 备份文件.sql 

再在新的mysql数据库服务器(192.168.1.60)上进行备份数据的导入。

 mysql -uroot -p密码 astercc10 < 备份文件.sql 

2.在MySQL机器上,对CTI、PHP1、PHP2机器进行数据库的授权。 在 mysql> 下执行如下命令:

 grant all privileges on astercc10.* to astercc@'192.168.1.%' identified by 'asterccpw'; 

3.分别在CTI、PHP1、PHP2三台机器上的/etc/astercc.conf 中,修改:[database]和[statistics]标签下的数据库信息:

[database] 
dbtype = mysql 
dbhost = 192.168.1.60 
dbname = astercc10 
dbport = 3306 
username = astercc 
password = asterccpw 
prefix= cc10_ 

[statistics] 
;on/off 
status = on 
dbtype = mysql 
dbhost = 192.168.1.60 
dbname = astercc10 
dbport = 3306 
dbuser = astercc 
dbpassword = asterccpw 
prefix= cc10_ 


[system] 
;if Cluster no,php,asterisk,all 
cluster = php 

注:该conf文件中system的标签下,做什么集群,就将该处修改成什么。

4.在/var/www/html/asterCC/app/config/database.php文件中将文件末尾的 var $default = array数据库信息修改成如下内容:

class DATABASE_CONFIG {

      var $default = array( 
              'driver' => 'mysql', 
              'persistent' => false, 
              'host' => '192.168.1.60', 
              'login' => 'astercc', 
              'password' => 'asterccpw', 
              'database' => 'astercc10', 
              'prefix' => 'cc10_', 
              'encoding' => 'utf8', 
      ); 

注:$test 的内容无需修改。

5.配置iptables服务,各机器配置完成后执行:service iptables restart

CTI(和Nginx)机器上:

*filter 
:INPUT DROP [32888:6036616] 
:FORWARD DROP [0:0] 
:OUTPUT ACCEPT [38964:13133002] 
-A INPUT -p udp -m udp --dport 5060 -j ACCEPT 
-A INPUT -p udp -m udp --dport 4569 -j ACCEPT 
-A INPUT -p udp -m udp --dport 5036 -j ACCEPT 
-A INPUT -p udp -m udp --dport 10000:20000 -j ACCEPT 
-A INPUT -p udp -m udp --dport 2727 -j ACCEPT 
-A INPUT -p udp -m udp --dport 137:138 -j ACCEPT 
-A INPUT -p udp -m udp --dport 123 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 8081 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 139 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 389 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 445 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 5038 -j ACCEPT 
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT 
-A INPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -j ACCEPT 
-A INPUT -m state --state ESTABLISHED -j ACCEPT 
COMMIT

MySQL机器上:

*filter 
:INPUT DROP [32888:6036616] 
:FORWARD DROP [0:0] 
:OUTPUT ACCEPT [38964:13133002] 
-A INPUT -p udp -m udp --dport 5060 -j ACCEPT 
-A INPUT -p udp -m udp --dport 4569 -j ACCEPT 
-A INPUT -p udp -m udp --dport 5036 -j ACCEPT 
-A INPUT -p udp -m udp --dport 10000:20000 -j ACCEPT 
-A INPUT -p udp -m udp --dport 2727 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT 
-A INPUT -p udp -m udp --dport 161 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 161 -j ACCEPT 
-A INPUT -p udp -m udp --dport 162 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 162 -j ACCEPT 
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT 
-A INPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -j ACCEPT 
-A INPUT -m state --state ESTABLISHED -j ACCEPT 
COMMIT 

PHP1机器上:

*filter 
:INPUT ACCEPT [32888:6036616] 
:FORWARD ACCEPT [0:0] 
:OUTPUT ACCEPT [38964:13133002] 
-A INPUT -p udp -m udp --dport 5060 -j ACCEPT 
-A INPUT -p udp -m udp --dport 4569 -j ACCEPT 
-A INPUT -p udp -m udp --dport 5036 -j ACCEPT 
-A INPUT -p udp -m udp --dport 10000:20000 -j ACCEPT 
-A INPUT -p udp -m udp --dport 2727 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 9000 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 5038 -j ACCEPT 
COMMIT 

PHP2机器上: 同PHP1

端口说明:请按实际情况,对/etc/sysconfig/iptables文件中端口进行保留。
21:FTP默认端口
22:SSH默认端口
80:http默认端口,由于我的机器改成8081了,所以CTI的iptables添加了8081
123:NTP默认端口
137:udp samba的端口
138:udp samba的端口
139:tcp samba的端口
389:tcp samba的端口
445:tcp samba的端口
901:tcp samba的端口
161:SNMP的端口
162:SNMP-trap的端口
443:https默认端口
2727:MGCP默认端口
3306:mysql默认端口
4569:IAX2默认端口
5036:IAX1默认端口
5038:Asterisk默认端口
5060:sip默认端口
9000:php默认端口
10000:20000:Asterisk中RTP要使用的端口

6.在CTI、PHP1上安装samba服务,执行命令:

 yum install samba 

7.安装完成后,分别创建samba用户及密码,如:sbu/123456, 先执行:

 useradd sbu 
再执行,并在提示时输入123456:
 smbpasswd -a sbu 

8.修改samba配置文件 /etc/samba/smb.conf,在smb.conf 文件末尾添加如下内容:

CTI机器上:

[ccastspool] 
        path = /var/spool/asterisk 
        comment = Home Directories 
        browseable = no 
        writable = yes 
;       valid users = %S 
;       valid users = MYDOMAIN\%S 
        create mask=777 
        directory mask = 777 
        force user = asterisk 

[ccastetc] 
        path = /etc/asterisk/ 
        comment = Home Directories 
        browseable = no 
        writable = yes 
;       valid users = %S 
;       valid users = MYDOMAIN\%S 
        create mask=777 
        directory mask = 777 
        force user = asterisk 

[ccastlib] 
        path = /var/lib/asterisk/ 
        comment = Home Directories 
        browseable = no 
        writable = yes 
;       valid users = %S 
;       valid users = MYDOMAIN\%S 
        create mask=777 
        directory mask = 777 
        force user = asterisk 

[ccscripts] 
        path = /opt/asterisk/scripts/astercc 
        comment = Home Directories 
        browseable = no 
        writable = yes 
;       valid users = %S 
;       valid users = MYDOMAIN\%S 
        create mask=777 
        directory mask = 777 
        force user = asterisk

PHP1机器上:

[ccdata] 
        path = /var/www/html/asterCC/data 
        comment = Home Directories 
        browseable = no 
        writable = yes 
;       valid users = %S 
;       valid users = MYDOMAIN\%S 
        create mask=777 
        directory mask = 777 
        force user = asterisk 

[ccstatistics] 
        path = /var/www/html/asterCC/statistics 
        comment = Home Directories 
        browseable = no 
        writable = yes 
;       valid users = %S 
;       valid users = MYDOMAIN\%S 
        create mask=777 
        directory mask = 777 
        force user = asterisk 

9.配置完成后,重启Samba 服务配置生效,执行命令:

 service smb restart 

10.将samba的文件,相互挂载。(注:挂载之前,请先将本机要mount过来的代码进行备份。比如:在CTI机器上,需要mount PHP1机器上的ccdata 到CTI机器的 /var/www/html/asterCC/data 目录,那么需要在CTI机器上,将/var/www/html/asterCC/data 进行备份,备份过程此处不做详细讲述)

CTI机器上,依次执行命令,进行挂载:

mount -t cifs -o username=sbu,password=123456 //192.168.1.61/ccdata /var/www/html/asterCC/data
mount -t cifs -o username=sbu,password=123456 //192.168.1.61/ccstatistics /var/www/html/asterCC/statistics 

PHP1机器上,依次执行命令,进行挂载:

mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastspool /var/spool/asterisk 
mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccscripts /opt/asterisk/scripts/astercc 
mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastlib /var/lib/asterisk 
mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastetc /etc/asterisk

PHP2机器上,依次执行命令,进行挂载:

mount -t cifs -o username=sbu,password=123456 //192.168.1.61/ccstatistics /var/www/html/asterCC/statistics
mount -t cifs -o username=sbu,password=123456 //192.168.1.61/ccdata /var/www/html/asterCC/data
mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastspool /var/spool/asterisk 
mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastlib /var/lib/asterisk 
mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastetc /etc/asterisk 
mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccscripts /opt/asterisk/scripts/astercc

11.修改 /etc/php-fpm.d/www.conf 配置文件内容 CTI机器上:

[www]
listen=127.0.0.1:9000
listen.allowed_clients=127.0.0.1

PHP1机器上:

[www]
listen=192.168.1.61:9000
listen.allowed_clients=127.0.0.1,192.168.1.61,192.168.1.62

PHP2机器上:

[www]
listen=192.168.1.70:9000
listen.allowed_clients=127.0.0.1,192.168.1.70,192.168.1.62

12.修改/usr/local/nginx/conf/nginx.conf 配置文件 CTI机器上:

12-1:在http中添加以下内容:

upstream myphp { 
        #ip_hash; PHP负载均衡
        server 192.168.1.61:9000 weight=2; 
        server 192.168.1.70:9000 weight=2; 
    }

注:http中server内的listen xxxx default,是指的页面访问的端口号。

12-2:在location中前面位置添加以下内容,并将默认配置的fastcgi_pass 127.0.0.1:9000; 用#号注释掉:

       #这个表示login和reload时,使用本机的PHP服务,因此CTI的php-fpm服务是开启的,而且开机自启动
        set $target myphp; 
        if ($request_uri ~* login) { 
            set $target 127.0.0.1:9000; 
        } 
        if ($request_uri ~* reloadConf) { 
            set $target 127.0.0.1:9000; 
        } 
        fastcgi_pass  $target; 
        #fastcgi_pass  127.0.0.1:9000; 

注:PHP1与PHP2机器上,这些配置都不用管,因为PHP1和PHP2上不使用nginx服务,默认fastcgi_pass 均为 127.0.0.1:9000;

如果只使用1台服务器(如:PHP1)运行PHP服务,而不使用PHP负载均衡,那么,CTI中不需要添加任何的内容。并且,location中第一句set $target myphp; 内容也需要修改成PHP1的地址加端口,即:set $target 192.168.1.61:9000;

13.授权相关文件的共用

CTI机器上:

13-1:先拷贝到mount的目录:

 cp -Rp /var/www/html/asterCC/app/views/agents/agentsxindesk.ctp /var/www/html/asterCC/statistics/agentsxindesk.ctp 
再执行:
 ln -s /var/www/html/asterCC/statistics/agentsxindesk.ctp /var/www/html/asterCC/app/views/agents/agentsxindesk.ctp 

13-2:拷贝:

 cp -Rp /var/www/html/asterCC/app/config/database.php /var/www/html/asterCC/statistics/database.php 
再执行:
 ln -s /var/www/html/asterCC/statistics/database.php /var/www/html/asterCC/app/config/database.php 

13-3:/opt/asterisk/scripts/astercc/identity.astercc 文件,不用做任何操作,但要保证该文件,是最开始CTI机器上mount前备份过的文件。

13-4:/opt/asterisk/scripts/astercc/license.astercc文件, 不用做任何操作,但要保证该文件,是最开始CTI机器上mount前备份过的文件。

13-5:拷贝:

 cp -Rp /usr/local/conf/hcdesk.conf /opt/asterisk/scripts/astercc/hcdesk.conf 
再执行:
 ln -s /opt/asterisk/scripts/astercc/hcdesk.conf /usr/local/conf/hcdesk.conf 

13-6:拷贝:

 cp -Rp /etc/astercc.conf /opt/asterisk/scripts/astercc/astercc.conf 
再执行:
 ln -s /opt/asterisk/scripts/astercc/astercc.conf /etc/astercc.conf 

PHP1机器上:

13-7:将本机的agentsxindesk.ctp文件备份成agentsxindesk.ctp.bak 备份:

 mv /var/www/html/asterCC/app/views/agents/agentsxindesk.ctp /var/www/html/asterCC/app/views/agents/agentsxindesk.ctp.bak 
再执行:
 ln -s /var/www/html/asterCC/statistics/agentsxindesk.ctp /var/www/html/asterCC/app/views/agents/agentsxindesk.ctp 

13-8:备份:

 mv /var/www/html/asterCC/app/config/database.php /var/www/html/asterCC/app/config/database.php.bak 
再执行:
 ln -s /var/www/html/asterCC/statistics/database.php /var/www/html/asterCC/app/config/database.php 

13-9:将本机的hcdesk.conf文件备份成hcdesk.conf.bak 备份:

 mv /usr/local/conf/hcdesk.conf /usr/local/conf/hcdesk.conf.bak 
再执行:
 ln -s /opt/asterisk/scripts/astercc/hcdesk.conf /usr/local/conf/hcdesk.conf 

13-10:将本机的astercc.conf文件备份成astercc.conf.bak 备份:

 mv /etc/astercc.conf /etc/astercc.conf.bak 
再执行:
 ln -s /opt/asterisk/scripts/astercc/astercc.conf /etc/astercc.conf 

PHP2机器上:

13-11:将本机的agentsxindesk.ctp文件备份成agentsxindesk.ctp.bak 备份:

 mv /var/www/html/asterCC/app/views/agents/agentsxindesk.ctp /var/www/html/asterCC/app/views/agents/agentsxindesk.ctp.bak 
再执行:
 ln -s /var/www/html/asterCC/statistics/agentsxindesk.ctp /var/www/html/asterCC/app/views/agents/agentsxindesk.ctp 

13-12:备份:

 mv /var/www/html/asterCC/app/config/database.php /var/www/html/asterCC/app/config/database.php.bak 
再执行:
 ln -s /var/www/html/asterCC/statistics/database.php /var/www/html/asterCC/app/config/database.php 

13-13:将本机的hcdesk.conf文件备份成hcdesk.conf.bak 备份:

 mv /usr/local/conf/hcdesk.conf /usr/local/conf/hcdesk.conf.bak 
再执行:
 ln -s /opt/asterisk/scripts/astercc/hcdesk.conf /usr/local/conf/hcdesk.conf 

13-14:将本机的astercc.conf文件备份成astercc.conf.bak 备份:

 mv /etc/astercc.conf /etc/astercc.conf.bak 
再执行:
 ln -s /opt/asterisk/scripts/astercc/astercc.conf /etc/astercc.conf 

14.修改一些文件的内容

CTI机器上:

/etc/asterisk/manager.conf 文件中,在文件最后面,添加所在网段的信息如下,然后保存退出,执行命令:

 asterisk -rx "manager reload" 

[astercc]
secret = asterccsecret 
deny=0.0.0.0/0.0.0.0 
permit=127.0.0.1/255.255.255.0 
permit=192.168.1.0/255.255.255.0 
read = system,call,agent 
write = system,call,agent,user,config,command,reporting,originate 

/etc/astercc.conf 文件中,[asterisk]标签下,server填写CTI的IP

[asterisk] 
server = 192.168.1.62 
port = 5038 
username = astercc 
secret = asterccsecret 

15.注意/etc/asterisk 的权限,asterisk:asterisk

16.crontab文件内容,执行:crontab -e 进行对其内容的编辑。crontab 中监测启动的程序,互补即可,不要有重复运行的。

CTI:

30 12 * * * /opt/asterisk/scripts/astercc/processmonitors -d 
30 20 * * * /opt/asterisk/scripts/astercc/processmonitors -d 
30 23 * * * /opt/asterisk/scripts/astercc/processmonitors -d 
* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app asterccdelete >/dev/null 2>&1 
10 2 * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app nighttask >/dev/null 2>&1 
10 0 * * * /opt/asterisk/scripts/astercc/agent_report -d 
20 0 * * * /opt/asterisk/scripts/astercc/agentgroup_report -d 

MySQL: 全删除,不需要执行任何程序。

PHP1 和 PHP2,两台机器需要根据配置和负载来划分执行哪些脚本,两台机器不要都执行,做到互补以下脚本即可:

* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app checkonline >/dev/null 2>&1 
* 2 * * * /opt/asterisk/scripts/astercc/astcc_backup.sh >/dev/null 2>&1 
* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app monitortar >/dev/null 2>&1 
* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app backupmonitor >/dev/null 2>&1 
* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app export >/dev/null 2>&1 
* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app asterccimport >/dev/null 2>&1 
*/5 * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app calculate >/dev/null 2>&1 
* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app mailman >/dev/null 2>&1 
* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app campaignpackgetask >/dev/null 2>&1 
* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app blacklistfilter >/dev/null 2>&1 
* * * * * /var/www/html/asterCC/cake/console/cake -app /var/www/html/asterCC/app asterccfilter >/dev/null 2>&1 
* * * * * /opt/asterisk/scripts/astercc/astcc_historydata -d 

17.mount 挂载的检测,需要添加到crontab中。 CTI:

*/5 * * * * dfccdata=`df |grep ccdata`; [ "X${dfccdata}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.61/ccdata /var/www/html/asterCC/data`; 
*/5 * * * * dfccstatistics=`df |grep ccstatistics`; [ "X${dfccstatistics}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.61/ccstatistics /var/www/html/asterCC/statistics`;

PHP1:

*/5 * * * * dfccastspool=`df |grep ccastspool`; [ "X${dfccastspool}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastspool /var/spool/asterisk/`; 
*/5 * * * * dfastetc=`df |grep etc/asterisk`; [ "X${dfastetc}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastetc /etc/asterisk/`; 
*/5 * * * * dfccastlib=`df |grep ccastlib`; [ "X${dfccastlib}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastlib /var/lib/asterisk/`; 
*/5 * * * * dfccscripts=`df |grep ccscripts`; [ "X${dfccscripts}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccscripts /opt/asterisk/scripts/astercc/`;

PHP2:

*/5 * * * * dfccdata=`df |grep ccdata`; [ "X${dfccdata}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.61/ccdata /var/www/html/asterCC/data`; 
*/5 * * * * dfccstatistics=`df |grep ccstatistics`; [ "X${dfccstatistics}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.61/ccstatistics /var/www/html/asterCC/statistics`; 

*/5 * * * * dfccastspool=`df |grep ccastspool`; [ "X${dfccastspool}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastspool /var/spool/asterisk/`; 
*/5 * * * * dfastetc=`df |grep etc/asterisk`; [ "X${dfastetc}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastetc /etc/asterisk/`; 
*/5 * * * * dfccastlib=`df |grep ccastlib`; [ "X${dfccastlib}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccastlib /var/lib/asterisk/`; 
*/5 * * * * dfccscripts=`df |grep ccscripts`; [ "X${dfccscripts}" = "X" ] && `mount -t cifs -o username=sbu,password=123456 //192.168.1.62/ccscripts /opt/asterisk/scripts/astercc/`;

18.最后,

在CTI机器上执行:

 /opt/asterisk/scripts/astercc/asterccc --RNI 
在PHP1机器上执行:
 /opt/asterisk/scripts/astercc/asterccc --ADI 
在PHP2机器上执行:
 /opt/asterisk/scripts/astercc/asterccc --ADI 

正常在CTI上会提示:001,在PHP1上会提示002,在PHP2上会提示003,再重新做授权。在CTI上重启asterccd服务,看是否有报错。

zh/常见问题及解答/如何为astercc系统配置多台php服务器.txt · 最后更改: 2017/12/12 03:05 (外部编辑)
Recent changes RSS feed Debian Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki