2016-09-14 44 views
0

我的主服务器出现问题,其中主要的php5-fpm进程会被一个HUP信号中止。在主进程被杀死后,将无法重生。由于每个子进程只允许服务器发送一定数量的请求,它们最终会死亡而不会产生其他子进程。这会导致服务器死机,我的用户会收到来自服务器的502响应。我最初能够通过有一个cron将检查PHP进程的线程数,然后重新启动来解决这个问题,如果搜索不到5php5-fpm,被HUP杀死信号:主进程无法重新生成

Sep 14 11:41:41 ubuntu kernel: [ 3699.092724] init: php5-fpm main process (3592) killed by HUP signal 
Sep 14 11:41:41 ubuntu kernel: [ 3699.092740] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.160940] init: php5-fpm main process (3611) terminated with status 78 
Sep 14 11:41:42 ubuntu kernel: [ 3699.160954] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.216950] init: php5-fpm main process (3619) terminated with status 78 
Sep 14 11:41:42 ubuntu kernel: [ 3699.216966] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.283573] init: php5-fpm main process (3627) terminated with status 78 
Sep 14 11:41:42 ubuntu kernel: [ 3699.283590] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.337563] init: php5-fpm main process (3635) terminated with status 78 
Sep 14 11:41:42 ubuntu kernel: [ 3699.337579] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.385293] init: php5-fpm main process (3643) terminated with status 78 
Sep 14 11:41:42 ubuntu kernel: [ 3699.385305] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.430903] init: php5-fpm main process (3651) terminated with status 78 
Sep 14 11:41:42 ubuntu kernel: [ 3699.430913] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.482790] init: php5-fpm main process (3659) terminated with status 78 
Sep 14 11:41:42 ubuntu kernel: [ 3699.482800] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.532239] init: php5-fpm main process (3667) terminated with status 78 
Sep 14 11:41:42 ubuntu kernel: [ 3699.532249] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.595810] init: php5-fpm main process (3675) terminated with status 78 
Sep 14 11:41:42 ubuntu kernel: [ 3699.595825] init: php5-fpm main process ended, respawning 
Sep 14 11:41:42 ubuntu kernel: [ 3699.648253] init: php5-fpm main process (3683) terminated with status 78 
Sep 14 11:41:42 ubuntu0 kernel: [ 3699.648265] init: php5-fpm respawning too fast, stopped 

我新贵脚本配置

# php5-fpm - The PHP FastCGI Process Manager 

description "The PHP FastCGI Process Manager" 
author "Ondřej Surý <[email protected]>" 

start on runlevel [2345] 
stop on runlevel [016] 

# Precise upstart does not support reload signal, and thus rejects the 
# job. We'd rather start the daemon, instead of forcing users to 
# reboot https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1272788 
# 
#reload signal USR2 

pre-start exec /usr/lib/php5/php5-fpm-checkconf 

respawn 
exec /usr/sbin/php5-fpm --nodaemonize --fpm-config /etc/php5/fpm/php-fpm.conf 

回答

2

后互联网终于能够通过修改php5-fpm新贵脚本/etc/init/php5-fpm.conf

# php5-fpm - The PHP FastCGI Process Manager 

description "The PHP FastCGI Process Manager" 
author "Ondřej Surý <[email protected]>" 

start on runlevel [2345] 
stop on runlevel [016] 

# Precise upstart does not support reload signal, and thus rejects the 
# job. We'd rather start the daemon, instead of forcing users to 
# reboot https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1272788 
# 
#reload signal USR2 

pre-start exec /usr/lib/php5/php5-fpm-checkconf 
pre-start exec /bin/bash /etc/init/php5-fpm.sh 
post-start exec /bin/bash /etc/init/php5-fpm-onstart.sh 

respawn 
exec /usr/sbin/php5-fpm --nodaemonize --fpm-config /etc/php5/fpm/php-fpm.conf 

因此增加额外的凭证得到了解决这一php5-fpm.conf中的ts pre-startpost-start。该pre-start脚本

#!/bin/bash 
rm /var/run/php5-fpm.pid 
rm /var/run/php5-fpm.sock 
CHILD_PIDS_FILE="/var/run/php5-fpm-child.pid" 
CHILD_PIDS=`ps -ef | grep 'php' | grep -v grep |awk '{print $2}'` 
echo "$CHILD_PIDS" > "$CHILD_PIDS_FILE" 

脚本基本上删除main process PID和sock文件。然后将子进程的pid写入该文件,以便在创建新进程php5-fpm时可以将其删除。

post-start脚本

#!/bin/bash 
CHILD_PIDS_FILE="/var/run/php5-fpm-child.pid" 
while read PID; do 
    kill -9 $PID 
done < $CHILD_PIDS_FILE 
>$CHILD_PIDS_FILE 

post-start脚本删除所有被php5-fpm重启之前运行儿童的PID。