nginx日志切割
nginx日志切割方式一 [root@weixinxiaochengxu ~]# crontab -l 01 05 * * * ntpdate -u 10.100.60.6 #Ansible: nginx-logcut 0 0 * * * /bin/sh /opt/nginx_logcut.sh 2>&1 > /dev/null #Ansible: nginx-logdel 1 0 * * * /bin/sh /opt/nginx_logdel.sh 2>&1 > /dev/null [root@weixinxiaochengxu ~]# cat /opt/nginx_logcut.sh #!/bin/bash nginxpiddir=/usr/local/nginx/logs nginxlogpath=/storage/nginx/logs mv $nginxlogpath/access.log $nginxlogpath/access_`date +%Y-%m-%d`.log mv $nginxlogpath/error.log $nginxlogpath/error_`date +%Y-%m-%d`.log kill -USR1 `cat $nginxpiddir/nginx.pid` [root@weixinxiaochengxu ~]# cat /opt/nginx_logdel.sh #!/bin/bash rm -rf /storage/nginx/logs/access_`date -d "-30 day" "+%Y-%m-%d"`.log rm -rf /storage/nginx/logs/error_`date -d "-30 day" "+%Y-%m-%d"`.log
nginx日志切割方式二 logrotate /storage/nginx-logs/*.log { daily missingok rotate 60 compress delaycompress dateext notifempty sharedscripts postrotate if [ -f /var/run/nginx.pid ]; then /bin/kill -USR1 `cat /var/run/nginx.pid` fi endscript }