加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-13 18:32:04 所属栏目:Linux 来源:网络整理
导读:我在/etc/logrotate.d/中放了一个logrotate配置文件,并希望日志在一致的时间旋转;然而,他们没有…记录旋转时间似乎是随机的/ – 一小时. 为什么日志轮换开始时间是随机的,我该如何更改? 信息:我的logrotate配置文件看起来像这样…… /opt/backups/network/
我在/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 ……

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读