您的位置:首页 > 运维架构 > Nginx

awstats 统计     nginx日志切割

2013-07-31 16:39 423 查看
1、nginx
cut_nginx_logs.sh

(在lnmp一键安装中有这个脚本,直接拿来用就行了)

#!/bin/bash
#function:cut nginx log files for lnmp v0.5 and v0.6
#author: http://lnmp.org
#set the path to nginx log files
log_files_path="/var/www/wwwlogs/"
log_files_dir=${log_files_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")
#set nginx log files you want to cut
log_files_name=(access)
#set the path to nginx.
nginx_sbin="/usr/local/nginx/sbin/nginx"
#Set how long you want to save
#save_days=30

############################################
#Please do not modify the following script #
############################################
mkdir -p $log_files_dir

log_files_num=${#log_files_name[@]}

#cut nginx log files
for((i=0;i<$log_files_num;i++));do
mv ${log_files_path}${log_files_name[i]}.log ${log_files_dir}/${log_files_name[i]}_$(date -d "yesterday" +"%Y%m%d").log
done

#delete 30 days ago nginx log files
#find $log_files_path -mtime +$save_days -exec rm -rf {} \;

$nginx_sbin -s reload

自动切割nginx access日志并存放到以年 月命名的文件夹中,也可以设置自动删除30天以前的日志。
#crontab -e
0 0 * * * /usr/local/nginx/cut_nginx_logs.sh

2、awstats
修改awstats配置文件的nginx日志目录
LogFile="/var/www/wwwlogs/%YYYY-24/%MM-24/access_%YYYY-24%MM-24%DD-24.log"
#crontab -e
10 0 * * * /var/www/awstats/tools/awstats_buildstaticpages.pl -update -config=cacti -lang=cn -dir=/var/www/awstats/html -awstatsprog=/var/www/awstats/wwwroot/cgi-bin/awstats.pl
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx 日志切割