日志分割工具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
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 #其他命令