logging - logrotate 不是每天轮换日志文件
问题描述
我在“/etc/logrotate.d/”目录中创建了一个 logrotate 文件。如下:
/opt/appliedpathways/tomcat/instance_2/logs/*.log /opt/appliedpathways/tomcat/instance_2/logs/catalina.out {
daily
copytruncate
missingok
ifempty
rotate 30
maxage 30
compress
dateext
dateformat -%Y%m%d-%s
}
“/etc/logrotate.conf”文件是:
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}
# system-specific logs may be also be configured here.
我已经执行了以下命令:
sudo logrotate -f /etc/logrotate.conf
“/var/lib/logrotate.status”文件如下:
logrotate state -- version 2
...
"/opt/appliedpathways/tomcat/instance_2/logs/localhost_access.log" 2018-4-30
"/opt/appliedpathways/tomcat/instance_2/logs/stacktrace.log" 2018-4-30
"/opt/appliedpathways/tomcat/instance_2/logs/catalina.out" 2018-4-30
...
为简洁起见,我添加了 ...。logrotate.status 文件中还有几个条目。
以下是执行“logrotate -d /etc/logrotate.conf”后的输出。
reading config file /etc/logrotate.conf
including /etc/logrotate.d
...
reading config file tomcat-instance_2
reading config info for /opt/appliedpathways/tomcat/instance_2/logs/*.log /opt/appliedpathways/tomcat/instance_2/logs/catalina.out
rotating pattern: /opt/appliedpathways/tomcat/instance_2/logs/*.log /opt/appliedpathways/tomcat/instance_2/logs/catalina.out after 1 days (30 rotations)
empty log files are rotated, old logs are removed
considering log /opt/appliedpathways/tomcat/instance_2/logs/localhost_access.log
log needs rotating
considering log /opt/appliedpathways/tomcat/instance_2/logs/stacktrace.log
log needs rotating
considering log /opt/appliedpathways/tomcat/instance_2/logs/catalina.out
log needs rotating
rotating log /opt/appliedpathways/tomcat/instance_2/logs/localhost_access.log, log->rotateCount is 30
Converted ' -%Y%m%d-%s' -> '-%Y%m%d-%s'
dateext suffix '-20180502-1525266808'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
copying /opt/appliedpathways/tomcat/instance_2/logs/localhost_access.log to /opt/appliedpathways/tomcat/instance_2/logs/localhost_access.log-20180502-1525266808
truncating /opt/appliedpathways/tomcat/instance_2/logs/localhost_access.log
compressing log with: /bin/gzip
rotating log /opt/appliedpathways/tomcat/instance_2/logs/stacktrace.log, log->rotateCount is 30
Converted ' -%Y%m%d-%s' -> '-%Y%m%d-%s'
dateext suffix '-20180502-1525266808'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
copying /opt/appliedpathways/tomcat/instance_2/logs/stacktrace.log to /opt/appliedpathways/tomcat/instance_2/logs/stacktrace.log-20180502-1525266808
truncating /opt/appliedpathways/tomcat/instance_2/logs/stacktrace.log
compressing log with: /bin/gzip
rotating log /opt/appliedpathways/tomcat/instance_2/logs/catalina.out, log->rotateCount is 30
Converted ' -%Y%m%d-%s' -> '-%Y%m%d-%s'
dateext suffix '-20180502-1525266808'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
copying /opt/appliedpathways/tomcat/instance_2/logs/catalina.out to /opt/appliedpathways/tomcat/instance_2/logs/catalina.out-20180502-1525266808
truncating /opt/appliedpathways/tomcat/instance_2/logs/catalina.out
compressing log with: /bin/gzip
...
logrotate 显然可以确定日志文件需要轮换,但是日志文件没有被轮换。
“/etc/cron.daily/”目录看起来像这样。
total 44
-rwxr-xr-x. 1 root root 4983 Dec 7 2016 0yum.cron
-rwx------. 1 root root 118 May 4 2017 cups
-rwxr-xr-x. 1 root mail 232 Aug 18 2017 exim-tidydb
-rwx------. 1 root root 180 Jul 9 2003 logrotate
-rwx------. 1 root root 927 Nov 8 2016 makewhatis.cron
-rwx------. 1 root root 189 Jan 26 2015 mlocate.cron
-rwxr-xr-x. 1 root root 2126 Jul 19 2013 prelink
-rwxr-xr-x. 1 root root 563 Oct 21 2013 readahead.cron
lrwxrwxrwx. 1 root root 55 Jan 20 2016 redhat-access-insights -> /etc/redhat-access-insights/redhat-access-insights.cron
-rwx------. 1 root root 256 Feb 10 2017 rhsmd
-rwxr-xr-x. 1 root root 433 Nov 6 2015 tmpwatch
我假设基于上述内容,每晚都会调用 logrotate。
任何帮助确定为什么没有发生日志的每日轮换将不胜感激。
解决方案
尝试在 /etc/logrotate.conf 中将“weekly”替换为“daily”
推荐阅读
- html - 如何在手机上以正确的分辨率打开我的 HTML 项目?
- java - 注销后如何让webview记住用户名和密码等用户凭据以在android中自动填充?
- python - lmdb.Error:磁盘空间不足
- sql-server - 在 TSQL 中将 Pivot 函数与 Sum 函数结合使用
- java - 第二种方法的 Java Scanner
- tabulator - 如何在初始设置之外设置 Tabulator groupValues
- xamarin - 创建模板类并添加事件时是否需要删除它?
- data-visualization - 数据可视化图表
- debugging - LLDB 失去了自动完成文件名的能力
- cygwin - 通过远程 Windows 主机上的脚本配置 cygwin sshd-host-config