Logrotate不旋转或创建新文件

时间:2019-01-22 15:55:00

标签: linux apache ubuntu logging logrotate

我正在尝试在Ubuntu服务器上为Apache设置logrotate,但是在尝试测试旋转时却出现以下错误:

logrotate_script: 4: logrotate_script:  : not found
error: error running shared prerotate script for '/var/log/apache2/*.log '

我已经在调试,详细和强制模式下运行了它,但似乎看不到任何明确指出该问题的东西,因此,我将非常感谢任何帮助。

这是我的/etc/logrotate.d/apache2文件:

/var/log/apache2/*.log {
        size 100k
        missingok
        rotate 14
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                /etc/init.d/apache2 restart > /dev/null;
        endscript
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi; \
        endscript
}

这是运行命令sudo logrotate -vf /etc/logrotate.d/apache2的输出:

reading config file /etc/logrotate.d/apache2
Handling 1 logs
rotating pattern: /var/log/apache2/*.log  forced from command line (14 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/apache2/access.log
  log does not need rotating
considering log /var/log/apache2/access_proxy.log
  log needs rotating
considering log /var/log/apache2/error.log
  log needs rotating
considering log /var/log/apache2/error_proxy.log
  log does not need rotating
considering log /var/log/apache2/other_vhosts_access.log
  log needs rotating
rotating log /var/log/apache2/access_proxy.log, log->rotateCount is 14
dateext suffix '-20190122'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /var/log/apache2/access_proxy.log.1 does not exist
renaming /var/log/apache2/access_proxy.log.14.gz to /var/log/apache2/access_proxy.log.15.gz (rotatecount 14, logstart 1, i 14), 
old log /var/log/apache2/access_proxy.log.14.gz does not exist
renaming /var/log/apache2/access_proxy.log.13.gz to /var/log/apache2/access_proxy.log.14.gz (rotatecount 14, logstart 1, i 13), 
old log /var/log/apache2/access_proxy.log.13.gz does not exist
renaming /var/log/apache2/access_proxy.log.12.gz to /var/log/apache2/access_proxy.log.13.gz (rotatecount 14, logstart 1, i 12), 
old log /var/log/apache2/access_proxy.log.12.gz does not exist
renaming /var/log/apache2/access_proxy.log.11.gz to /var/log/apache2/access_proxy.log.12.gz (rotatecount 14, logstart 1, i 11), 
old log /var/log/apache2/access_proxy.log.11.gz does not exist
renaming /var/log/apache2/access_proxy.log.10.gz to /var/log/apache2/access_proxy.log.11.gz (rotatecount 14, logstart 1, i 10), 
old log /var/log/apache2/access_proxy.log.10.gz does not exist
renaming /var/log/apache2/access_proxy.log.9.gz to /var/log/apache2/access_proxy.log.10.gz (rotatecount 14, logstart 1, i 9), 
old log /var/log/apache2/access_proxy.log.9.gz does not exist
renaming /var/log/apache2/access_proxy.log.8.gz to /var/log/apache2/access_proxy.log.9.gz (rotatecount 14, logstart 1, i 8), 
old log /var/log/apache2/access_proxy.log.8.gz does not exist
renaming /var/log/apache2/access_proxy.log.7.gz to /var/log/apache2/access_proxy.log.8.gz (rotatecount 14, logstart 1, i 7), 
old log /var/log/apache2/access_proxy.log.7.gz does not exist
renaming /var/log/apache2/access_proxy.log.6.gz to /var/log/apache2/access_proxy.log.7.gz (rotatecount 14, logstart 1, i 6), 
old log /var/log/apache2/access_proxy.log.6.gz does not exist
renaming /var/log/apache2/access_proxy.log.5.gz to /var/log/apache2/access_proxy.log.6.gz (rotatecount 14, logstart 1, i 5), 
old log /var/log/apache2/access_proxy.log.5.gz does not exist
renaming /var/log/apache2/access_proxy.log.4.gz to /var/log/apache2/access_proxy.log.5.gz (rotatecount 14, logstart 1, i 4), 
old log /var/log/apache2/access_proxy.log.4.gz does not exist
renaming /var/log/apache2/access_proxy.log.3.gz to /var/log/apache2/access_proxy.log.4.gz (rotatecount 14, logstart 1, i 3), 
old log /var/log/apache2/access_proxy.log.3.gz does not exist
renaming /var/log/apache2/access_proxy.log.2.gz to /var/log/apache2/access_proxy.log.3.gz (rotatecount 14, logstart 1, i 2), 
old log /var/log/apache2/access_proxy.log.2.gz does not exist
renaming /var/log/apache2/access_proxy.log.1.gz to /var/log/apache2/access_proxy.log.2.gz (rotatecount 14, logstart 1, i 1), 
old log /var/log/apache2/access_proxy.log.1.gz does not exist
renaming /var/log/apache2/access_proxy.log.0.gz to /var/log/apache2/access_proxy.log.1.gz (rotatecount 14, logstart 1, i 0), 
old log /var/log/apache2/access_proxy.log.0.gz does not exist
log /var/log/apache2/access_proxy.log.15.gz doesn't exist -- won't try to dispose of it
rotating log /var/log/apache2/error.log, log->rotateCount is 14
dateext suffix '-20190122'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /var/log/apache2/error.log.1 does not exist
renaming /var/log/apache2/error.log.14.gz to /var/log/apache2/error.log.15.gz (rotatecount 14, logstart 1, i 14), 
old log /var/log/apache2/error.log.14.gz does not exist
renaming /var/log/apache2/error.log.13.gz to /var/log/apache2/error.log.14.gz (rotatecount 14, logstart 1, i 13), 
old log /var/log/apache2/error.log.13.gz does not exist
renaming /var/log/apache2/error.log.12.gz to /var/log/apache2/error.log.13.gz (rotatecount 14, logstart 1, i 12), 
old log /var/log/apache2/error.log.12.gz does not exist
renaming /var/log/apache2/error.log.11.gz to /var/log/apache2/error.log.12.gz (rotatecount 14, logstart 1, i 11), 
old log /var/log/apache2/error.log.11.gz does not exist
renaming /var/log/apache2/error.log.10.gz to /var/log/apache2/error.log.11.gz (rotatecount 14, logstart 1, i 10), 
old log /var/log/apache2/error.log.10.gz does not exist
renaming /var/log/apache2/error.log.9.gz to /var/log/apache2/error.log.10.gz (rotatecount 14, logstart 1, i 9), 
old log /var/log/apache2/error.log.9.gz does not exist
renaming /var/log/apache2/error.log.8.gz to /var/log/apache2/error.log.9.gz (rotatecount 14, logstart 1, i 8), 
old log /var/log/apache2/error.log.8.gz does not exist
renaming /var/log/apache2/error.log.7.gz to /var/log/apache2/error.log.8.gz (rotatecount 14, logstart 1, i 7), 
old log /var/log/apache2/error.log.7.gz does not exist
renaming /var/log/apache2/error.log.6.gz to /var/log/apache2/error.log.7.gz (rotatecount 14, logstart 1, i 6), 
old log /var/log/apache2/error.log.6.gz does not exist
renaming /var/log/apache2/error.log.5.gz to /var/log/apache2/error.log.6.gz (rotatecount 14, logstart 1, i 5), 
old log /var/log/apache2/error.log.5.gz does not exist
renaming /var/log/apache2/error.log.4.gz to /var/log/apache2/error.log.5.gz (rotatecount 14, logstart 1, i 4), 
old log /var/log/apache2/error.log.4.gz does not exist
renaming /var/log/apache2/error.log.3.gz to /var/log/apache2/error.log.4.gz (rotatecount 14, logstart 1, i 3), 
old log /var/log/apache2/error.log.3.gz does not exist
renaming /var/log/apache2/error.log.2.gz to /var/log/apache2/error.log.3.gz (rotatecount 14, logstart 1, i 2), 
old log /var/log/apache2/error.log.2.gz does not exist
renaming /var/log/apache2/error.log.1.gz to /var/log/apache2/error.log.2.gz (rotatecount 14, logstart 1, i 1), 
old log /var/log/apache2/error.log.1.gz does not exist
renaming /var/log/apache2/error.log.0.gz to /var/log/apache2/error.log.1.gz (rotatecount 14, logstart 1, i 0), 
old log /var/log/apache2/error.log.0.gz does not exist
log /var/log/apache2/error.log.15.gz doesn't exist -- won't try to dispose of it
rotating log /var/log/apache2/other_vhosts_access.log, log->rotateCount is 14
dateext suffix '-20190122'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /var/log/apache2/other_vhosts_access.log.1 does not exist
renaming /var/log/apache2/other_vhosts_access.log.14.gz to /var/log/apache2/other_vhosts_access.log.15.gz (rotatecount 14, logstart 1, i 14), 
old log /var/log/apache2/other_vhosts_access.log.14.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.13.gz to /var/log/apache2/other_vhosts_access.log.14.gz (rotatecount 14, logstart 1, i 13), 
old log /var/log/apache2/other_vhosts_access.log.13.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.12.gz to /var/log/apache2/other_vhosts_access.log.13.gz (rotatecount 14, logstart 1, i 12), 
old log /var/log/apache2/other_vhosts_access.log.12.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.11.gz to /var/log/apache2/other_vhosts_access.log.12.gz (rotatecount 14, logstart 1, i 11), 
old log /var/log/apache2/other_vhosts_access.log.11.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.10.gz to /var/log/apache2/other_vhosts_access.log.11.gz (rotatecount 14, logstart 1, i 10), 
old log /var/log/apache2/other_vhosts_access.log.10.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.9.gz to /var/log/apache2/other_vhosts_access.log.10.gz (rotatecount 14, logstart 1, i 9), 
old log /var/log/apache2/other_vhosts_access.log.9.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.8.gz to /var/log/apache2/other_vhosts_access.log.9.gz (rotatecount 14, logstart 1, i 8), 
old log /var/log/apache2/other_vhosts_access.log.8.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.7.gz to /var/log/apache2/other_vhosts_access.log.8.gz (rotatecount 14, logstart 1, i 7), 
old log /var/log/apache2/other_vhosts_access.log.7.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.6.gz to /var/log/apache2/other_vhosts_access.log.7.gz (rotatecount 14, logstart 1, i 6), 
old log /var/log/apache2/other_vhosts_access.log.6.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.5.gz to /var/log/apache2/other_vhosts_access.log.6.gz (rotatecount 14, logstart 1, i 5), 
old log /var/log/apache2/other_vhosts_access.log.5.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.4.gz to /var/log/apache2/other_vhosts_access.log.5.gz (rotatecount 14, logstart 1, i 4), 
old log /var/log/apache2/other_vhosts_access.log.4.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.3.gz to /var/log/apache2/other_vhosts_access.log.4.gz (rotatecount 14, logstart 1, i 3), 
old log /var/log/apache2/other_vhosts_access.log.3.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.2.gz to /var/log/apache2/other_vhosts_access.log.3.gz (rotatecount 14, logstart 1, i 2), 
old log /var/log/apache2/other_vhosts_access.log.2.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.1.gz to /var/log/apache2/other_vhosts_access.log.2.gz (rotatecount 14, logstart 1, i 1), 
old log /var/log/apache2/other_vhosts_access.log.1.gz does not exist
renaming /var/log/apache2/other_vhosts_access.log.0.gz to /var/log/apache2/other_vhosts_access.log.1.gz (rotatecount 14, logstart 1, i 0), 
old log /var/log/apache2/other_vhosts_access.log.0.gz does not exist
log /var/log/apache2/other_vhosts_access.log.15.gz doesn't exist -- won't try to dispose of it
running prerotate script
logrotate_script: 4: logrotate_script:  : not found
error: error running shared prerotate script for '/var/log/apache2/*.log '

非常感谢您的帮助,谢谢:)

编辑:凹凸

1 个答案:

答案 0 :(得分:0)

这有点令人困惑,但是/etc/logrotate.d/httpd是否预旋转了您要执行的文件?每个运行部分man

  

运行部分[-测试] [-详细] [-报告] [-lsbsysinit] [-regex = RE] [-umask = umask] [-arg =参数] [-错误退出] [帮助] [版本] [列表] [反向] [-] 目录

如果要将单个文件传递给运行部件,则不会知道如何处理它。只需设置该文件可执行文件并直接调用即可,即

prerotate
  if [ -d /etc/logrotate.d/httpd-prerotate ]; then
    /etc/logrotate.d/httpd-prerotate;
  fi;
endscript