日志切割

配置文件格式

[root@yu ~]# cat /etc/logrotate.d/nginx
/usr/local/openresty/nginx/logs/*.log {    #指定你要切割的文件
    daily                                  #每天
    rotate 7                               #最多保留多少个切割后的日志.
    missingok                              #如果对应日志不存在,跳过,不显示错误信息
    dateext                                #归档日志文件的旧版本,添加日期扩展名,如YYYYMMDD,而不是简单地添加数字。可以使用dateformat和datetoday选项配置扩展名。
    compress                               #日志是否压缩 gzip
    delaycompress                          #延迟一个周期,然后在进行压缩
    notifempty                             #not if empty 如果日志是空的跳过.
    sharedscripts
    postrotate                             #在日志轮询(切割)之后,执行里面的命令
        if [ -f /usr/local/openresty/nginx/logs/nginx.pid ]; then
            kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`
        fi
    endscript
}

crontab定时执行,命令格式 logrotate -vf /etc/logrotate.d/nginx

posted @ 2022-11-28 14:12  ForLivetoLearn  阅读(61)  评论(0编辑  收藏  举报