AWStats配置与应用详解

【原创】【A WStats 】配置 Apache/Windows IIS 的日志分析工具2009年08月20日 星期四 12:09RHEL-5.3===========================

【原创】【A WStats 】配置 Apache/Windows IIS 的日志分析工具

2009年08月20日 星期四 12:09

RHEL-5.3

===================================================================================

【简介】

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

A wstats 是一个免费非常简洁而且强大有个性的统计工具。它可以统计您站点的如下信息: ① 访问量,访问次数,页面浏览量,点击数,数据流量等

② 精确到每月、每日、每小时的数据

③ 访问者国家

④ 访问者 IP

⑤ Robots/Spiders 的统计

⑥ 纺客持续时间

⑦ 对不同 Files type 的统计信息

⑧ Pages-URL 的统计

⑨ 访客操作系统浏览器等信息

其它信息(搜索关键字等等)

A WStats 是一个免费的强大而有个性的工具,带来先进的网络流量,FTP 或邮件服务器统计图。 本日志分析器作为 CGI 或从命令行在数个图形网页中显示你日志中包含的所有可能信息。 它利用一部分档案资料就能经常很快地处理大量日志档案,它能分析日志文件来自从各大服务器工具,如 Apache 日志档案(NCSA combined/XLF/ELF log format or common/CLF log format ), WebStar ,IIS (W3C 的日志格式)及许多其他网站,Proxy (代理服务器)、Wap 、流量服务器、邮件服务器和一些 FTP 服务器。

看一看这个比较表在最著名统计工具(A WStats, Analog, Webalizer,...)之间有何特点和不同的想法.

A WStats 是一个在 GNU 通用公共许可证下发行的免费软件。你可以看看这个许可证图表而知道你可以/不可以做。

由于A WStats 工程来自网上信息,但也作为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 -----

A WStats 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 ,我看了一下,我默认的就是 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 filesapache groupapacheconfhttpd.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 '' directive

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

Y our 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.

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

Y ou should have a look inside to check and change manually main parameters.

Y ou can then manually update your statistics for 'qu6zhi.com' with command:

> perl awstats.pl -update -config=qu6zhi.com

Y ou 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: A WStats 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-24MM-24�-24"

# YYYY-24MM-24�-24是指用24小时前的年月日日志文件名,如access_log.20061206 # LogFile="gzip -d < /qu6zhi.com/data/awstats/src/YYYY-24/MM-24/�-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.

#

Options None

AllowOverride None

Order allow,deny

Allow from all

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

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

从新启动apache

# service httpd restart

------------------------------------------------------------------------------------------------------------------------------------

用浏览器访问:http://server/awstats/awstats.pl?config=mysite

,

The server encountered an internal error or misconfiguration and was unable to complete your request.

------------------------------------------------------------------------------------------------------------------------------------

当你的 web 程序出现上述错误后,很有可能是文件的权限设置的不对,linux 下文件单个文件需要设置为755,当你设置的是777就会这样!

------------------------------------------------------------------------------------------------------------------------------------

SELinux 有提示

,

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

,

===================================================================================

把图标等文件目录复制到 WEB 的 HTML 文件发布目录下,例如:/home/apache/htdocs/ 下发布更多的批量更新脚本等在 tools 目录下,可以一并放到 cgi-bin/awstats/ 目录下升级国内主要搜索引擎和蜘蛛定义,安装 GeoIP 的应用库: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-24MM-24�-24"

SiteDomain="www.chedong.com"

HostAliases="chedong.com"

DefaultFile="index.html"

DirData="/home/apache/cgi-bin/awstats/data/"

------------------------------------------------------------------------------------------------------------------------------------

内容摘要:

A WStats 的使用简介和配置一些改进说明。很高兴看到在 A WStats 6.3 版本开始:中文用户基本上已经只需要将配置文件中将 LoadPlugin="decodeutfkeys" 启用基本上就没有什么中文搜索引擎的统计问题了,目前增加了多个国内主要搜索引擎厂商。包含了针对国内主要搜索引擎和蜘蛛定义的补丁(解包后覆盖 lib 目录下的原程序目录即可) ,其中也包含了本站的样例配置文件

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

A WStats: Advanced Web Statistics

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

1. 界面友好:可以根据浏览器直接调用相应语言界面(有简体中文版)

参考输出样例:http://www.chedong.com/cgi-bin/awstats/awstats.pl?config=chedong

标签: