安装日志分析工具awstats

之前用Google Analytics分析网站,觉得多一次请求,对用户不太好,于是自己分析统计apache log。大约花了一个小时安装测试awstats,比预期的要顺利。

服务器是fedora,用yum安装很快。
[root@athena~]# yum install awstats

用默认的安装方法,/etc/httpd/conf.d/ 目录下面已经有了awstats.conf,如果没有,复制一个过去
# cp /usr/share/awstats/tools/httpd_conf /etc/httpd/conf.d/awstats.conf

编辑 /etc/httpd/conf.d/awstats.conf文件,默认的是:

<Directory "/usr/share/awstats/wwwroot">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from 127.0.0.1
</Directory>

如果是外面的服务器,将 127.0.0.1改为 all

[root@athena~]# cp /etc/awstats/awstats.module.conf /etc/awstats/awstats.broncho.cn.conf
编辑/etc/awstats/awstats.broncho.cn.conf, 修改下面三项即可:
SiteDomain="broncho.cn"
LogFile="/var/log/httpd/broncho.cn_access_log.%YYYY-0%MM-0%DD-0"
Lang="cn"

[root@athena~]# cd /usr/share/awstats/wwwroot/cgi-bin
[root@athena cgi-bin]# ./awstats.pl -update -config=broncho.cn

发现:

Create/Update database for config “/etc/awstats/awstats.broncho.cn.conf” by AWStats version 6.8 (build 1.910)
From data in log file “/var/log/httpd/broncho.cn_access_log.20100927″…
Phase 1 : First bypass old records, searching new record…
Searching new records from beginning of log file…
AWStats did not find any valid log lines that match your LogFormat parameter, in the 50th first non commented lines read of your log.
Your log file /var/log/httpd/broncho.cn_access_log.20100927 must have a bad format or LogFormat parameter setup does not match this format.
Your AWStats LogFormat parameter is:1
This means each line in your web server log file need to have “combined log format” like this:
111.22.33.44 – – [10/Jan/2001:02:14:14 +0200] “GET / HTTP/1.1” 200 1234 “http://www.fromserver.com/from.htm” “Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)”
And this is an example of records AWStats found in your log file (the record number 50 in your log):
113.227.9.179 – – [27/Sep/2010:10:34:49 +0800] “GET /forum/styles/prosilver_se/theme/images/border_right.gif HTTP/1.1” 200 124
Setup (‘/etc/awstats/awstats.broncho.cn.conf’ file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in ‘docs’ directory).

原来的日志按天分割的:

CustomLog “|/usr/local/sbin/cronolog /var/log/httpd/broncho.cn_access_log.%Y%m%d” common

按错误提示,修改为:

CustomLog "|/usr/local/sbin/cronolog /var/log/httpd/broncho.cn_access_log.%Y%m%d" combined

浏览 http://192.168.1.222/awstats/awstats.pl?config=broncho.cn 就可以看到效果。

定时分析日志,在服务器负载比较低的时候,一般是凌晨3,4点。

[root@athena~]# vim /usr/share/awstats/wwwroot/cgi-bin/awstats.sh

#!/bin/bash

cd /usr/share/awstats/wwwroot/cgi-bin
perl awstats.pl -update -config=broncho.cn

[root@athena~]# chmod 755 /usr/share/awstats/wwwroot/cgi-bin/awstats.sh

[root@athena~]# crontab -e
0 3 * * * /usr/share/awstats/wwwroot/cgi-bin/awstats.sh

If you enjoyed this post, make sure you subscribe to my RSS feed!

One thought on “安装日志分析工具awstats

  1. sell this domain at sedo

    This is my first time visiting your site. I do envy you since you seem to get a lot more comments then I do. Do you have any secret tips on how I can get more comments or do I just have to be paitent? Anyway, keep up the good work.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *