利用linux自带的logrotate切割nginx的日志

1.  采用linux系统自带的logrotate

    1.  logrotate的配置文件: /etc/logrotate.conf

        配置文件里面的参数,按照自己的需求进行修改,我这里使用默认值

weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
        minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

    2.  在/etc/logrotate.d目录下,新建一个文件nginx,内容如下:

/data/logs/nginx/*log {
    daily
    rotate 7
    missingok
    notifempty
    create 0644 root root
    compress
    sharedscripts
    postrotate
        [ ! -f /usr/local/nginx/logs/nginx.pid ] || kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
    endscript
}

        参数解释:

          #脚本调用

          prerotate/endscript - 指定日志转存前调用脚本

          postrotate/endscript - 指定日志转存后调用脚本

 

posted @ 2017-10-30 18:37  奋斗史  阅读(155)  评论(0)    收藏  举报