zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    13种状况不宜立即止损
    市场运行趋势该如何研判
    炒股的九重境界
    标准止损法
    又感冒了
    量价分析之毕生经验之谈
    您的电池出现问题,因此可能导致您的计算机突然关机 出现红色X
    《股票大作手操盘术》读书笔记
    Spring.NET学习笔记——目录(原)
    Spring.NET实用技巧2——NHibernate访问Oracle数据库
  • 原文地址:https://www.cnblogs.com/fengzhongzhuzu/p/8962010.html
Copyright © 2011-2022 走看看