在 Red Hat Enterprise Linux Server 版本 6.6(圣地亚哥)上 nginx 版本:nginx/1.0.15
我使用常见的 nginx logrotate 配置,logrotate 工作正常,nginx 创建新的日志文件,如 access.log 或 error.log
# cat /etc/logrotate.d/nginx
/var/log/nginx/*log {
daily
rotate 4
missingok
notifempty
compress
sharedscripts
postrotate
/bin/kill -USR1 $(cat /var/run/nginx.pid 2>/dev/null) 2>/dev/null || :
endscript
}
然而,有一次我的可用空间变低,过了一会儿我发现 nginx 保留了已删除文件的文件描述符。释放服务器上空间的唯一方法是重新启动 nginx,从而释放文件描述符。
有任何想法吗?
> [srv2 nginx]# logrotate -f /etc/logrotate.d/nginx
> [srv2 nginx]# lsof +L1
> COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
> vmtoolsd 1125 root 3u REG 253,3 4240 0 45 /tmp/vmware-root-2883746505/vmware-apploader-1125.log (deleted)
> nginx 38748 nginx 2w REG 253,4 1370362 0 674 /var/log/nginx/error.log.1 (deleted)
> nginx 38748 nginx 4w REG 253,4 1370362 0 674 /var/log/nginx/error.log.1 (deleted)
> nginx 38748 nginx 5w REG 253,4 0 0 220 /var/log/nginx/access.log (deleted)
> nginx 38748 nginx 6w REG 253,4 41819 0 693 /var/log/nginx/localhost.access.log.1 (deleted)
> nginx 38749 nginx 2w REG 253,4 1370362 0 674 /var/log/nginx/error.log.1 (deleted)
> nginx 38749 nginx 4w REG 253,4 1370362 0 674 /var/log/nginx/error.log.1 (deleted)
> nginx 38749 nginx 5w REG 253,4 0 0 220 /var/log/nginx/access.log (deleted)
> nginx 38749 nginx 6w REG 253,4 41819 0 693 /var/log/nginx/localhost.access.log.1 (deleted)
> nginx 38750 nginx 2w REG 253,4 1370362 0 674 /var/log/nginx/error.log.1 (deleted)
> nginx 38750 nginx 4w REG 253,4 1370362 0 674 /var/log/nginx/error.log.1 (deleted)
> nginx 38750 nginx 5w REG 253,4 0 0 220 /var/log/nginx/access.log (deleted)
> nginx 38750 nginx 6w REG 253,4 41819 0 693 /var/log/nginx/localhost.access.log.1 (deleted)
答案1
这是正常的,您可能在不重新启动的情况下“旋转”日志,因此进程(实际上是任何进程)将使描述符保持打开状态。
要么使用postrotate
要么copytruncate
.这很受欢迎:
postrotate
kill -USR1 `cat /var/run/nginx.pid` &>/dev/null
endscript
信号USR1
告诉我们nginx重新加载日志文件(从而释放描述符)
答案2
这与我在 ModSecurity 存储库上打开的问题完全相同。仅供参考,我已经与spyderlabs联系以获得支持nginx的专业付费合同,自从他们开始研究nginx支持以来我还没有听说过他们......我暂时停止了nginx中的所有mod_security模块因为我现在还有其他未决的错误没有解决方案......