- 首先安装logrotate日志切割工具
yum -y install logrotate
- vim /etc/logrotate.d/nginx
- 在/etc/logrotate.d目录下创建一个nginx的配置文件"nginx"配置内容如下,里面的路径根据自己项目的实际情况配置
/opt/wisecloud/cloudstorage/cs_resty/software/cs_resty/logs/*.log {
daily
rotate 5
missingok
notifempty
create 0664 root utmp
olddir /opt/wisecloud/cloudstorage/cs_resty/software/cs_resty/logs/history_log
sharedscripts
postrotate
if [ -f /opt/wisecloud/cloudstorage/cs_resty/software/cs_resty/logs/nginx.pid ]; then
kill -USR1 `cat /opt/wisecloud/cloudstorage/cs_resty/software/cs_resty/logs/nginx.pid`
fi
endscript
}
- 让logrotate每天进行一次滚动,在crontab中添加一行定时脚本
crontab -e
59 23 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx_log
每天23点59分进行日志滚动
网友评论