使用 Logrorate 切割 nginx 日志
1 | vim /etc/logrotate.d/nginx |
1 | /var/log/nginx/*.log #此处为nginx存储日志的地方; |
测试程序执行的情况
1 | logrotate -vf /etc/logrotate.d/nginx |
查看 log 文件的具体执行情况
1 | cat /var/lib/logrotate/logrotate.status |
加入定时任务
1 | crontab -e |
1 | 0 0 * * * /usr/sbin/logrotate -vf /etc/logrotate.d/nginx #每天凌晨00:00自动执行日志切割任务; |
常见问题
1、分割日志时报错:error: skipping “/var/log/nginx/test.access.log” because parent directory has insecure permissions (It’s world writable or writable by group which is not “root”) Set “su” directive in config file to tell logrotate which user/group should be used for rotation.
在配置文件中添加 “su root nginx
1 | /var/log/nginx/*.log |