logrotate 学习

/var/lib/docker/containers/*/*.log {
  rotate 7
  daily
  compress
  size=1M
  missingok
  delaycompress
  copytruncate
}
 copytruncate 会先cp 目标日志文件,然后清空目标文件。 offset 清零,重新从头append
  nocopytruncate 会mv  目标日志文件至备份,然后需要重启服务或者发送信号重新生成日志文件。

# Lines below here are managed by Salt, do not edit
# crontab logrotate wireles nginx log by salt
0 1 * * * /usr/sbin/logrotate  -f /root/scripts/wireless-logrotate.sh

"/data2/logs/nginx/wireless.*.log" {
nocopytruncate
missingok
rotate 876000
compress
delaycompress
notifempty
sharedscripts
postrotate
   /bin/kill -USR1 `cat /data1/run/nginx_zhe800.pid`
endscript
dateext
dateformat -%Y-%m-%d-%s
olddir /data2/logs/nginx/oldlog
}

对于日志输出量大的日志 建议每小时切割但不压缩,然后选定凌晨时间进行压缩

/bin/find /data1/logs/nginx/oldlog/tmp_log/  -type f -name '*.log'  |xargs -r -n 1 -P 3 gzip && mv  /data1/logs/nginx/oldlog/tmp_log/*.gz /data1/logs/nginx/oldlog/


Pingbacks已打开。

引用地址

评论
发表评论