nginx日志轮询切割实战
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx日志轮询切割实战相关的知识,希望对你有一定的参考价值。
apache切割工具: cronlog 和rotare等日志切割工具
nginx切割工具有: nginx cron+x scripts
[[email protected] ~]# mkdir -p /server/scripts [[email protected] ~]# cd /server/scripts/ [[email protected] scripts]# vim cut_nginx_log.sh #vim输入如下内容 cd /application/nginx/logs /bin/mv access.log access_$(date +%F).log /application/nginx/sbin/nginx -s reload
[[email protected] logs]# /bin/sh /server/scripts/cut_nginx_log.sh [[email protected] scripts]# ls /application/nginx/logs/ access.log error.log nginx.pid access_2017-08-21.log [[email protected] scripts]# date -s "2016/05/14" #设定现在时间为20160514 Sat May 14 00:00:00 CST 2016 [[email protected] scripts]# /bin/sh /server/scripts/cut_nginx_log.sh [[email protected] scripts]# ls /application/nginx/logs/ access_2016-05-14.log access.log nginx.pid access_2017-08-21.log error.log www_access_2017-08-21.log
继续优化切割脚本
[[email protected] scripts]# vim cut_nginx_log.sh cd /application/nginx/logs /bin/mv access.log access_$(date +%F).log /application/nginx/sbin/nginx -s reload # rsync .....to backup server #del date before 7 day find ...
设置定时任务:每天00:00切换日志
[[email protected] scripts]# crontab -e [[email protected] scripts]# crontab -l #time sync by oldboy at 2010-2-1 */5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1 #backup 00 00 * * * /bin/bash /server/scripts/backup.sh &>/dev/null ######cut_nginx_log##### 00 00 * * * /bin/sh /server/scripts/cut_nginx_log.sh>/dev/null 2>&1 ##这个就是切割日志
上述脚本时间可以写成access_$(date %F -d ‘-1day‘).log ##就是当前日志-1天意思
本文出自 “sandshell” 博客,请务必保留此出处http://sandshell.blog.51cto.com/9055959/1958181
以上是关于nginx日志轮询切割实战的主要内容,如果未能解决你的问题,请参考以下文章