logrotate脚本定时每日执行,脚本通常在 /etc/cron.daily/
logrotate对nginx的配置在,/etc/logrotate.d/nginx
举例:
/var/log/nginx/*/*.log {
daily
missingok
rotate 5
compress
nodelaycompress
notifempty
create 0644 nginx adm
sharedscripts
prerotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
daily,每日轮询,其他参数还有weekly、monthly、yearly
missingok,日志路径不存在时,不报错
rotate 5,如果时间是daily,rotate 5代表保留近5天的日志,之前的日志删掉
compress,记录完成的日志以gzip格式压缩
nodelaycompress,在每日轮询之后压缩日志
notifempty,日志为空就不轮询
create 0644 nginx adm,日志模式是0644,owner是nginx,group是adm
sharedscripts,多日志共用同一脚本,不用重启服务多次
prerotate,命令开始
endscript,命令结束