zoukankan      html  css  js  c++  java
  • nginx日志切割

      当请求上来的时候nginx的日志是不个不容小觑的文件,它能增长到令人发指的地步,硬盘占满也是早晚的事

    要切割的日志

      access.log 和 error.log,目录  /home/nginx/logs/  (自己Nginx的安装目录)

    日志切割脚本

    #!/bin/bash
    year=`date +%Y`
    month=`date +%m`
    day=`date +%d`
    logs_backup_path="/home/nginx/logs_backup/$year$month"               #日志存储路径
    
    logs_path="/home/nginx/logs/"                                                             #要切割的日志路径
    logs_access="access"                                                                            #要切割的日志
    logs_error="error"
    pid_path="/home/nginx/logs/nginx.pid"                                                 #nginx的pid
    
    [ -d $logs_backup_path ]||mkdir -p $logs_backup_path
    rq=`date +%Y%m%d`
    #mv ${logs_path}${logs_access}.log ${logs_backup_path}/${logs_access}_${rq}.log
    mv ${logs_path}${logs_error}.log ${logs_backup_path}/${logs_error}_${rq}.log
    kill -USR1 $(cat /home/nginx/logs/nginx.pid)

    定时任务(按天进行日志切割)

      crontab -e   #注意是 -e

      59 23 * * * bash /home/nginx/logs/cut_ngnix_log.sh   #每天23:59分开始执行;

  • 相关阅读:
    Lake Counting
    部分和问题
    迷宫最短路
    sublime 的使用技巧
    数组
    Factorial Trailing Zeroes
    Top K Frequent Elements
    Number of Connected Component in An Undirected Graph
    Zigzag Iterator
    Single Number III
  • 原文地址:https://www.cnblogs.com/xbblogs/p/10654045.html
Copyright © 2011-2022 走看看