使用logrotate做nginx日志轮询

来源:互联网 发布:局域网行为监控软件 编辑:程序博客网 时间:2024/06/05 04:06
  

logrotate看名字就知道是专门做日志轮询的,只把任务配置放在/etc/logrotate.d/下,任务就会自动完成,而且无需安装,系统自带,比较推荐使用.

Java代码
  1. [root@srv logrotate.d]# vi /etc/logrotate.d/nginx  
[root@srv logrotate.d]# vi /etc/logrotate.d/nginx


配置如下

Java代码
  1. /usr/local/nginx/logs/www.willko.cn.log /usr/local/nginx/logs/nginx_error.log {   
  2.         notifempty   
  3.         daily   
  4.         sharedscripts   
  5.         postrotate   
  6.                 /bin/kill -USR1 `/bin/cat /usr/local/nginx/nginx.pid`   
  7.         endscript   
  8.   
  9. }  
/usr/local/nginx/logs/www.willko.cn.log /usr/local/nginx/logs/nginx_error.log {
            notifempty 
            daily 
            sharedscripts 
            postrotate 
                     /bin/kill -USR1 `/bin/cat /usr/local/nginx/nginx.pid` endscript 
}多个日志以空格分开, notifempty 如果日志为空则不做轮询 daily 每天执行一次 postrotate 日志轮询后执行的脚本 这样,每天都会自动轮询,生成nginx.log.1-n 
原创粉丝点击