centos – 为什么nginx保存日志的文件描述?

在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 (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...