Home > Backend Development > PHP Tutorial > nginx or tengine access log split processing

nginx or tengine access log split processing

WBOY
Release: 2016-07-29 09:08:06
Original
1381 people have browsed it

When using naginx, the access log is getting larger and larger, which can reach GB level, so we need to split it,

I split it according to time,

#!/bin/bash

#访问日志文件位置
nginx_path="/usr/local/nginx/logs/"
bak_path="/usr/local/nginx/logs/dowload/"
#本程序log位置  包含文件名
log_path="/usr/local/nginx/logs/mv_log.log"
#文件夹名称英文逗号分隔
access_name="dir1,dir2,dir3,dir4,dir5,dir6"
#nginx pid文件位置
nginx_pid_path="/usr/local/nginx/logs/nginx.pid"
DATE=$(date +%Y-%m-%d )
log_time=$(date +%Y-%m-%d_%H:%M:%S)
echo "time ${DATE}"
echo $log_time
OLD_IFS="$IFS"
IFS=","
arr=($access_name)
IFS="$OLD_IFS"
echo "####################### mv log ${log_time}  #####################################"  >>${log_path}
for s in ${arr[@]}
do
    src_path=$nginx_path"/"$s"/"access_$s.log
    #echo $nginx_path"/"$s"/"access_$s.log
    echo "####($s)_ start_${log_time} ####" >> ${log_path}
    if [ -f "$src_path" ]; then 
        mv $src_path $bak_path$s"/"access_${log_time}.log  2>> ${log_path}
        #防止文件过大或过多 每个进行复制和发送变量
        kill -USR1 `cat ${nginx_pid_path}`
	#echo "  $s move Success  " >>${log_path}
    else
       echo "##($s)_NOT_FIND_FILE_${log_time} ##" >> ${log_path}
    fi
    echo "####($s)_end_${log_time} ######" >> ${log_path}
    echo " " >>${log_path}
done
echo "######################## END LOG #################################################"  >> ${log_path}
echo "" >>${log_path}
echo "" >>${log_path}
Copy after login

The above introduces the nginx or tengine access log segmentation processing, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template