在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重新加载日志文件(从而释放描述符)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。