【AWStats】配置 Apache/Windows IIS 的日志分析工具

转自: http://hi.baidu.com/qu6zhi/blog/item/a66307bfc246440318d81f69.html

RHEL-5.3
===================================================================================
【简介】
奇码科技的美国空间是带有详细的统计流量工具 awstats,AWStats 是一套免费基于 Perl 的网站日志分析工具。这个工具界面较为友好,执行速度快,扩展功能众多,在国外空间使用 apache 服务器的,AWStats 是当之无愧的首选。

Awstats 是一个免费非常简洁而且强大有个性的 统计工具。 它可以统计您站点的如下信息:
① 访问量,访问次数,页面浏览量,点击数,数据流量等
② 精确到每月、每日、每小时的数据
③ 访问者国家
④ 访问者 IP
⑤ Robots/Spiders 的统计
⑥ 纺客持续时间
⑦ 对不同 Files type 的统计信息
⑧ Pages-URL 的统计
⑨ 访客操作系统浏览器等信息
其它信息(搜索关键字等等)

AWStats 是一个 免费的强大而有个性的工具,带来先进的 网络流量FTP邮件服务器 统计图。 本日志分析器作为 CGI 或从命令行在数个图形网页中显示你日志中包含的所有可能信息。 它利用一部分档案资料就能经常很快地处理大量日志档案,它能分析日志文件来自从各大服务器工具,如 Apache日志档案(NCSA combined/XLF/ELF log format or common/CLF log format), WebStar,IIS (W3C的日志格式)及许多其他网站,Proxy(代理服务器)、Wap、流量服务器、邮件服务器和一些 FTP 服务器。
看一看这个比较表在最著名统计工具(AWStats, Analog, Webalizer,...)之间有何特点和不同的想法.
AWStats 是一个在 GNU 通用公共许可证下发行的免费软件。你可以看看这个许可证图表而知道你可以/不可以做。
由于AWStats工程来自网上信息,但也作为CGI、 它可以与允许进入Perl,CGI与日志的大型网站主办提供商一起工作。
===================================================================================
【下载·安装】
打开页面: http://sourceforge.net/projects/awstats/
# wget http://jaist.dl.sourceforge.net/project/awstats/AWStats/6.9/awstats-6.9.tar.gz
也可下载
# wget http://jaist.dl.sourceforge.net/project/awstats/AWStats/6.9/awstats-6.9-1.noarch.rpm

# rpm -ivh awstats-6.9-1.noarch.rpm
Preparing...                ########################################### [100%]
1:awstats                   ########################################### [100%]

----- AWStats 6.9 - Laurent Destailleur -----
AWStats files have been installed in /usr/local/awstats

If first install, follow instructions in documentation
( /usr/local/awstats/docs/index.html) to setup AWStats in 3 steps:
Step 1 : Install and Setup with awstats_configure.pl (or manually)
Step 2 : Build/Update Statistics with awstats.pl
Step 3 : Read Statistics

# whereis awstats
awstats:
/usr/etc/awstats
/usr/local/awstats
===================================================================================
【配置 awstats】
awstats 要求将 http.conf 中的 CustomLog /yourlogpath/yourlogfile common 改为 CustomLog /yourlogpath/yourlogfile combined ,qu6zhi看了一下,qu6zhi默认的就是 combined,可能现在新版本默认的都是这个吧,那就不用改了。

再进入 /usr/local/awstats/tools 里,运行 ./awstats_configure.pl 启动安装向导,
# cd /usr/local/awstats/tools
# ./awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 1.8) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).

-----> Running OS detected: Linux, BSD or Unix

-----> 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):
> /etc/httpd/conf/httpd.conf

输入你 httpd.conf 的路径。对于 httpd2 系列的一般都在 /etc/httpd/conf/ 这个目录下面,这里将 awstats 的配置信息直接写入了 httpd.conf。

-----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
Add '<Directory>' directive
AWStats directives added to Apache config file.

-----> 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

-----> 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:
> qu6zhi.com

下面是要生成 conf 文件的名称了,因为 conf 文件的名称都是 awstats.yourdomainname.conf 格式的,所以这里要求你输入你要监测的域名,其实这个域名只是与其他域名相区分的,并不一定非要真实的。

-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>

这里是让你输入配置文件的路径,直接回车会执行默认的,当然你也可以自己定义。

-----> Create config file ' /etc/awstats/awstats.qu6zhi.com.conf'
Error: Failed to open ' /usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf' for read.

那是因为该路径找不到 awstats.model.conf 文件可以修改,而该文件所在的目录是 /usr/local/www/awstats/cgi-bin, 既然程序只读固定的路径,那就按照它要读取的路径进行相关设置,然后重新配置一次。

# cp /usr/etc/awstats/awstats.model.conf /usr/local/awstats/wwwroot/cgi-bin/
# ./awstats_configure.pl

-----> Create config file ' /etc/awstats/awstats.qu6zhi.com.conf'
Config file /etc/awstats/awstats.qu6zhi.com.conf created.

-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=qu6zhi.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...

A SIMPLE config file has been created: /etc/awstats/awstats.qu6zhi.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'qu6zhi.com' with command:
> perl awstats.pl -update -config=qu6zhi.com
You can also read your statistics for 'qu6zhi.com' with URL:
> http://localhost/awstats/awstats.pl?config=qu6zhi.com

Press ENTER to finish...
------------------------------------------------------------------------------------------------------------------------------------
更新数据
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl --update -config=qu6zhi.com
Error: AWStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable.
Setup ('/etc/awstats/awstats.qu6zhi.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).


对于 /var/lib/awstats 目录没有写入权限造成的

# chmod 777 /var/lib/awstats
chmod: cannot access `/var/lib/awstats': No such file or directory
# mkdir /var/lib/awstats
# chmod 777 /var/lib/awstats
更新数据
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl --update -config=qu6zhi.com
Create/Update database for config "/etc/awstats/awstats.qu6zhi.com.conf" by AWStats version 6.9 (build 1.925)
From data in log file "/var/log/httpd/mylog.log"...
Error: Couldn't open server log file "/var/log/httpd/mylog.log" : No such file or directory
Setup ('/etc/awstats/awstats.qu6zhi.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).


日志路径错位造成的
# vi /etc/awstats/awstats.qu6zhi.com.conf

LogFile="/var/log/httpd/mylog.log"
改成
LogFile="/var/log/httpd/ access_log "

更新数据
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl --update -config=qu6zhi.com
Create/Update database for config "/etc/awstats/awstats.qu6zhi.com.conf" by AWStats version 6.9 (build 1.925)
From data in log file " /var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 8
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 8 new qualified records.

# cp /usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf /etc/awstats/common.conf
# vi /etc/awstats/awstats.qu6zhi.com.conf

Include "common.conf"

#LogFile="/var/log/httpd/mylog.log"
LogFile="/var/log/httpd/access_log.%YYYY-24%MM-24%DD-24"
# %YYYY-24%MM-24%DD-24是指用24小时前的年月日日志文件名,如access_log.20061206
# LogFile="gzip -d < /qu6zhi.com/data/awstats/src/%YYYY-24/%MM-24/%DD-24.log.gz |"

SiteDomain="qu6zhi.com"
HostAliases="qu6zhi.com www.qu6zhi.com 127.0.0.1 localhost"
DefaultFile="index.html"
DirData="/var/lib/awstats"
DirData="/home/cgi-bin/awstats/data/"

添加定时分析指令
# crontab -e
20 1 * * *       /usr/local/awstats/wwwroot/cgi-bin/awstats.pl --update -config=qu6zhi.com
===================================================================================
【配置 apache】

# vi /etc/httpd/conf/httpd.conf
281 DocumentRoot "/var/www/html/ "
282 DocumentRoot "/usr/local/awstats/wwwroot"
这里将 awstats 的配置信息直接写入了 httpd.conf
*****************************************************************
Please add the following to your apache config, and restart.

#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses “/usr/local/www/awstats/classes/”
Alias /awstatscss “/usr/local/www/awstats/css/”
Alias /awstatsicons “/usr/local/www/awstats/icons/”
ScriptAlias /awstats/ “/usr/local/www/awstats/cgi-bin/”

#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>

*****************************************************************
对要分析的虚拟主机,将 CustomLog logs/access_xxx_log common 中的 common 改成 combined

从新启动apache
# service httpd restart
------------------------------------------------------------------------------------------------------------------------------------
用浏览器访问:http://server/awstats/awstats.pl?config=mysite

http://218.*.*.254/awstats/awstats.pl?config=qu6zhi.com
【AWStats】配置 Apache/Windows IIS 的日志分析工具 - banu - 入海数沙
The server encountered an internal error or misconfiguration and was unable to complete your request.
------------------------------------------------------------------------------------------------------------------------------------
当你的 web 程序出现上述错误后,很有可能是文件的权限设置的不对,linux 下文件单个文件需要设置为 755,当你设置的是 777就 会这样!
------------------------------------------------------------------------------------------------------------------------------------
SELinux 有提示
【AWStats】配置 Apache/Windows IIS 的日志分析工具 - banu - 入海数沙
【AWStats】配置 Apache/Windows IIS 的日志分析工具 - banu - 入海数沙
【AWStats】配置 Apache/Windows IIS 的日志分析工具 - banu - 入海数沙
【AWStats】配置 Apache/Windows IIS 的日志分析工具 - banu - 入海数沙

根据 SELinux 的提示,更改配置

# chcon -t httpd_sys_content_t '/usr/local/awstats/wwwroot/cgi-bin/awstats.pl'
===================================================================================
用浏览器再次访问: http://218.241.143.254/awstats/awstats.pl?config=qu6zhi.com
【AWStats】配置 Apache/Windows IIS 的日志分析工具 - banu - 入海数沙
===================================================================================
把图标等文件目录复制到 WEB 的 HTML 文件发布目录下,例如:/home/apache/htdocs/ 下发布更多的批量更新脚本等在 tools 目录下,可以一并放到 cgi-bin/awstats/ 目录下升级国内主要搜索引擎和蜘蛛定义,安装 GeoIP 的应用库:C
http://www.maxmind.com/download/geoip/api/c/ 解包,编译安装
perl -MCPAN -e 'install "Geo::IP"' 或者使用纯 Perl 包  perl -MCPAN -e 'install "Geo::IP::PurePerl"'
下载 GeoIP/GeoIPCityLite 包:解包并部署到 awstats 目录下:
# wget  http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
# wget  http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

将缺省 awstats.model.conf 命名成 common.conf
修改其中的一些配置选项:
LoadPlugin="decodeutfkeys"
LoadPlugin="geoip GEOIP_STANDARD /home/apache/chedong.com/cgi-bin/awstats/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /home/apache/chedong.com/cgi-bin/awstats/GeoLiteCity.dat"

创建 awstats下创建:data 目录用于统计数据输出,缺省的统计输出是按月汇总的;对于日志非常大的最好选择按天统计输出,并修改awstats.pl: 设置LIMITFLUSH加10倍;
$LIMITFLUSH =
50000;   # Nb of records in data arrays after how we need to flush data on disk
可以有效提高统计的速度(减少磁盘IO),并避免按月汇总数据导致的统计文件过大;

按照一下样例设置配置文件:
Include "common.conf"
LogFile="/home/apache/logs/access_log.%YYYY-24%MM-24%DD-24"
SiteDomain="www.chedong.com"
HostAliases="chedong.com"
DefaultFile="index.html"
DirData="/home/apache/cgi-bin/awstats/data/"
------------------------------------------------------------------------------------------------------------------------------------
内容摘要:
AWStats 的使用简介和配置一些改进说明。很高兴看到在 AWStats 6.3 版本开始:中文用户基本上已经只需要将配置文件中将 LoadPlugin="decodeutfkeys" 启用基本上就没有什么中文搜索引擎的统计问题了,目前增加了多个国内主要搜索引擎厂商。包含了针对国内主要搜索引擎和蜘蛛定义的补丁(解包后覆盖 lib\ 目录下的原程序目录即可),其中也包含了本站的样例配置文件

日志统计系统在站点的用户行为分析中扮演了重要的角色,尤其是对于来自搜索引擎的关键词访问统计:是很有效的用户行为分析数据来源。随着互联网多年的发 展,WEB日志统计工具已经越来越成熟,功能也越来越丰富。其中有很多是开放源代码的, AWStats 就是其中非常优秀的一款。
AWStats: Advanced Web Statistics

AWStats 是在Sourceforge上发展很快的一个基于 Perl 的 WEB 日志分析工具。相对于另外一个非常优秀的开放源代码的日志分析工具Webalizer,AWStats的优势在于:

1. 界面友好:可以根据浏览器直接调用相应语言界面(有简体中文版)
参考输出样例:http://www.chedong.com/cgi-bin/awstats/awstats.pl?config=chedong
2. 基于 Perl:并且很好的解决了跨平台问题,系统本身可以运行在 GNU/Linux上或 Windows 上(安装了ActivePerl后);分析的日志直接支持Apache格式 (combined)和IIS格式(需要修改)。Webalizer虽然也有Windows 平台版,但目前已经缺乏维护;
AWStats 完全可以实现用一套系统完成对自身站点不同WEB服务器:GNU/Linux/Apache和Windows/IIS服务器的统一统计。
3. 效率比较高:AWStats 输出统计项目比Webalizer丰富了很多,速度仍可以达到 Webalizer 的1/3左右,对于一个日访问量百万级的站点,这个速度都是足够的;
4. 配置/定制方便:系统提供了足够灵活但缺省也很合理的配置规则,需要修改的缺省配置不超过3,4项就可以开始运行,而且修改和扩展的插件还是 比较多的;
5. AWStats 的设计者是面向精确的"Human visits"设计的,因此很多搜索引擎的机器人访问都被过滤掉了,因此有可能比其他日志统计工具统计的数字要低,来自公司内部的访问也可以通过 IP 过滤 设置过滤掉。
6. 提供了很多扩展的参数统计功能:使用 ExtraXXXX 系列配置生成针对具体应用的参数分析会对产品分析非常有用。

更多与其他工具:Webalizer, analog 的比较请参考:
http://awstats.sourceforge.net/#COMPARISON
------------------------------------------------------------------------------------------------------------------------------------
AWStats 安装备忘

AWStats 的运行模式是这样的:

1. 分析日志:运行后将这样的日志统计结果归档到一个 AWStats 的数据库(纯文本)里;
2. 然后是输出:分两种形式
* 一种是通过 cgi 程序读取统计结果数据库输出;
* 一种是运行后台脚本将输出导出成静态文件;

以下是2个针对单个站点日志统计例子:
一个是在 GNU/Linux 上通过 CGI 方式的输出,
一个是在 Windows 2000 上的基于静态页面的导出

下载/安装
http://sourceforge.net/projects/awstats/ 下载安装包后:

GNU/Linux:tar zxf awstats-version.tgz
awstats 的脚本和静态文件缺省都在 wwwroot 目录下: 将 cgi-bin 目录下的文件都部署 awstats.pl 程序到/home/apache/cgi-bin/awstats/ 下
mv awstats-version/wwwroot/cgi-bin /path/to/apache/cgi-bin/awstats
#把图标等文件目录复制到WEB的HTML文件发布目录下:/home/apache/htdocs/ 下发布
更多的批量更新脚本等在 tools 目录下,可以一并放到 cgi-bin/awstats/ 目录下,

Windows 2000:按照后台脚本模式运行,直接解包,然后移动到 D:\AWStats 目录下
把图标 icon 目录复制到IIS的发布目录下:inetpub/icon

数据源日志格式和按天的截断规则

1. 对于 Apache:日志格式好设置:设置成 combined 格式即可,日志截断麻烦一点:需要安装 cronolog 工具,将日志设置成按天截断:
CustomLog "|/usr/local/sbin/cronolog /path/to/apache/logs/access_log.%Y%m%d" combined
比如:logs/access_log.20030326
日志是压缩格式,可以使用gzip -d < /home/apache/logs/access_log.%YYYY-24%MM-24%DD-24.gz | 动态解压缩统计。
2. 对于 IIS:缺省有比较好的日志按天截断规则,但是 IIS 的日志格式比较不适合 AWStats 统计,
因此最好直接去掉所有日志字段,然后严格按照以下列表设置
* 日期 date
* 时间 time
* 客户IP地址 c-ip
* 用户名 cs-username
* 方法 cs-method
* URI资源 cs-uri-stem
* 协议状态 sc-status
* 发送字节数 sc-bytes
* 协议版本 cs-version
* 用户代理 cs(User-Agent)
* 参照 cs(Referer)
相比IIS缺省设置:
减少的有:
* 服务器IP地址
* 服务器端口
* URI查询
增加的有:
* 发送字节数
* 协议版本
* 参照

配置文件的命名规则:awstats.sitename.conf

AWStats的主程序 awstats.pl 会自动根据站点名调用相应站点的配置文件:awstats.sitename.conf
比如:运行./awstats.pl -config=chedong 调用的就是同目录下的 awstats.chedong.conf 配置文件;
如果没有指定 -config,还会找当前目录下的 awstats.conf 或者/etc/awstats.conf作为缺省配置文件。
所以最好把缺省的 awstats.model.conf 重命名成 awstats.yoursite.conf;比如:awstats.chedong.conf,

对于多个站点的统计,AWStats 的配置文件包含功能还是非常有用的,我们可以把通用的配置放在一个文档中,然后用(5.4版本以后开始支持) Include 配置将通用配置包含在各个具体配置文件的头部,然后用其他配置覆盖通用配置中的相应属性,比如:
Include="common.conf"
LogFile="/path/to/bbs/access_log"
SiteName="bbs.chedong.com"
最少的配置文件修改:LogFile SiteDomain LogFormat

对于在 GNU/Linux 上统计 Apache 日志只需修改:LogFile SiteDomain 这2个选项

1. GNU/Linux LogFile="/path/to/apache/logs/access_log.%YYYY-24%MM-24%DD-24"
Windows 2000 LogFile="d:\iis_logs\W3SV3\ex%YY-24%MM-24%DD-24.log"
这个配置的意思是用24小时前的年份,月份,日期拼出的日志文件名;
2. SiteDomain="www.chedong.com"
站点的名称,缺省是空的,如果为空,AWStats 将拒绝运行;
3. 对于统计 IIS 日志需要多修改一个:
LogFormat=2
缺省值是1:Apache日志,2是IIS日志

其他需要注意的事项:
AWStats 缺省不过滤 swf 文件,会把.swf算成 PageView,所以如果站点上 swf 文件主要是广告的话最好还是要过滤掉:

日志分析
./awstats.pl -update -config=sitename -lang=cn
比如:./awstats.pl -update -config=chedong
会自动调用 awstats.chedong.conf 这个配置文件
统计输出

GNU/Linux    http://localhost/cgi-bin/awstats/awstats.pl?config=chedong
Windows 2000 http://localhost/awstats/awstats.chedong.html
日志统计自动运行

GNU/Linux上:crontab -e: 每天8点10分运行
#update awstats
10 8 * * * (cd /path/to/apache/cgi-bin/awstats/; ./awstats.pl -update -config=chedong)

Windows 2000上:设置每天8点10分运行
D:\Perl\bin\perl.exe d:\AWStats\tools\awstats_buildstaticpages.pl -update -config=chedong -lang=cn -dir=c:\inetpub\awstats\ -awstatsprog=d:\awstats\wwwroot\cgi-bin\awstats.pl
多站点日志统计

AWStats 自带了一个批处理工具:tools/awstats_updateall.pl,可以批量地遍历一个目录下所有地配置文件并运行统计。因此剩下的工作就主 要是日志的同步问题了。

针对多个站点,很多配置选项是重复的,如果每个配置文件都修改维护起来会很麻烦,AWStats 从5.4版本开始提供了配置文件包含的功能,所以我们可 以配置一个通用配置,比如:common.conf

然后其他站点的配置设置为:可以通过后面的选项覆盖和缺省不一致的配置。
awstats.bbs.chedong.conf
Include "chedong.common.conf"
LogFile "/path/to/bbs_log"
SiteName "bbs.chedong.com"

awstats.www.chedong.conf
Include "chedong.common.conf"
LogFile "/path/to/www_log"
SiteName "www.chedong.com"
HostAliases="chedong.com"
统计指标说明

* 参观者:按来访者不重复的IP统计,一个IP代表一个参观者;
* 参观次数:一个参观者可能1天之内参观多次(比如:上午一次,下午一次),所以按一定时间内(比如:1个小时),不重复的IP数统计,参观者 的访问次数;
* 网页数:不包括图片,CSS, JavaScript文件等的纯页面访问总数,但如果一个页面使用了多个帧,每个帧都算一个页面请求;
* 文件数:来自浏览器客户端的文件请求总数,包括图片,CSS,JavaScript等,用户请求一个页面是,如果页面中包含图片等,所以对服 务器会发出多次文件请求,文件数一般远远大于文件数;
* 字节:传给客户端的数据总流量;
* 来自REFERER中的数据:日志中的参考(REFERER)字段,记录了访问相应网页之前地址,因此如果用户是通过搜索引擎的搜索结果点击 进入网站的,日志中就会有用户在相应搜索引擎的查询地址,这个地址中就可以通过解析将用户查询使用的关键词提取出来:
比如:
2003-03-26 15:43:58 123.123.123.123 - GET /index.html 200 192 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0) http://www.google.com/search?q=chedong
AWStats 在搜索引擎的关键短语和关键词统计方面的功能还是比较完整的:可以对全世界3百多种机器爬虫进行识别,并且可以识别大部分主流国际化搜索引擎和很多地区的 本地语言搜索引擎。

Hacking AWStats
基于地理信息的插件安装:

GeoIP 和 Geo::IPfree(awstats 5.5+)
GeoIP和Geo::IPfree都免费的是国家/IP的影射表,比通过DNS反相解析域名得到的统计准确,而且速度快。GeoIP的API都是免费 的,缺省库是免 费的,收费的是它的数据更新服务。Geo::IPfree不仅代码是公开的,而且库数据也是公开的。

GeoIP 安装:
先下载 C 库:GeoIP C解包后
%./configure; make
#make install

然后下载 Perl 库:GeoIP Perl 解包后
%perl MakeFile.PL; make
#make install

Geo::IPfree安装:
下载Geo::IPfree解 包后
%perl Makefile
%make
#make install

配置:通过在配置文件中启用 GEOIP 相关插件:

LoadPlugin="geoip GEOIP_STANDARD /home/apache/chedong.com/cgi-bin/awstats/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /home/apache/chedong.com/cgi-bin/awstats/GeoLiteCity.dat"

MaxMind 目前免费提供了 GeoIP 和 GeoIPCityLite 数据包:可以定期每个月从以下地址下载:

wget  http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget  http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

从最近的统计来看一般为每月3日更新,此外:http://geolite.maxmind.com/download/geoip/database/ 下也有 CSV  源文件提供;此外:利用 QQ 的纯真库也能获得更详细的地理信息分布统计;
===================================================================================
安装完毕后会有一段提示

*****************************************************************
Please add the following to your apache config, and restart.

#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses “/usr/local/www/awstats/classes/”
Alias /awstatscss “/usr/local/www/awstats/css/”
Alias /awstatsicons “/usr/local/www/awstats/icons/”
ScriptAlias /awstats/ “/usr/local/www/awstats/cgi-bin/”

#
# This is to permit URL access to scripts/files in AWStats directory.
#

Options None
AllowOverride None
Order allow,deny
Allow from all


*****************************************************************

If you are upgrading from AWStats 6.4 or older, please note the following:

If you used the geoip plugin, you must edit your AWStats config file
to change the line
LoadPlugin=”geoip GEOIP_STANDARD”
into
LoadPlugin=”geoip GEOIP_STANDARD /pathto/GeoIP.dat”

*****************************************************************
===> Registering installation for awstats-6.6_1,1


这里是让你输入配置文件的路径,直接回车会执行默认的,当然你也可以自己定义

剩下的工作我们就需要手工完成了。

第一, 在 crontab 里手工加进去
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.youdomains.com,因为这个程序是通过分析日志来进行流量统计的,如果你的日志文件很大的话是很耗系统资源的。还 好,我的流量不大,我设定的是每个小时运行一次,你如果服务器比较繁忙的话也可以每天夜里运行一次。当然你也可以手工运行上面的命令来进行更新统计信息。

第二,conf文件的配置:

LogFile
指定你要分析的日志文件,默认是 /var/log/httpd/mylog.log,可以根据你的需要调整,如果你要分析 httpd 的全部日志的就是 /var/log/httpd/access_log,我们一般就选这个了。

LogType
log 类型,默认是 web log,不用修改,如果你不是的话就自己照说明改了。

LogFormat
log 格式,一般情况下如果是 apache 的话就是1,iis就是2,默认不用修改,你也可以照说明自定义,呵呵,我还不太清楚怎么定义。

LogSeparator
log 中的分隔符,默认不用修改,如果上面的格式是你自定义的话这里也要修改了

DNSLookup
默认不用修改

DirData
生成的日志分析结果的保存路径,默认是 /var/lib/awstats,你如果要使用默认的路径的话,这个目录是需要手工创建的,注意这个路径必须是可读写的。
下面四项都是在配置时,不用修改。

DirCgi cgi 的路径,这里都是相对于网站根目录的绝对路径
DirIcons icon的路径
SiteDomain 域名:www.youdomains.com
HostAliases 主机别名

AllowToUpdateStatsFromBrowser
下面这项是是否允许从浏览器里更新统计文件,默认是0不允许,如果我们改为1的话,就需要 apache 的属主用户对 /var/lib/awstats 目录有读写权限,并对 /var/log/httpd 目录有读取权限

AllowFullYearView

这个不用修改默认值。awstats 默认是以月为单位进行日志分析,如果我们要分析整年的日志的可以在这里设置,因为分析整年的日志的话可能要消耗很多系统资源。如果你需要对年日志进行分析 的话,建议手工启动。

这样最基本的配置就完成了,我们可以通过http://www.youdomains.com/awstats /awstats.pl?config=www.youdomains.com 来查看统计信息。

常见问题:
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.bestunix.net
Error: AWStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable.
Setup ('/etc/awstats/awstats.www.youdomains.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).

这个是因为在/etc/awstats/awstats.www.youdomains.com.conf中DirData中定义的目录启动apache 的用户没有写得权限,更改目录或更改权限都可以解决。
问题二,出来的页面里所有的流量统计都是空的。
同样是 /etc/awstats/awstats.www.youdomains.com.conf 的问题,在这个文件里有一行
LogFile=”/var/log/httpd/mylog.log”
我们一般情况下把这个路径改为”/var/log/apache/access.log”就可以了,如果你设了很多虚拟主机,每个主机都配置了不同的 log的话,在这里指定你要统计的那个主机的log文件就可以了。
问题三,浏览页面时提示没有权限,出现403错误,给上wwwroot目录权限755就OK了

注:默认的awstats目录结构里并没有 wwwroot。可以自己加上去。
===================================================================================
附: 其它说明

++按天统计
perl awstats.pl -config=www.my_site.com -update -databasebreak=day
http://www.internetofficer.com/cgi-bin/awstats.pl?config=blog.zhangjianfeng.com&databasebreak=day&day=22&month=12&year=2008

++不统计指定IP的访问量
SkipHosts=”x.x.x.x.”

++不统计指定URL
SkipFiles=”/badpage.php /page.php?param=x REGEX[^\/excludedirectory]”

#数据源日志格式和按天的截断规则
对于Apache:日志格式好设置:设置成combined格式即可,日志截断麻烦一点:需要安装cronolog工具,
将日志设置成按天截断:
CustomLog “|/usr/local/sbin/cronolog /path/to/apache/logs/access_log.%Y%m%d” combined 比如:logs/access_log.20061126
日志是压缩格式,可以使用gzip -d < /home/apache/logs/access_log.%YYYY-24%MM-24%DD-24.gz | 动态解压缩统计。

#多站点日志统计
AWStats自带了一个批处理工具:tools/awstats_updateall.pl,可以批量地遍历一个目录下所有地配置文件并运行统计。针对 多个站点,很多配置选项是重复的,如果每个配置文件都修改维护起来会很麻烦,所以我们可 以配置一个通用配置,比如:common.conf
然后其他站点的配置设置可以通过后面的选项覆盖和缺省不一致的配置。
awstats.blog.zhangjianfeng.com.conf
Include “common.conf”
LogFile “/path/to/access_log”
SiteName “blog.zhangjianfeng.com”
HostAliases=”zhangjianfeng.com”

#统计指标说明
参观者:按来访者不重复的IP统计,一个IP代表一个参观者;
参观次数:一个参观者可能1天之内参观多次(比如:上午一次,下午一次),所以按一定时间内(比如:1个小时),不重复的IP数统计,参观者 的访问次数;
网页数:不包括图片,CSS, JavaScript文件等的纯页面访问总数,但如果一个页面使用了多个帧,每个帧都算一个页面请求;
文件数:来自浏览器客户端的文件请求总数,包括图片,CSS,JavaScript等,用户请求一个页面是,如果页面中包含图片等,所以对服 务器会发出多次文件请求,文件数一般远远大于文件数;
字节:传给客户端的数据总流量;
来自REFERER中的数据:日志中的参考(REFERER)字段,记录了访问相应网页之前地址,因此如果用户是通过搜索引擎的搜索结果点击 进入网站的,日志中就会有用户在相应搜索引擎的查询地址,这个地址中就可以通过解析将用户查询使用的关键词提取出来:

##plugin

安装GeoIP
先下载安装C库:下载地址:http://www.maxmind.com/download/geoip/api/c/
# ./configure && make && make install
然后下载Perl库:下载地址:http://www.maxmind.com/download/geoip/api/perl/
# perl MakeFile.PL && make && make install
# 然后
# perl -MCPAN -e ‘install “Geo::IP”‘
# perl -MCPAN -e ‘install “Geo::IPfree”‘

更新GeoIP库
wget http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
# 将上面的文件解压后,放至/usr/local/share/GeoIP/
#定时更新GeoIP库
#0 0 * * * root /usr/local/bin/geoipupdate -v

修改/usr/local/etc/awstats/awstats.www.test.com.conf,取消下面这行的注释,启用此插件
LoadPlugin=”decodeutfkeys”
LoadPlugin=”hashfiles”
LoadPlugin=”geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoLiteCity.dat”

安装XWhois
# perl -MCPAN -e shell
cpan> install Net::XWhois
修改/usr/local/etc/awstats/awstats.www.test.com.conf,取消下面这行的注释,启用此插件
LoadPlugin=”hostinfo”

安装decodeutfkeys,解决搜索搜索关键词乱码问题(不管是utf8,gb2312…)
# perl -MCPAN -e shell
cpan> install URI::Escape
修改/usr/local/etc/awstats/awstats.www.test.com.conf,取消下面这行的注释,启用此插件
LoadPlugin=”decodeutfkeys”

更新日志
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=blog.zhangjianfeng.com -update -lang=cn

++仅统计分析指定URL
OnlyFiles=”REGEX[/abc/abc]” #URL中包括/abc/abc/,如/abc/abc/xxxx

++Update statistics when I use a load balancing system that splits my logs?
LogFile=”/pathto/logresolvemerge.pl file*.log |” #在配置文件中指定
logresolvemerge.pl file1.log file2.log … filen.log > newfiletoprocess.log #先用工具把所有LOG合并,再配置LogFile

++多台缓存服务器的日志合并处理
多服务器的日志合并统计 http://blog.zhangjianfeng.com/article/522

++如果调用月度速度很慢的时候,可以考虑把输出文件静态化
$path/awstats/tools/awstats_buildstaticpages.pl -update -config=blog.zhangjianfeng.com -lang=cn -dir=$path/data/www/mgr1/test/awstats/blog.zhangjianfeng.com/ -awstatsprog=$path/app/tools/awstats/wwwroot/cgi-bin/awstats.pl -DatabaseBreak=month
#-month=mm 使用月份的两位数
#-builddate=%04%02%01% 以某一日期为文件名输出页面

++提高些处理速度(unique url reach flush limit of 5000)
在awstats.pl中修改. 默认值是5000,如果内存较大,可以适当加大,比如50000
===================================================================================
参考:
http://www.chedong.com/tech/awstats.html
http://baike.baidu.com/view/228748.htm
http://blog.chinaunix.net/u2/71666/showart_1988397.html
http://blog.zhangjianfeng.com/article/317

AWStats开源项目: http://awstats.sourceforge.net/
Webalizer开源项目:http://www.webalizer.org/
日志分析工具:directory.google.com/Top/Computers/Software/Internet /Site_Management/Log_Analysis/
商业日志统计/分析工具: directory.google.com/Top/Computers/Software/Internet/Site_Managemen/Log_Analysis/Commercial/
多站点的日志合并:www.chedong.com/tech/rotate_merge_log.html
日志统计对于分析搜索引擎对站点的影响具 有非常重要的意义:www.chedong.com/tech/google.html
AWStats插件说明:awstats.sourceforge.net/awstats_contrib.html

感谢:
孙国光
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卷边书_王诣

您的鼓励,是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值