功能:按天分割nginx日志文件,并且只保留最近60天日志文件
配置文件:
/etc/logrotate.conf
配置目录
/etc/logrotate.d
新建文件/etc/logrotate.d/nginx
vi nginx
写入以下内容:
/usr/local/nginx/logs/*.log {
missingok
rotate 60
nocompress
daily
notifempty
dateext
create 644 nginx nginx
sharedscripts
postrotate
[ -f /usr/local/nginx/run/nginx.pid ] && kill -USR1 `cat /usr/local/nginx/run/nginx.pid`
endscript
}
//调试
logrotate -d -f /etc/logrotate.d/nginx
monthly:说明是一个月进行一次处理,常用的还有daily,weekly
rotate 2:意思是说最多保留两个备份,多余的老的日志就被覆盖了
olddir:定义了旧的日志存储在哪里
missingok:意思是如果上述news.crit文件找不到的话也不报错,直接跳过
postrotate … endscript:它们以及中间的命令定义了在执行完rotate之后要做什么,一般主要是为了让使用该日志文件的程序知道这个日志被替换了,需要重新打开这个文件
nocompress:说明旧日志不需要被压缩保存
logrotate定义了如何处理日志,而它