码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 访问日志轮询切割

时间:2017-05-25 19:43:14      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:access   cut   bash   nbsp   就会   日志   ash   div   不同的   

默认情况下 Nginx 会把所有的访问日志生成到一个指定的访问日志文件 access.log 里,但这样一来,时间长了就会导致日志个头很大,不利于日志的分析和处理,因此,有必要对 Nginx 日志,按天或按小时进行切割,使其分成不同的文件保存。

[root@localhost conf]# cat cut_nginx_log.sh 
#!/bin/bash
Dateformat=`date +%Y%m%d`
Basedir="/usr/local/nginx"
Nginxlogdir="$Basedir/logs"
Logname="access"
[ -d $Nginxlogdir ] && cd $Nginxlogdir || exit 1
[ -f ${Logname}.log ] || exit 1
/bin/mv ${Logname}.log ${Dateformat}_${Logname}.log
$Basedir/sbin/nginx -s reload
[root@localhost nginx]# crontab -l
0 0 * * * /bin/bash /usr/local/nginx/conf/cut_nginx_log.sh > /dev/null 2>&1

 

效果:

[root@localhost logs]# ll
-rw-r--r--. 1 root root    0 May 25 18:57 20170521_access.log
-rw-r--r--. 1 root root    0 May 25 18:57 20170522_access.log
-rw-r--r--. 1 root root    0 May 25 18:57 20170523_access.log
-rw-r--r--. 1 root root    0 May 25 18:57 20170524_access.log
-rw-r--r--. 1 root root    0 May 25 18:57 20170525_access.log
-rw-r--r--. 1 root root    0 May 25 18:57 access.log
-rw-r--r--. 1 root root 6083 May 25 18:57 error.log
-rw-r--r--. 1 root root    5 May 25 13:12 nginx.pid

 

 

 

 

    

 

Nginx 访问日志轮询切割

标签:access   cut   bash   nbsp   就会   日志   ash   div   不同的   

原文地址:http://www.cnblogs.com/pzk7788/p/6905473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!