Я создал файл logrotate в каталоге /etc/logrotate.d/. Это выглядит следующим образом:
/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 вызывается каждую ночь, исходя из вышеизложенного.
Любая помощь в определении того, почему не происходит ежедневная ротация бревен, будет принята с благодарностью.