首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么nginx保存日志的文件描述?

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

Unix & Linux用户
提问于 2015-04-08 16:48:37
回答 2查看 3K关注 0票数 2

红帽企业Linux服务器版本6.6 (圣地亚哥) nginx版本: nginx/1.0.15

我使用了通用的nginx log旋转式配置,log旋转式运行良好,nginx创建了像access.log或error.log这样的新日志文件。

代码语言:javascript
复制
# 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,从而释放文件描述符。

有什么想法吗?

代码语言:javascript
复制
>     [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)
EN

回答 2

Unix & Linux用户

发布于 2015-04-08 17:40:03

这是正常的,您可能在不重新启动的情况下“旋转”日志,因此进程(任何进程)都会保持描述符处于打开状态。

可以使用postrotatecopytruncate。这很受欢迎:

代码语言:javascript
复制
postrotate   
    kill -USR1 `cat /var/run/nginx.pid` &>/dev/null   
endscript

USR1信号告诉nginx重新加载日志文件(从而释放描述符)

票数 3
EN

Unix & Linux用户

发布于 2015-04-09 13:01:03

这与我在ModSecurity回购上打开的问题完全相同。我已经和间谍实验室联系了一份支持nginx的专业付费合同,自从他们开始调查nginx的支持之后我就没听说过他们.目前,我已经停止了nginx中的所有mod_security模块,因为我现在还有其他挂起的bug没有解决方案.

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/195086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档