php-fpm – logrotate导致php5-fpm停机

前端之家收集整理的这篇文章主要介绍了php-fpm – logrotate导致php5-fpm停机前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我注意到我们的一台服务器在logrotate运行后才开始返回错误,即在Nginx错误日志中我可以看到:

[error] 8501#0: *118126869 recv() Failed (104: Connection reset by
peer) while reading response header from upstream,client: xxx.yyy.zz.ww,server: www.test.com,request: “GET /index.PHP HTTP/1.1”,upstream: “fastcgi://127.0.0.1:9011”,host: “www.test.com”

我尝试添加一个postrotate动作,使PHP重新加载优雅,但错误仍在发生,我们当前的logrotate如下:

/var/log/PHP5-fpm.log {
        daily
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 644 root root
        postrotate
                [ ! -f /var/run/PHP5-fpm.pid ] || kill -USR2 `cat /var/run/PHP5-fpm.pid`
        endscript
}

PHP配置如下:

[www-9011]

user = www-data
group = www-data
listen = 127.0.0.1:9011
listen.backlog = 65535
pm = ondemand
pm.max_children = 50
pm.process_idle_timeout = 10s;
pm.max_requests = 500
rlimit_files = 16384
chdir = /
catch_workers_output = no
PHP_admin_value[error_log] = /var/log/fpm-PHP.www.log
PHP_admin_flag[log_errors] = on

我们正在运行ubuntu 12.04和PHP 5.3.10

发送USR1

https://github.com/php/php-src/blob/b7a7b1a624c97945c0aaa49d46ae996fc0bdb6bc/sapi/fpm/fpm/fpm_events.c#L94

代码显示这是专门为旋转文件,我知道Ubuntu 14.04没有很好地处理fpm重载(USR2),我认为它也适用于旧版本.

所以改为

postrotate
                [ ! -f /var/run/PHP5-fpm.pid ] || kill -USR1 `cat /var/run/PHP5-fpm.pid`
endscript

简单地旋转日志

猜你在找的PHP相关文章