Logrotate不能正常工作

我试图让logrotate工作在我的VPS每周旋转我的Apache文件。 目前apache2configuration文件的内容是这样的。

"/var/www/user/site.com/logs/*.log" { weekly missingok rotate 8 compress delaycompress notifempty create 640 root adm sharedscripts postrotate /etc/init.d/apache2 reload > /dev/null endscript } 

我现在已经离开了两个星期,没有什么变化,据我所知。 当我从命令行模拟它时,我得到以下输出。

 user@geneva:/var/lib/logrotate$ /usr/sbin/logrotate -d /etc/logrotate.d/apache2 reading config file /etc/logrotate.d/apache2 reading config info for "/var/www/user/site.com/logs/*.log" Handling 1 logs rotating pattern: "/var/www/user/site.com/logs/*.log" weekly (8 rotations) empty log files are not rotated, old logs are removed considering log /var/www/user/site.com/logs/access.log log does not need rotating considering log /var/www/user/site.com/logs/error.log log does not need rotating not running postrotate script, since no logs were rotated 

任何想法,以什么configuration错了?

我的状态文件也是空的:(

 user@geneva:~$ cat /var/lib/logrotate/status logrotate state -- version 2 

更新

我删除了状态文件,并执行logrotate的强制运行,现在日志看起来像他们已经旋转,状态文件看起来更有希望!

 sudo rm /var/lib/logrotate/status sudo /usr/sbin/logrotate -f /etc/logrotate.conf 

我认为weekly意味着logrotate想要查看您的access.log文件中至less一周的条目,以便将其旋转。

因此,问题似乎是你没有存储状态条目触发旋转。


下面是一个简单的案例,如何logrotate决定旋转日志文件的一个例子
(这些是Fedorapath,Ubuntu,Centos等可能不同)

(我向http://localhost提出了一些请求,所以access_log中有一些条目,否则logrotate永远不会旋转…)

所以我已经把apache的logrotate设置为每周一次。

 /var/log/httpd/*log { weekly ... } 

最初在/var/lib/logrotate.status文件中没有条目

 # grep access_log /var/lib/logrotate.status <- nothing 

所以logrotate不会旋转access_log文件;

  # /usr/sbin/logrotate -d /etc/logrotate.d/httpd ... considering log /var/log/httpd/access_log log does not need rotating 

但是,如果我这样手动运行logrotate;

 # /usr/sbin/logrotate /etc/logrotate.d/httpd 

现在在httpd access_log的状态文件中有一个条目;

  # grep access_log /var/lib/logrotate.status "/var/log/httpd/access_log" 2012-5-11 

然而apache仍然不会旋转日志,因为入口只有0天(2012-5-11);

  # /usr/sbin/logrotate -d /etc/logrotate.d/httpd considering log /var/log/httpd/access_log log does not need rotating 

但是,如果你用vi vi /var/lib/logrotate.status编辑状态文件,所以像这样设置date超过一个星期…;

  # grep access_log /var/lib/logrotate.status "/var/log/httpd/access_log" 2012-4-11 <--- more than a week ago.. 

然后logrotate现在正确地旋转文件由于2012-4-11状态文件中的date是从一个多星期前从今天2012-5-11

  # /usr/sbin/logrotate -d /etc/logrotate.d/httpd considering log /var/log/httpd/access_log log needs rotating <--- logrotate rotates the file. 

(请记住, -d导致一个干运行,因此只用于检查,您必须实际运行命令没有-d进行状态input或旋转文件等)

 log does not need rotating 

这可能是因为你的日志文件是空的。
这种情况可能会发生,因为Apache仍然在之前的日志文件中写入,这个日志文件已经重新命名而不需要重新启动Apache。 所以access.log变成了access.log.1,并且apache写入了它。

或者你的日志创build时间有问题:

 ls -al --time=ctime /var/www/user/site.com/logs/ 

我面临类似的问题,除了这些答案都没有帮助我。 我的日志文件是巨大的和旧的,我的configuration是100%确定和有效的,删除状态文件没有帮助。

原来问题是重复的logrotate条目 。 当我在我的configuration文件上手动运行logrotate时,只能这样做:

 logrotate -df /etc/logrotate.d/my_service_name 

它没有显示任何错误,只是说:

 log does not need rotating 

我仍然不知道为什么。 但是,当我运行一个完整的logrotate命令:

 logrotate -f /etc/logrotate.conf 

我得到了以下行:

 error: my_service_name:1 duplicate log entry for /var/log/nginx/my_service_name.access.log 

事实certificate,我的服务的logrotateconfiguration文件包含旋转nginx访问日志的条目以及服务日志本身。 而这与ngnix logrotateconfiguration有冲突,它对所有的nginx条目都有一个规则:

 # grep nginx /etc/logrotate.d/* /etc/logrotate.d/nginx:/var/log/nginx/*.log { 

所以我的案例的解决scheme是非常简单的:我只需要从我的configuration 删除冲突 nginx日志旋转规则

我认为logrotate只是从最新版本中的一个开始放弃处理规则冲突的文件。 我得到这个错误与v.3.8.7但在v.3.7.8与相同的冲突configuration它写出相同的错误,但旋转正常。 虽然我无法在logrotate更新日志中find任何logging。

尝试运行sudo logrotate -f --verbose /etc/logrotate.d/apache2查看控制台中写入的内容,并修复任何错误的内容。

我有一台Debian 7机器,在系统更新之后,它不再轮换邮件日志。 所有其他日志,但邮件正确旋转。 我发现邮件日志已经增长了几千兆字节。 我总是通过Webminpipe理日志轮换。 然后,运行logrotate -d /etc/logrotate.conf我看到以下消息:

Ignoring rsyslog.dpkg-old, because of .dpkg-old ending

它出来了,我的邮件轮换条目列在/etc/logrotate.d/rsyslog.dpkg-old ,被忽略! 重命名文件修复了日志文件的旋转:-)