Logrotate无法正常工作

我试图让logrotate在我的VPS上工作,每周轮换我的apache文件.目前apache2配置文件的内容是这样的.

"/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

关于我配置错误的任何想法?

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

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
我认为每周意味着logrotate想要查看至少一周的access.log文件条目以便旋转它.

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

以下是logrotate如何决定旋转日志文件的简单案例的逐步示例
 (这些是fedora路径,Ubuntu,Centos等可能会有所不同)

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

所以我已经将我的logroate for apache设置为每周一次;

/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编辑状态文件,那么将此日期设置为超过一周……;

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

然后logrotate现在正确地旋转文件,因为状态文件2012-4-11中的日期超过一周前从今天开始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来生成状态条目或旋转文件等)

相关文章
相关标签/搜索