• nginx 日志切割


    nginx优化之日志切割

    编写日志分割的脚本

    复制代码
    #!/bin/bash
    #nginx日志切割
    ACCESS_LOG=/var/log/nginx/access.log
    ERROR_LOG=/var/log/nginx/error.log
    

    NGINX=/usr/local/nginx/sbin/nginx
    DATE
    =<span style="color: rgba(0, 0, 255, 1)">date</span> -d <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">-1 day</span><span style="color: rgba(128, 0, 0, 1)">"</span> +%Y%m%<span style="color: rgba(0, 0, 0, 1)">d
    BAKUP_DIR=/bakup/logs/nginx

    STATUS=<span style="color: rgba(0, 0, 255, 1)">ps</span> -ef |<span style="color: rgba(0, 0, 255, 1)">grep</span> nginx |<span style="color: rgba(0, 0, 255, 1)">wc</span> -<span style="color: rgba(0, 0, 0, 1)">l

    [ -d $BAKUP_DIR ] ||mkdir -p $BAKUP_DIR

    if [ $STATUS -gt 1 ];then
    mv $ACCESS_LOG $BAKUP_DIR/access.log-$DATE
    mv $ERROR_LOG $BAKUP_DIR/error.log-$DATE
    $NGINX
    -s reopen
    gzip -9 $BAKUP_DIR/*
    else
    echo "error: nginx is stoped." |tee -a $ERROR_LOG
    fi

    find $BAKUP_DIR -name ".log" -mtime +7 -exec rm -rf {} ;

    复制代码

    将脚本添加到系统定时任务中

    [root@lb nginx]# crontab -l
    0    0    *    *    *    /root/logqg.sh
    [root@lb nginx]#
    [root@lb nginx]# chmod +x /root/logqg.sh

  • 相关阅读:
    Javascript 与 c# 数据加密互通 DEC
    Auto.js 隐藏日志信息、定时器
    Auto.js 检测开启无障碍
    Auto.js 初学碰到的坑
    SmartAssembly 汉化说明
    espcms 表结构说明
    处理器调度
    进程死锁与避免
    并发程序设计
    Mysql性能调优
  • 原文地址:https://www.cnblogs.com/ianlab/p/14009258.html
Copyright © 2020-2023  润新知