Linux   发布时间:2022-05-08  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux – 为什么我的CentOS logrotate随机运行?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在/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 ……

大佬总结

以上是大佬教程为你收集整理的linux – 为什么我的CentOS logrotate随机运行?全部内容,希望文章能够帮你解决linux – 为什么我的CentOS logrotate随机运行?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: