Linux日志轮询设置时间执行【原创】

自动切割时间 默认的logrotate(配置文件里设置的是cron.daily)一般会在每天的3点05分到3点50分之间执行

但是由于我们统计日志时间需要从每天0点开始,所以就要利用crontab设置定时任务执行

 

1、创建自定义目录
mkdir /etc/logrotate_self

2、创建日志轮询文件
cat /etc/logrotate_self/nginx
/usr/local/nginx/logs/*.log{
daily
create 644 root root
dateext
copytruncate
compress
delaycompress
rotate 30
notifempty
missingok
}

3、测试
logrotate -d /etc/logrotate_self/nginx # 测试
logrotate -v -f /etc/logrotate_self/nginx # 强制

4、设置定时任务
# nginx日志分割
0 0 * * * /usr/sbin/logrotate  -vf /etc/logrotate_self/nginx

 

posted @ 2022-11-28 12:20  paul_hch  阅读(556)  评论(0编辑  收藏  举报