在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)
解决方法:
这是正常的,您可能在不重新启动的情况下“旋转”日志,因此进程(任何进程确实)都会使描述符保持打开状态.
使用postrotate或copytruncate.这很受欢迎:
postrotate
kill -USR1 `cat /var/run/nginx.pid` &>/dev/null
endscript
USR1信号告诉nginx重新加载日志文件(从而释放描述符)
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!