logrotate:即使我使用-f选项,每日轮换也不起作用

问题描述 投票:-2回答:1

这是/etc/logrotate.d/mylog下的logrotate配置文件

/var/www/www.mysite.com/logs/* {
        daily
        rotate 365
        compress
        delaycompress
        missingok
        notifempty
        create 0664 apache apache
}

我昨天下午4点设置了这个,今天上午10点我没有看到任何压缩文件。

我用-d和-f选项尝试了logrotate

使用-d选项,我得到了这个输出

reading config file mysite
reading config info for /var/www/www.mysite.com/logs/*

Handling 1 logs

rotating pattern: /var/www/www.mysite.com/logs/*  after 1 days (365 rotations)
empty log files are not rotated, old logs are removed
considering log/var/www/www.mysite.com/logs/access-2018-08-08.log
  log does not need rotating

使用-f选项,什么也没出现。

但我注意到它为我的每个日志添加了.1后缀。

有人请解释这是什么奇怪的行为吗?

linux logrotate
1个回答
1
投票

Logrotate没有内置的调度系统。

如果要手动清理日志,请确保可以手动运行:

logrotate /etc/logrotate.d/mylog

如果你检查-rot behavior的logrotate手册页:

-f, --force
   Tells  logrotate  to force the rotation, even if it doesn't think this is necessary.  
   Sometimes this is useful after adding new entries to a logrotate config file, 
   or if old log files have been removed by hand, as the new files will be created, 
   and logging will continue correctly.

-d, --debug
   Turns on debug mode and implies -v.  In debug mode, no changes will be made to 
   the logs or to the logrotate state file.

因此,使用-f选项可以强制旋转所有日志,从而调整.1后缀。

使用-d选项它是一个干运行,所以你只预览更改。

现在如果你想每天运行它,你必须使用cron。

默认情况下,安装后logrotate应具有默认配置文件/etc/logrotate.conf和默认的cron作业/etc/cron.daily/logrotate

您可以使用它们,也可以创建自己的配置文件和cron作业。

假如您将自定义配置放在/etc/logrotate.d/mylog上,那么您可以将以下cron作业放在/etc/cron.d/logrotate-cron上以便每天运行它。

0 0 * * * root /usr/sbin/logrotate /etc/logrotate.d/mylog --state /etc/logrotate.status

您可以检查文件/etc/logrotate.status以确保它已运行。

© www.soinside.com 2019 - 2024. All rights reserved.