• nginx 的日志切割


    nginx的日志切割脚本

    说明:在nginx的配置文件中nginx.conf并没有定义access_log的位置,

    在/usr/local/nginx/conf/vhost/下的配置文件中定义了access_log的位置。

    该位置在/home/wwwlogs/的目录下,

    本例中是在/usr/local/nginx/conf/vhost/下有90005.com.conf和www-xam.com两个配置文件,

    同样的access_log定义了

    access_log  /home/wwwlogs/90005.com_access.log;

    access_log  /home/wwwlogs/www-xam.com_access.log;

    vi nginx.cut.sh

    #!/bin/bash
    #function:cut nginx log files for nginx

    #set the path to nginx log files
    log_files_path="/home/wwwlogs/"
    #log_files_dir=${log_files_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")
    log_files_dir=$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")
    #set nginx log files you want to cut
    log_files_name=( 90005.com_access www-xam.com_access)
    #set the path to nginx.
    nginx_sbin="/usr/local/nginx/sbin/nginx"
    #Set how long you want to save
    save_days=10

    cd $log_files_path

    mkdir -p $log_files_dir

    log_files_num=${#log_files_name[@]}

    #cut nginx log files
    for((i=0;i<$log_files_num;i++));do
    #mv ${log_files_path}${log_files_name[i]}.log ${log_files_dir}/${log_files_name[i]}_$(date -d "yesterday" +"%Y%m%d").log
    tar -zcvf ${log_files_dir}/${log_files_name[i]}_$(date -d "yesterday" +"%Y%m%d").tar.gz ${log_files_name[i]}.log
    #delete source
    rm -rf ${log_files_name[i]}.log
    done

    #delete 10 days ago nginx log files
    find $log_files_path -mtime +$save_days -exec rm -rf {} ;

    $nginx_sbin -s reload

    在crontab中同步脚本文件

    * 0 * * * sh /home/shell/cut_nginx_logs.sh  >> /dev/null 2>&1

  • 相关阅读:
    《DSP using MATLAB》Problem 6.17
    一些老物件
    《DSP using MATLAB》Problem 6.16
    《DSP using MATLAB》Problem 6.15
    《DSP using MATLAB》Problem 6.14
    《DSP using MATLAB》Problem 6.13
    《DSP using MATLAB》Problem 6.12
    《DSP using MATLAB》Problem 6.11
    P1414 又是毕业季II
    Trie树
  • 原文地址:https://www.cnblogs.com/fengzhongzhuzu/p/8962010.html
Copyright © 2020-2023  润新知