我在/etc/logrotate.d/中放了一个logrotate配置文件,并希望日志在一致的时间旋转;然而,他们没有…记录旋转时间似乎是随机的/ – 一小时.
为什么日志轮换开始时间是随机的,我该如何更改?
信息:我的logrotate配置文件看起来像这样……
/opt/backups/network/*.conf { copytruncate rotate 30 daily create 644 root root dateext maxage 30 missingok notifempty compress delaycompress postrotate ## Create symbolic links in daily/ PATH=`/usr/bin/dirname $1`; FILE=`/bin/basename $1`; /bin/ln -s $1 $PATH/daily/$FILE endscript }
解决方法
关键是知道CentOS从anacron运行/etc/cron.{daily,weekly,monthly}中的脚本… / etc / anacrontab正在设置RANDOM_DELAY,它可以达到预期的效果(它在开始之前延迟到RANDOM_DELAY分钟)工作)…
# /etc/anacrontab: configuration file for anacron # See anacron(8) and anacrontab(5) for details. SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # the maximal random delay added to the base delay of the jobs RANDOM_DELAY=45 # the jobs will be started during the following hours only START_HOURS_RANGE=3-22 #period in days delay in minutes job-identifier command 1 5 cron.daily nice run-parts /etc/cron.daily 7 25 cron.weekly nice run-parts /etc/cron.weekly @monthly 45 cron.monthly nice run-parts /etc/cron.monthly
设置RANDOM_DELAY = 0 / START_HOURS_RANGE = 3解决了问题…
编辑
经过深思熟虑后,我要删除anacron并安装普通的vixie cron ……