日志分片

  1. 新建shell脚本log_cut

     vim /usr/bin/log_cut
    
     #!/bin/bash
     # Nginx日志分割 创建:2017-02-16
    
     # 日志文件路径
     LOGS_PATH=/usr/local/nginx-1.11.5/logs
    
     # 当前时间格式
     TODAY=$(date -d 'today' +%Y-%m-%d)
    
     # 移动当前日志
     mv ${LOGS_PATH}/error.log  ${LOGS_PATH}/error_${TODAY}.log
     mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${TODAY}.log
    
     # 重新打开日志
     /usr/local/nginx-1.11.5/sbin/nginx -s reopen
    
     ESC
     :wq
    
  2. 添加计划任务

     crontab -e
     0 0 * * * /usr/bin/log_cut
     ESC
     :wq
     chmod 755 /usr/bin/log_cut
    
  3. 每天00:00之后即可看到效果

@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2019-07-08 16:49:59

results matching ""

    No results matching ""