cd /root
wget http://ncu.dl.sourceforge.net/project/awstats/AWStats/7.0/awstats-7.0.zip
unzip awstats-7.0.zip
mv /root/awstats-7.0 /usr/local/awstats
cd /usr/local/awstats/tools
./awstats_configure.pl
“-----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
#> none #因为我们这里用的是 Nginx,所以写 none,跳过。“
”
Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ?
#> y #y 创建一个新的统计配置"
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
#> www.google.com
. #统计网站的域名 例:
www.google.com
回车完成向导,接下来修改 www.google.com 的统计配置#vi /etc/awstats/awstats.www.google.com.conf
找到统计的日志文件的路径
LogFile="/var/log/httpd/mylog.log"
改为
LogFile="/home/wwwlogs/(date -d "yesterday" +"%Y")/$(date -d"yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log " 对应上边 Nginx 日志切割程序的所生成的目录存放结构,要注意 Awstats 的年月日格式的跟 Nginx 的写法有所不同。我们现在执行统计的顺序是:
Nginx 产生日志 –> 日志切割 –> Nginx 继续产生日志 –> 另存切割日志 –> 交由Awstats统计 –> 生成结果
在本文中 Awstats 所统计的日志,是已切下来的那部分。也能调转顺序,先统计完了再切。不过这比较容易造成统计的遗漏。配置修改完成后,保存退出。然后我们可以开始试一下手动执行。 /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=域名 ————————新建Awstat分析目录———————— mkdir /home/wwwroot/awstats /usr/local/awstats/tools/awstats_buildstaticpages.pl -update \-config=www.google.com -lang=cn -dir=/home/wwwroot/awstats \-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
上述命令的具体意思如下:
•/usr/local/awstats/tools/awstats_buildstaticpages.pl Awstats 静态页面生成工具•-update -config=www.google.com 更新配置项
•-lang=cn 语言为中文
•-dir=/data/admin_web/awstats 统计结果输出目录
•-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl Awstats 日志更新程序路径。
用浏览器查看到统计的详细结果 http://youhostname/awstats/awstats.www.google.com.html
至此,使用 awstats 已能完全支持 Nginx 的日志统计。
为了让整个日志的统计过程自动完成,我们需要设置 crontab 计划任务,让 Nginx 日志切割以及 Awstats 自动运行,定时生成结果页面。
#vi /etc/crontab
11 59 * * * /opt/nginx/sbin/logcron.sh #半夜11:59 进行日志切割
00 1 * * * /usr/local/awstats/tools/awstats_buildstaticpages.pl \
-update -config=www.google.com -lang=cn -dir=/data/admin_web/awstats \
-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
#凌晨00:01 Awstats进行日志分析
:wq保存退出
#crontab /etc/crontab 指定cron所执行的配置档路径