旋转nginx日志文件的最佳方法是什么?在我看来,我应该在/etc/logrotate.d/中创建一个文件"nginx“,并用下面的代码填充它,然后执行/etc/init.d/syslog重新启动。
这将是我的配置(我还没有测试它):
/usr/local/nginx/logs/*.log {
#rotate the logfile(s) daily
daily
# adds extension like YYYYMMDD instead of simply adding a number
dateext
# If log file is missing, go on to next one without issuing an error msg
missingok
# Save logfiles for the last 49 days
rotate 49
# Old versions of log files are compressed with gzip
compress
# Postpone compression of the previous log file to the next rotation cycle
delaycompress
# Do not rotate the log if it is empty
notifempty
# create mode owner group
create 644 nginx nginx
#after logfile is rotated and nginx.pid exists, send the USR1 signal
postrotate
[ ! -f /usr/local/nginx/logs/nginx.pid ] || kill -USR1 `cat
/usr/local/nginx/logs/nginx.pid`
endscript
}
我在/usr/local/nginx/ error.log /中同时拥有error.log和error.log文件,并且希望每天都轮流使用。有人能告诉我“约会”是否正确吗?我希望日志文件名类似于“access.log.log-2010-12-04”。还有一件事:我可以每天在特定的时间(例如晚上11点)旋转日志吗?如果是这样的话,是怎么做的?谢谢。
发布于 2014-04-17 10:45:38
您可以同时旋转所有vhost:
/var/www/vhosts/*/logs/*.log { ... }
发布于 2010-12-04 22:22:21
dateext
的值由dateformat
指令提供,默认为%Y%m%d
(年份、月和日)。您可以像%Y-%m-%d
一样定制它。
如果您已经安装并工作了logrotate
,很可能它每天都会作为cron
作业运行,您只需找到它来更改时间(请记住,其他东西会影响anacron
的使用,但每个系统都会有所不同)。
https://serverfault.com/questions/209177
复制相似问题