日志分割工具logrotate

日志分割工具logrotate

nginx
tee /etc/logrotate.d/nginx <<-EOF
/data/wwwlogs/*main.log {
  daily
  rotate 5
  missingok
  dateext
  compress
  notifempty
  sharedscripts
  postrotate
    [ -e /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
  endscript
}
EOF
other tools
tee /etc/logrotate.d/mymon <<-EOF
/home/work/gopath/src/github.com/open-falcon/mymon/mymon.log {
  daily
  rotate 5
  missingok
  dateext
  compress
  notifempty
  sharedscripts
  postrotate
  endscript
}
EOF
logrotate -d /etc/logrotate.d/mymon             #测试
logrotate -vf /etc/logrotate.d/mymon            #强制执行
简单说明参数
  daily                 #每日执行,weekly,yearly
  rotate 5              #保存几份
  missingok             #忽略logrotate执行时的错误
  dateext               #日期方式命令保存的文件
  compress              #压缩
  notifempty            #检查日志文件是否为空,空不执行
  sharedscripts         
  postrotate            #其他命令
posted @ 2018-09-11 15:00  ops_sylar  阅读(620)  评论(0编辑  收藏  举报