linux – 为什么我的CentOS logrotate随机运行?

前端之家收集整理的这篇文章主要介绍了linux – 为什么我的CentOS logrotate随机运行?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在/etc/logrotate.d/中放了一个logrotate配置文件,并希望日志在一致的时间旋转;然而,他们没有…记录旋转时间似乎是随机的/ – 一小时.

为什么日志轮换开始时间是随机的,我该如何更改?

信息:我的logrotate配置文件看起来像这样……

  1. /opt/backups/network/*.conf {
  2. copytruncate
  3. rotate 30
  4. daily
  5. create 644 root root
  6. dateext
  7. maxage 30
  8. missingok
  9. notifempty
  10. compress
  11. delaycompress
  12. postrotate
  13. ## Create symbolic links in daily/
  14. PATH=`/usr/bin/dirname $1`;
  15. FILE=`/bin/basename $1`;
  16. /bin/ln -s $1 $PATH/daily/$FILE
  17. endscript
  18. }

解决方法

关键是知道CentOS从anacron运行/etc/cron.{daily,weekly,monthly}中的脚本… / etc / anacrontab正在设置RANDOM_DELAY,它可以达到预期的效果(它在开始之前延迟到RANDOM_DELAY分钟)工作)…
  1. # /etc/anacrontab: configuration file for anacron
  2.  
  3. # See anacron(8) and anacrontab(5) for details.
  4.  
  5. SHELL=/bin/sh
  6. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  7. MAILTO=root
  8. # the maximal random delay added to the base delay of the jobs
  9. RANDOM_DELAY=45
  10. # the jobs will be started during the following hours only
  11. START_HOURS_RANGE=3-22
  12.  
  13. #period in days delay in minutes job-identifier command
  14. 1 5 cron.daily nice run-parts /etc/cron.daily
  15. 7 25 cron.weekly nice run-parts /etc/cron.weekly
  16. @monthly 45 cron.monthly nice run-parts /etc/cron.monthly

设置RANDOM_DELAY = 0 / START_HOURS_RANGE = 3解决了问题…

编辑

经过深思熟虑后,我要删除anacron并安装普通的vixie cron ……

猜你在找的Linux相关文章