Logrotate 没有进行任何旋转

Logrotate 没有进行任何旋转

我刚刚在 RHEL6 服务器上设置了 LogRotate,以便它可以轮换我的自定义 Apache 日志文件。但是,当我尝试手动运行它时,它什么也没做。

我希望它轮换日志文件“access.log”和“err.log”。它们已经在那里几天了,需要轮换。

输出如下:

[root@pc1 httpd]# logrotate -d -f /etc/logrotate.d/apache
reading config file /etc/logrotate.d/apache
reading config info for /var/log/httpd/*log
/var/www/html/NSLogs/access.log
/var/www/html/NSErrorLogs/err.log


Handling 1 logs

rotating pattern: /var/log/httpd/*log
/var/www/html/NSLogs/access.log
/var/www/html/NSErrorLogs/err.log
 forced from command line (no old logs will be kept)
empty log files are rotated, old logs are removed
considering log /var/log/httpd/access_log
  log needs rotating
considering log /var/log/httpd/error_log
  log needs rotating
considering log /var/www/html/NSLogs/access.log
  log needs rotating
considering log /var/www/html/NSErrorLogs/err.log
  log needs rotating
rotating log /var/log/httpd/access_log, log->rotateCount is 0
dateext suffix '-20131023'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
fscreate context set to unconfined_u:object_r:httpd_log_t:s0
renaming /var/log/httpd/access_log to /var/log/httpd/access_log-20131023
disposeName will be /var/log/httpd/access_log-20131023.gz
running postrotate script
running script with arg /var/log/httpd/access_log: "
      /usr/bin/killall -HUP httpd
"
compressing log with: /bin/gzip
removing old log /var/log/httpd/access_log-20131023.gz
error: error opening /var/log/httpd/access_log-20131023.gz: No such file or directory
rotating log /var/log/httpd/error_log, log->rotateCount is 0
dateext suffix '-20131023'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
fscreate context set to unconfined_u:object_r:httpd_log_t:s0
renaming /var/log/httpd/error_log to /var/log/httpd/error_log-20131023
disposeName will be /var/log/httpd/error_log-20131023.gz
running postrotate script
running script with arg /var/log/httpd/error_log: "
      /usr/bin/killall -HUP httpd
"
compressing log with: /bin/gzip
removing old log /var/log/httpd/error_log-20131023.gz
error: error opening /var/log/httpd/error_log-20131023.gz: No such file or directory
rotating log /var/www/html/NSLogs/access.log, log->rotateCount is 0
dateext suffix '-20131023'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
fscreate context set to unconfined_u:object_r:httpd_sys_rw_content_t:s0
renaming /var/www/html/NSLogs/access.log to /var/www/html/NSLogs/access.log-20131023
disposeName will be /var/www/html/NSLogs/access.log-20131023.gz
running postrotate script
running script with arg /var/www/html/NSLogs/access.log: "
      /usr/bin/killall -HUP httpd
"
compressing log with: /bin/gzip
removing old log /var/www/html/NSLogs/access.log-20131023.gz
error: error opening /var/www/html/NSLogs/access.log-20131023.gz: No such file or directory
rotating log /var/www/html/NSErrorLogs/err.log, log->rotateCount is 0
dateext suffix '-20131023'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
fscreate context set to unconfined_u:object_r:httpd_sys_rw_content_t:s0
renaming /var/www/html/NSErrorLogs/err.log to /var/www/html/NSErrorLogs/err.log-20131023
disposeName will be /var/www/html/NSErrorLogs/err.log-20131023.gz
running postrotate script
running script with arg /var/www/html/NSErrorLogs/err.log: "
      /usr/bin/killall -HUP httpd
"
compressing log with: /bin/gzip
removing old log /var/www/html/NSErrorLogs/err.log-20131023.gz
error: error opening /var/www/html/NSErrorLogs/err.log-20131023.gz: No such file or directory

答案1

我不确定这是否是问题所在,但如果 Apache 仍在运行,它可能会锁定这些日志文件。也许它/usr/bin/killall -HUP httpd不能足够快地杀死 Apache。

首先尝试关闭 Apache,看看是否有帮助:

service httpd stop
logrotate -f /etc/logrotate.d/apache
service httpd start

如果您没有使用服务启动 Apache,则需要使用适当的命令。

顺便说一下,我的/etc/logrotate.d/httpd(也就是你的/etc/logrotate.d/apache)看起来像这样:

/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

答案2

我将配置文件的格式更改为以下内容,现在看来运行良好。

/var/log/httpd/*log
/var/www/html/NSLogs/access.log
/var/www/html/NSErrorLogs/err.log
{
    copytruncate
    daily
    size 500M
    compress
    dateext
    maxage 60
}

相关内容