什么计划 logrotate?

use*_*963 24 cron logrotate

我正在开发一个创建大日志文件的程序。

我想用 logrotate 处理它。

这是我的配置/etc/logrotate.d/

/var/log/myproject.log  {
 hourly
 maxsize 1
 rotate 6
 missingok
 notifempty
 compress
 nocreate
 copytruncate
 su www-data www-data 
}
Run Code Online (Sandbox Code Playgroud)

/var/log/myproject.log有主人www-data

命令

sudo logrotate -vf /etc/logrotate.conf
Run Code Online (Sandbox Code Playgroud)

sudo logrotate -vf /etc/logrotate.d/myproject
Run Code Online (Sandbox Code Playgroud)

正确旋转日志。

但是,调用它们之后/etc/cron.hourly是空的。这意味着 logrotate 不是每小时调用一次。

  1. 我保证有logrotate脚本/etc/cron.daily吗?

  2. 脚本是否检查日志文件的更新频率。即,如果我在我设置的设置中有logrotate脚本/etc/cron.daily和某些日志文件,将每天或每周轮换?X/etc/logrotate.d/weeklyX

  3. 我可以直接复制粘贴/etc/cron.daily/logrotate/etc/cron.hourly/吗?可以剪切粘贴吗?

  4. 我应该将0anacron文件添加到/etc/cron.hourly/?

  5. 我应该做其他事情来启用每小时日志记录吗?

mur*_*uru 13

  1. 不。

  2. 来自man logrotate

    Each  configuration  file  can  set  global  options (local definitions
    override global ones, and later definitions override earlier ones)
    
    Run Code Online (Sandbox Code Playgroud)

    所以,是的。

  3. 再次,从联机帮助页:

    hourly Log files are rotated every hour. Note that usually logrotate is
           configured  to  be  run  by  cron daily. You have to change this
           configuration and run logrotate hourly  to  be  able  to  really
           rotate logs hourly.
    
    Run Code Online (Sandbox Code Playgroud)

    所以,是的,您应该移动脚本。检查cron.daily我系统中的脚本,我认为移动它应该可以正常工作。