nginx的日志轮转

nginx的日志轮转:
[root@192 ~]# rpm -ql nginx |grep log

/etc/logrotate.d/nginx

/var/log/nginx

[root@192 ~]# vim /etc/logrotate.d/nginx

/var/log/nginx/*.log { #指定需要轮转处理的日志文件

daily #日志文件轮转周期,可用值为: daily/weekly/yearly

missingok# 忽略错误信息

rotate 7 # 轮转次数,即最多存储7个归档日志,会删除最久的归档日志

minsize 5M #限制条件,大于5M的日志文件才进行分割,否则不操作

dateext # 以当前日期作为命名格式

compress # 轮循结束后,已归档日志使用gzip进行压缩

delaycompress # 与compress共用,最近的一次归档不要压缩

notifempty # 日志文件为空,轮循不会继续执行

create 640 nginx nginx #新日志文件的权限

sharedscripts #有多个日志需要轮询时,只执行一次脚本 postrotate # 将日志文件转储后执行的命令。以endscript结尾,命令需要单独成行

if [ -f /var/run/nginx.pid ]; then #判断nginx的PID。# 默认logrotate会以 root身份运行

kill -USR1 cat /var/run/nginx.pid

fi

endscript

}

执行命令: [root@192 nginx]# /usr/sbin/logrotate -f /etc/logrotate.conf

创建计划任务: [root@192 nginx]# crontab -e

59 23 * * * /usr/sbin/logrotate -f /etc/logrotate.conf
 

原文地址:https://www.cnblogs.com/wyglog/p/12494776.html