logrotate:打开时出错(没有这样的文件或目录)

logrotate:打开时出错(没有这样的文件或目录)

我收到一条错误消息。这会自动发送到我的邮箱。

/etc/cron.daily/logrotate:
error: error opening /var/log/apache2/access.log.1.gz: No such file or directory
error: error opening /var/log/apache2/myhost/access.log.1.gz: No such file or directory

我还检查我的/var/log/apache2/*/var/log/apache2/myhost/*那些目录。没有该文件,但目录中access.log.1.gz肯定存在一个文件。access.log.1我刚刚开始配置logrotate这个工具来管理我的日志文件,我的apache已经运行了很长一段时间,我的目录中至少存在30个日志文件。目前,我不知道为什么会发生这样的事情。

/etc/logrotate的如下:

/var/log/apache2/*.log {
     daily
     missingok
     rotate 10
     compress
     delaycompress
#    notifempty
     create 640 root adm
     sharedscripts
     postrotate
                 /etc/init.d/apache2 reload > /dev/null;
     endscript
     prerotate
             if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                     run-parts /etc/logrotate.d/httpd-prerotate; \
             fi; \
     endscript
}
/var/log/apache2/myhost/*.log {
     daily
     missingok
     rotate 10
     compress
     delaycompress
#    notifempty
     create 640 root adm
     sharedscripts
     postrotate
             /etc/init.d/apache2 reload > /dev/null; \
     endscript
     prerotate
             if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                     run-parts /etc/logrotate.d/httpd-prerotate; \
             fi; \
     endscript
}

答案1

我修好了。我的新配置修改了两个地方。现在, /var/log/apache2/myhost/ 如下所示,没有任何单独的“access.log.1”和“error.log.1”。

我的 /etc/logrotate.d 上的配置如下。我去掉了星号并专门为他们起了名字。否则,我评论“delaycompress”这个指令。
/var/log/apache2/myhost/access.log /var/log/apache2/myhost/error.log { daily missingok rotate 2 compress # delaycompress # notifempty create 640 root adm sharedscripts postrotate /etc/init.d/apache2 reload > /dev/null; \ endscript }

这里我添加了一个文件/etc/logrotate.conf。我也注释掉“压缩”。然后,我执行“sudo logrotate -f /etc/logrotate.d/apache2”。这意味着强制它执行这个执行。结果很好。谢谢大家。

# 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

# uncomment this if you want your log files compressed
compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
missingok
monthly
create 0664 root utmp
rotate 1
}

/var/log/btmp {
missingok
monthly
create 0660 root utmp
rotate 1
}

# system-specific logs may be configured here
</code>

相关内容