Nginx log grows too fast, scheduled log management

Source: Internet
Author: User

1> vi/usr/local/webserver/nginx/logs/cut_nginx_log.sh

#!/bin/bash#function:cut nginx log files for lnmp  #author:  http://lnmp.org# Set the path to nginx log fileslog_files_path= "/usr/local/webserver/nginx/logs/" Log_files_dir= "/usr/local/webserver/nginx/logs/old/" #set  nginx log files you want  to cutlog_files_name= "Access.log" save_days=30mkdir -p ${log_files_dir}################### ######################### #Please  do not modify the following script ####### ##################################### #cp  ${log_files_path}${log_files_name} ${log_files_path}${log_ files_name}_bak# Cycle Generation Delete 3rd to 12th old log, #for ((i=3;i<13;i++)), #do   #if  [  $i  -lt  ' ten '  ] ; then#d=0$i#else#d= $i #fi#11/oct/2015#date_g=$ (date -d last-day + "%d/%b/%Y") #date_g = $d/oct/2015# 20151011#date_l=$ (date -d last-day + "%y%m%d") #date_l =201510$d#11\/oct\/2015#date=$ (date -d  last-day + "%d\/%b\/%y") #date = "$d \/oct\/2015" #cat  ${log_files_path}${log_files_name} | grep ${ date_g} >${log_files_dir}www_access_${date_l}.log#sed -i /${date}/d ${log_files_path}${ Log_files_name} #done #11/oct/2015   yesterday date date_g=$ (date -d last-day + "%d/%b/%Y") #20151011    Yesterday date    date_l=$ (date -d last-day + "%y%m%d") #11 \/oct\/2015    Yesterday date date=$ (date -d last-day + "%d\/%b\/%y") Cat ${log_files_path}${log_files_name}  | grep ${date_g} >${log_files_dir}www_access_${date_l}.logsed -i /${date}/d  ${log_files_path}${log_files_name} #delete  30 days ago nginx log filesfind  ${log_files_dir} -mtime +${save_days} -exec rm -rf {} \; # Restart Nginx service, otherwise don't know why, the log no longer grows/usr/local/webserver/nginx/sbin/nginx -s reload

2>chmod 777/usr/local/webserver/nginx/logs/cut_nginx_log.sh #运行的权限

3>crontab-e

Trailing append:

0 4 * * */usr/local/webserver/nginx/logs/cut_nginx_log.sh

4>crontab-l #查看是否成功

This article is from "Meow" blog, please be sure to keep this source http://aijinnini.blog.51cto.com/10783125/1702380

Nginx log grows too fast, scheduled log management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.