zoukankan      html  css  js  c++  java
  • nginx日志按天自动切割

    1、编写shell脚本,创建nginx_log.sh文件
    #!/bin/bash
    source /etc/profile
    #设置Nginx日志文件存放目录
    log_path="/usr/local/nginx/logs"
    YESTERDAY=`date -d "yesterday" +"%Y%m%d"`
    #对日志进行重命名
    mv ${LOG_PATH}/access.log    ${LOG_PATH}/access.log_$YESTERDAY
    pid_path=“/usr/local/nginx/logs/nginx.pid“

    #重载日志文件
    kill -USR1 `cat ${PID_PATH}`

    #对日志进行压缩
    gzip ${LOGS_PATH}/access_${YESTERDAY}.log

    2、修改nginx_log.sh文件权限,此处设置为可执行权限
    chmod a+x /usr/local/nginx/nginx_log.sh

    3、添加任务计划
    [root@nginx171 ~]# vim /etc/crontab
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=root
    # For details see man 4 crontabs
    # Example of job definition:
    # .---------------- minute (0 - 59)
    # | .------------- hour (0 - 23)
    # | | .---------- day of month (1 - 31)
    # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
    # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    # | | | | |
    # * * * * * user-name command to be executed
    00 00 * * * root /usr/local/nginx/nginx_log.sh

    4、查看效果,/usr/local/nginx/logs目录下多出一个日志文件 

     

     

     

     
  • 相关阅读:
    c#结构体、打他table、excel、csv互转
    WPF 自定义图表(柱状图,曲线图)
    NemaStudio船舶模拟软件下载及破解
    点双连通分量
    HDU4612 Warm up
    边双连通分量
    [Jsoi2010]连通数
    Intern Day73
    Intern Day72
    Intern Day70
  • 原文地址:https://www.cnblogs.com/larry-luo/p/10678137.html
Copyright © 2011-2022 走看看