我尝试设置位于/tmp/hr_logs/的日志文件的日志轮换。为了进行设置,我在 linux 中使用了 logrotate,并且可以使用/etc/logrotate.conf 中的以下配置每天轮换它
/tmp/hr_logs {
daily
rotate 4
使用此配置,文件将每天轮换,系统将保留 4 个附加日期的日志文件副本 [格式:-YYYYMMDD]
现在,我尝试设置一组不同的日志文件,我需要每小时轮换一次,为此,我已经在 logrotate.conf 中完成了配置:
/tmp/last_logs {
hourly
rotate 4
但这根本不起作用?有人可以请指导我吗?
最佳答案
logrotate.conf
的手册页包含关于 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.
正如 yellow1pl 所指出的那样解决方案是将文件 /etc/cron.daily/logrotate
复制到 /etc/cron.hourly/
目录中。这至少适用于 Debian,可能还有一些 Debian 衍生产品。
关于linux - 使用 logrotate 每小时轮换文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25485047/