|
由于需要,需要在一台windows服务器上安装日志统计工具,自然而然的就想到了awstats。
以前有做过在linux下配置awstats,这次再试试windows的。。。
首先需要下载几个工具,当然都是运行在windows平台的。
perl5
cronolog
awstats
下载地址分别为:
perl5: www.activestate.com/activeperl/
cronolog: cronolog.org/download/index.html
awstats: awstats.sourceforge.net/#DOWNLOAD
好,先安装perl5,然后从cronolog的压缩包中把cronolog.exe提取出来,
解压缩awstats压缩包,放到你想要的目录中留待备用。
假设目录结构如下:
D:/
awstats/
per5/
bin/
perl.exe
cronolog/
cronolog.exe
awstats-6.9/
wwwroot/
js/
icon/
css/
classes/
cgi-bin/
tools/
docs/
README.TXT
———-
现在先来修改apache的配置文件。
这里需要在配置文件末尾增加如下代码(让apache可以访问到awstats的目录):
Alias /awstatsclasses “D:/awstats/awstats-6.9/wwwroot/classes/”
Alias /awstatscss “D:/awstats/awstats-6.9/wwwroot/css/”
Alias /awstatsicons “D:/awstats/awstats-6.9/wwwroot/icon/”
ScriptAlias /awstats/ “D:/awstats/awstats-6.9/wwwroot/cgi-bin/”
#
# This is to permit URL access to scripts/files in AWStats directory.
#
Options None
AllowOverride None
Order allow,deny
Allow from all
再来加一行,设置记录日志格式的,假设日志记录在D:/Logs/httpd
LogFormat “%h %l %u %t /”%r/” %>s %b /”%{Referer}i/” /”%{User-Agent}i/”" combined
LogFormat “%h %l %u %t /”%r/” %>s %b” common
CustomLog “|D:/awstats/cronolog/cronolog.exe D:/Logs/httpd/access_awstats.%Y%m%d” combined
注:如果有虚拟站点,放在虚拟站点里配置比较合理
好了,apache的配置文件搞好了,重启apache,就可以让你的设置生效,接下来在log目录下就可以看到记录了,
接下来进行awstats的配置文件
———-
进入到:D:/awstats/awstats-6.9/wwwroot/cgi-bin 目录。
找到默认的awstats.model.conf文件,复制出来两份到当前目录,一份取名为:
common.conf,另一份取名为:awstats.www.domain.com.conf,具体的名字根据你的域名更改吧。
common.conf不用去管,打开awstats.www.domain.com.conf,把里面的内容清空,换成如下内容:
#包含通用的配置文件
Include “common.conf”
#按日期时间分割的日志文件的位置
LogFile=”D:/Logs/httpd/access_awstats.%YYYY-24%MM-24%DD-24.txt”
#记录日志文件的类型,这个如果是apache的话不用修改
LogType=W
#记录日志文件的类型,这个如果是apache,LogFormat是combined的话不用修改
LogFormat=1
#日志每条记录每列的分隔符,一般不用修改
LogSeparator=” ”
#记录日志的域名
SiteDomain=”www.domain.com”
#主机别名
HostAliases=”127.0.0.1″
#存放分析日志结果的目录,这个目录一定要存在
DirData=”./data”
#cgi-bin目录,这个一般不用修改
DirCgi=”/cgi-bin”
#icon图标存在的目录,这个需要修改成/awstatsicons
DirIcons=”/awstatsicons”
———-
好了,进行完如上配置,可以开始测试了,先用命令行方式,进入到D:/awstats/awstats-6.9/wwwroot/cgi-bin目录,
然后执行:
D:/awstats/perl5/bin/perl.exe awstats.pl -config=www.domain.com,不出意外的话,会显示出如下信息:
Create/Update database for config “./awstats.www.domain.com.conf” by AWStats ver
sion 6.9 (build 1.925)
From data in log file “D:/Logs/httpd/access_awstats.20090907.txt”…
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: 4896
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 4896 new qualified records.
接下来就该考虑如何用web方式来显示了,
cgi-bin目录下有两个pl文件,分别为,awredir.pl,awstats.pl
将这两个文件打开,把第一行的:#!/usr/bin/perl都修改成:#!D:/awstats/perl5/bin/perl.exe
然后打开web浏览器,输入: www.domain.com/awstats/awstats.pl?config=www.domain.com
或者:http://127.0.0.1/awstats/awstats.pl?config=www.domain.com
127.0.0.1替换成你的服务器ip,就可以看到awstats的统计界面了。。。
———-
接下来给awstats加一个需要用户名才可以访问的功能。
将刚才的awstats.www.domain.com.conf文件打开,添加如下两行
AllowAccessFromWebToAuthenticatedUsersOnly=1
AllowAccessFromWebToFollowingAuthenticatedUsers=”yourAuthUserName”
然后使用apache的http验证机制,进入到你的apache安装的bin目录下,执行:
htpasswd.exe -c .authPasswd yourAuthUserName
接下来按照命令行提示,输入两次密码,就会出现了一个.authPasswd文件了,
将这个生成的文件移动到你想要放的位置,并且在上面的……
中增加如下内容
AuthType Basic
AuthName “auth”
AuthUserFile D:/awstats/awstats-6.9/wwwroot/cgi-bin/.authPasswd
Require valid-user require
其中AuthUserFile要改成你相应的密码文件位置。
重启apache,再次访问刚才的网址,就会让你输入你设置好的用户名和密码了。
———-
再接下来,给awstats增加一个显示来访IP归属地的功能。
这里有两个解决方案,一个是采用Geo-IP,另外一个是采用QQWry.Dat
我这里采用的是后者,
先来下载三个东西:
www.ieasy.org/download/qqhostinfo.pm
这个是显示来访IP归属地的插件,下载后放到cgi-bin/plugins目录中
www.ieasy.org/download/qqwry.pl
这个是分析QQWry.Dat的perl脚本,放在同一目录。
QQWry.Dat 这个从网上搜索下下载吧,是IP归属地的地址库,一搜一大堆。
好了,上面的工作做完了,接着来修改配置文件,在最后继续增加如下内容:
LoadPlugin=”qqhostinfo”
———-
BUT!!!运行后效果并不好,所以还是老老实实的采用GEO-IP吧,哈哈。。。
先进入到perl5的bin目录: D:/awstats/perl5/bin
然后执行如下命令:
ppm install Geo::IP::PurePerl
ppm install Geography::Countries
ppm install IP::Country
ppm install Geo-IPfree
ppm install Net-Xwhois
再下载个GeoIP.dat
www.big-cat.cn/wp-content/uploads/2008/05/GeoIP.dat
如果下载链接失效,也是网上搜索一下儿下载吧。
下载好后放到cgi-bin目录
好,接下来打开插件
# 开启 GeoIP 反查模块
LoadPlugin=”geoip GEOIP_STANDARD D:/awstats/awstats-6.9/wwwroot/cgi-bin/ipdata/GeoIP.dat”
# 开启 IP 反查的外挂
LoadPlugin=”geoipfree”
# 开启 decodeutfkeys 外挂,解决”用以搜索的关键词”乱码
LoadPlugin=”decodeutfkeys”
现在把刚才生成的data目录下的数据文件删除掉,使用
D:/awstats/perl5/bin/perl.exe awstats.pl -config=www.domain.com
命令重新生成,这个时候儿,出现了如下错误:
Error: Conflict between plugin ‘geoipfree’ and ‘geoip’. They both implements the ‘must be unique’ function ‘GetCountryCodeByAddr’.
是说这两个插件产生了冲突,所以我把LoadPlugin=”geoipfree”这样给注释掉了
#LoadPlugin=”geoipfree”
———-
最后,再使用bat批处理+计划任务,设置成每天0点10分自动执行
批处理如下:
@ECHO OFF
D:
cd “D:/awstats/awstats-6.9/wwwroot/cgi-bin/”
D:/awstats/perl5/bin/perl.exe awstats.pl -config=www.domain.com |
|
|