微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

简单地旋转日志

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐