我正在开发一个创建大日志文件的程序。
我想用 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 不是每小时调用一次。
我保证有logrotate
脚本/etc/cron.daily
吗?
脚本是否检查日志文件的更新频率。即,如果我在我设置的设置中有logrotate
脚本/etc/cron.daily
和某些日志文件,将每天或每周轮换?X
/etc/logrotate.d/
weekly
X
我可以直接复制粘贴/etc/cron.daily/logrotate
到/etc/cron.hourly/
吗?可以剪切粘贴吗?
我应该将0anacron
文件添加到/etc/cron.hourly/
?
我应该做其他事情来启用每小时日志记录吗?
mur*_*uru 13
不。
Each configuration file can set global options (local definitions
override global ones, and later definitions override earlier ones)
Run Code Online (Sandbox Code Playgroud)
所以,是的。
再次,从联机帮助页:
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
我系统中的脚本,我认为移动它应该可以正常工作。