nginx日志切割配置
1)日志切割脚本
#!/bin/bash
LOG_PATH="/usr/local/nginx/logs"
RECORD_TIME=$(date -d "today" +%Y-%m-%d)
PID=/usr/local/nginx/logs/nginx.pid
mv ${LOG_PATH}/access.log ${LOG_PATH}/access.${RECORD_TIME}.log
mv ${LOG_PATH}/error.log ${LOG_PATH}/error.${RECORD_TIME}.log
kill -USR1 `cat $PID
2)定时任务
定时任务常见命令
# 查看定时任务
crontab -l
# 编辑定时任务
crontab -e
# 启动定时任务
systemctl start crond
# 关闭定时任务
systemctl stop crond
# 重启定时任务
systemctl restart crond
把日志切片脚本加入定时任务
crontab -e
# 每天凌晨23:59进行日志切片
59 23 * * * /usr/local/nginx/sbin/cut_log.sh
systemctl restart crond

浙公网安备 33010602011771号