配置nginx日志切割功能
1.查看日志
ll /usr/local/nginx/logs/access.log
2.编写切割日志的脚本
vim /opt/cut_nginx_log.sh
#!/bin/bash
#cut_nginx_log.sh
ll /usr/local/nginx/logs/access.log
2.编写切割日志的脚本
vim /opt/cut_nginx_log.sh
#!/bin/bash
#cut_nginx_log.sh
datetime=$(date -d "-1 day" "+%Y%m%d")
log_path="/usr/local/nginx/logs"
pid_path="/usr/local/nginx/logs/nginx.pid"
[ -d $log_path/backup ] || mkdir -p $log_path/backup
if [ -f $pid_path ]
then
mv $log_path/access.log $log_path/backup/access.log-$datetime
kill -USR1 $(cat $pid_path)
find $log_path/backup -mtime +30 | xargs rm -f
else
echo " Error,Nginx is not working!" | tee -a /var/log/massages
fi
3.设置一个周期性的计划任务
crontab -e
0 0 * * * /opt/cut_nginx_log.sh