nginx 日志轮询脚本
nginx 没有自带日志轮询功能, 这个脚本必须配合crontab来实现日志的按天轮询。生产环境使用下还是很靠谱和方便,推荐给大家使用。 里面具体的内容大家自己看把有点shell基础就能明白的。
crontab -e
00 08 * * * /bin/bash /opt/scripts/BackupNginxLog.sh
BackupNginxLog.sh
#!/bin/bash LogPath=/usr/local/logs_nginx BackupPath=/opt/BackupLogs Yesterday=`date -d "yesterday" +%Y%m%d` #NginxPid=`cat /var/run/nginx.pid` NginxPid=`cat /usr/local/nginx/nginx.pid` BackupSaveCycle=+5 [ -d ${BackupPath} ] || mkdir -p ${BackupPath} cd $LogPath mv downt.log $BackupPath\/downt.ntalker.com.log_$Yesterday.log mv crmcentertlog $BackupPath\/crmcentert.ntalker.com.log_$Yesterday.log #echo $BackupPath\/images_access80_$Yesterday.log kill -USR1 $NginxPid sleep 5 cd $BackupPath #tar zcvf images_access80_$Yesterday.tgz images_access80_$Yesterday.log gzip downt.log_$Yesterday.log gzip crmcentert.log_$Yesterday.log sleep 5 find $BackupPath -mtime $BackupSaveCycle -exec rm {} \;
本文出自 “振兴的空间” 博客,请务必保留此出处http://renzhenxing.blog.51cto.com/728846/1579226
原文地址:http://renzhenxing.blog.51cto.com/728846/1579226