功用:通过使用logrotate和crontab,将Nginx单日志,按照logrotate配置要求每个小时进行一次转储操作。


运行环境:centos 6.6,


所需安装程序:logrotate,crontab

安装:   

   yum install logrotate crontabs 



配置logrotate

添加|修改 /etc/logrotate.d/nginx

内容为


/var/log/nginx/access/access.log /var/log/nginx/access/default.log { 

rotate 3

size=50G

missingok

notifempty

compress

delaycompress

sharedscripts

postrotate

  /usr/sbin/nginx -s reload > /dev/null 2>&1

endscript

}


配置crontabs


创建计划任务每小时执行一次logrotate并将日志记录追加于/tmp/logrotate.日期中

执行: 

echo "0 * * * * /usr/sbin/logrotate -vf /etc/logrotate.d/nginx >>/tmp/logrotate.`date +%y%m%d` 2>&1"|crontab