我在“/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。
非常感谢任何帮助确定日常旋转日志的原因。
答案 0 :(得分:0)
尝试更换"每周" by"每日"在/etc/logrotate.conf中