1、新建日志分割文件
目录:
cd /etc/logrotate.d
新建:
vim nginxlog
添加内容:
/usr/local/nginx/logs/sjt_access.log {
su root root
daily
missingok
dateext
rotate 180
compress
delaycompress
postrotate
/bin/kill -HUP cat /usr/local/nginx/logs/sjt_nginx.pid 2> /dev/null
2> /dev/null || true
endscript
create 644 root root
}
2、添加定时任务
crontab -e
59 23 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginxlog