php Ubuntu php5-fpm 在重新加载时抛出未知实例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19998526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:20:47  来源:igfitidea点击:

Ubuntu php5-fpm throws unknown instance on reload

ubuntunginxphp

提问by Iulian

I am having some problems with ubuntu and php5-fpm on my VPS. Php works fine, however it throws terminal error when I am trying to reload / restart / stop it. Basically, I cannot stop php because it does not recognize the instance

我的 VPS 上的 ubuntu 和 php5-fpm 有一些问题。Php 工作正常,但是当我尝试重新加载/重新启动/停止它时会引发终端错误。基本上,我无法停止 php,因为它无法识别实例

It says "reload: Unknown instance:" If I try "service php5-fpm restart" it sais unknown instance and gives this in logs

它说“重新加载:未知实例:”如果我尝试“service php5-fpm restart”它说未知实例并在日志中给出

[15-Nov-2013 11:56:40] ERROR: An another FPM instance seems to already listen on /var/run/php5-fpm.sock
[15-Nov-2013 11:56:40] ERROR: FPM initialization failed
[15-Nov-2013 11:56:40] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful

I have php listening on /var/run/php5-fpm.sock ; I use nginx for webserver and it is correctly configured with

我有 php 监听 /var/run/php5-fpm.sock ;我将 nginx 用于网络服务器,并且它已正确配置

fastcgi_pass unix:/var/run/php5-fpm.sock;

(or so I know) Also need to mention that this happened after a reboot.

(或者我知道)还需要提到这是在重新启动后发生的。

Site is working well, however I don't think this is a good sign. Any thoughts ? Thank you.

网站运行良好,但我认为这不是一个好兆头。有什么想法吗 ?谢谢你。

EDIT : I did as suggested in below post. It seems that if i kill the process, and then use start/stop it works fine. However, after I use reload command, it stops recongizing the instance.

编辑:我按照下面的帖子中的建议做了。似乎如果我终止进程,然后使用启动/停止它工作正常。但是,在我使用 reload 命令后,它停止识别实例。

root@developer2:/# service php5-fpm stop
stop: Unknown instance:
root@developer2:/# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Nov14 ?        00:00:00 init
root      1101     1  0 Nov14 ?        00:00:00 /sbin/udevd --daemon
root      1168     1  0 Nov14 ?        00:00:00 /usr/sbin/sshd -D
root      1227     1  0 Nov14 ?        00:00:00 /usr/sbin/xinetd -dontfork -pidfile /var/run/xinetd.pid -stayalive -inetd_compa
root      1229     1  0 Nov14 ?        00:00:00 cron
mysql     1249     1  0 Nov14 ?        00:00:18 /usr/sbin/mysqld
syslog    1283     1  0 Nov14 ?        00:00:00 /sbin/syslogd -u syslog
memcache  1293     1  0 Nov14 ?        00:00:07 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1
root      1426     1  0 Nov14 ?        00:00:00 /usr/lib/postfix/master
postfix   1440  1426  0 Nov14 ?        00:00:00 qmgr -l -t fifo -u
root      1468     1  0 Nov14 ?        00:00:00 /usr/sbin/varnishd -P /var/run/varnishd.pid -a :80 -T localhost:6082 -f /etc/va
nobody    1469  1468  0 Nov14 ?        00:01:14 /usr/sbin/varnishd -P /var/run/varnishd.pid -a :80 -T localhost:6082 -f /etc/va
root      1593     1  0 Nov14 ?        00:00:14 /usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock
root      1595     1  0 Nov14 ?        00:00:00 /usr/lib/gamin/gam_server
www-data  3535     1  0 Nov14 ?        00:00:30 php-fpm: pool www
postfix  10016  1426  0 11:18 ?        00:00:00 pickup -l -t fifo -u -c
root     10064  1168  0 11:37 ?        00:00:00 sshd: root@pts/0
root     10080 10064  0 11:37 pts/0    00:00:00 -bash
root     10143  1168  0 11:47 ?        00:00:00 sshd: root@notty
root     10159 10143  0 11:47 ?        00:00:00 /usr/lib/openssh/sftp-server
root     11330     1  0 12:03 ?        00:00:00 nginx: master process /usr/sbin/nginx
www-data 11331 11330  0 12:03 ?        00:00:00 nginx: worker process
www-data 11332 11330  0 12:03 ?        00:00:00 nginx: worker process
www-data 11333 11330  0 12:03 ?        00:00:00 nginx: worker process
www-data 11334 11330  0 12:03 ?        00:00:00 nginx: worker process
root     11465  1168  0 12:14 ?        00:00:00 sshd: root@notty
root     11481 11465  0 12:14 ?        00:00:00 /usr/lib/openssh/sftp-server
root     11519 10080  0 12:23 pts/0    00:00:00 ps -ef
root@developer2:/# kill 3535
root@developer2:/# service php5-fpm start
php5-fpm start/running, process 11529
root@developer2:/# service php5-fpm stop
php5-fpm stop/waiting
root@developer2:/# service php5-fpm start
php5-fpm start/running, process 11544
root@developer2:/# service php5-fpm stop
php5-fpm stop/waiting
root@developer2:/# service php5-fpm start
php5-fpm start/running, process 11559
root@developer2:/# service php5-fpm reload
root@developer2:/# service php5-fpm reload
reload: Unknown instance:

Edit 2 : my php5 seems to create 3 processes

编辑 2:我的 php5 似乎创建了 3 个进程

root     11813     1  1 12:34 ?        00:00:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 11815 11813  0 12:34 ?        00:00:00 php-fpm: pool www
www-data 11816 11813  0 12:34 ?        00:00:00 php-fpm: pool www

When I use reload function the master process dissapears and I have to manually kill the other 2 processes in order to be able to correctly start it again.

当我使用重新加载功能时,主进程消失了,我必须手动终止其他 2 个进程才能再次正确启动它。

回答by keithm

This is a Ubuntu bug. In /etc/init/php5-fpm.conf, there is a commented-out line reload signal USR2, which causes the reload function to terminate the php5-fpm master process by sending SIGHUP. Any further reloads, restarts or stops will fail, because the master process has been terminated.

这是一个 Ubuntu 错误。在 /etc/init/php5-fpm.conf 中,有一个注释掉的行reload signal USR2,它会导致 reload 函数通过发送 SIGHUP 来终止 php5-fpm 主进程。任何进一步的重新加载、重新启动或停止都将失败,因为主进程已终止。

I fixed this in Ubuntu 14.04 by creating a file /etc/init/php5-fpm.overridewith the single line reload signal USR2in it. Credits to Jurian Sluiman's comment in this answer.

我通过创建一个/etc/init/php5-fpm.override包含单行的文件在 Ubuntu 14.04 中修复了这个reload signal USR2问题。归功于 Jurian Sluiman 在此答案中的评论。

Here is the primary bug report, proposed workarounds, and confirmation of workaround.

这是主要的错误报告建议的解决方法解决方法的确认

$ ps aux | grep php
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      1966  0.0  0.9 473276 37040 ?        Ss   10:03   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)                    
www-data  2009  0.0  1.5 478280 62500 ?        S    10:03   0:01 php-fpm: pool www                                                       
www-data  2011  0.0  1.3 476504 55220 ?        S    10:03   0:00 php-fpm: pool www                                                       
www-data  2012  0.0  1.6 481592 65840 ?        S    10:03   0:00 php-fpm: pool www

$ sudo service php5-fpm status
php5-fpm start/running, process 1966

$ sudo service php5-fpm stop
php5-fpm stop/waiting

$ sudo service php5-fpm status
php5-fpm stop/waiting

$ sudo service php5-fpm start
php5-fpm start/running, process 2651

$ sudo service php5-fpm status
php5-fpm start/running, process 2651

$ ps aux | grep php
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      2651  0.2  0.9 473276 36996 ?        Ss   10:35   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)                    
www-data  2654  0.0  0.1 473276  7104 ?        S    10:35   0:00 php-fpm: pool www                                                       
www-data  2655  0.0  0.1 473276  7104 ?        S    10:35   0:00 php-fpm: pool www                                                       
www-data  2656  0.0  0.1 473276  7104 ?        S    10:35   0:00 php-fpm: pool www

回答by BurninLeo

Usually, the servicecommand will do fine:

通常,该service命令可以正常工作:

service php5-fpm restart

But if the "unknown instance" issue appears, you can just kill the processes and have the service restarted, using this line:

但是,如果出现“未知实例”问题,您可以使用以下行终止进程并重新启动服务:

sudo pkill php5-fpm; sudo service php5-fpm start

回答by Mihail

Try to stop your php5-fpm instance by service php5-fpm stopagain. Wait for some seconds. Try to see, which processes was not terminated using ps -ef. Terminate them by kill <processId>. Start php5-fpm again. Is seems, not all child processes was terminated properly by service ...command. I have similar issues in on server, but they are not regular

尝试再次停止您的 php5-fpm 实例service php5-fpm stop。等待几秒钟。尝试查看哪些进程没有使用ps -ef. 终止它们kill <processId>。再次启动 php5-fpm。看来,并非所有子进程都被service ...命令正确终止。我在服务器上有类似的问题,但它们不正常

回答by Barnabas Kecskes

I have experienced the same issue using Envoyer for Laravel- and that was quite annoying. My solution was to follow option 3) at https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1242376/comments/16

我在使用Envoyer for Laravel 时遇到了同样的问题——这很烦人。我的解决方案是遵循选项 3) 在https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1242376/comments/16

Create /etc/init/php5-fpm.override file with the single line "reload signal USR2" in it.

创建 /etc/init/php5-fpm.override 文件,其中包含单行“reload signal USR2”。

回答by Graham T

Deploying with Envoyer brought me here. I ended up adding a 'before' deployment hook to the Activate New Release action with the pkill php5-fpmprocess

与 Envoyer 一起部署让我来到这里。我最终在pkill php5-fpm流程中向 Activate New Release 操作添加了一个“之前”部署挂钩

回答by Kevin

The option that worked for me was to reset opcache. Create a file opcache-reset.php file in your site root and add:

对我有用的选项是重置 opcache。在您的站点根目录中创建一个文件 opcache-reset.php 文件并添加:

<?php opcache_reset(); ?>

After reseting opcache, you can delete the file or move it out of your site root.

重置 opcache 后,您可以删除该文件或将其移出站点根目录。

回答by stucki

Seems like the servicecommand sometimes fails. I don't know about the reason, however I ended up using this workaround in /etc/logrotate.d/php5-fpm:

似乎service命令有时会失败。我不知道原因,但是我最终在以下位置使用了这个解决方法/etc/logrotate.d/php5-fpm

/var/log/php5-fpm.log {
    ...
    postrotate
        # The original reload command did never work
        #invoke-rc.d php5-fpm reopen-logs > /dev/null

        # Workaround for cases when the reload command fails for some reason
        service php5-fpm reload > /dev/null 2>&1
        [ $? = 0 ] || ( service php5-fpm stop; pkill php5-fpm; service php5-fpm start ) > /dev/null
    endscript
}

回答by Paulo Coghi - Reinstate Monica

When none of the above answers solves the problem, test your configuration to see your mistakes:

当以上答案都不能解决问题时,请测试您的配置以查看您的错误:

$ php5-fpm -t

I most cases you probably made a mistake in your /etc/php5/fpm/php-fpm.confor /etc/php5/fpm/pool.d/www.conf

大多数情况下,您可能在您的/etc/php5/fpm/php-fpm.conf/etc/php5/fpm/pool.d/www.conf

回答by Bery

For me it turned out to be an error in pool configuration file (loaded from pool.d directory)

对我来说,结果是池配置文件中的错误(从 pool.d 目录加载)

Try running php-fpm7.0 -tto run configtest (name of the executable may vary based on your installation and name of the service)

尝试运行php-fpm7.0 -t以运行 configtest(可执行文件的名称可能因您的安装和服务名称而异)