Chinaunix首页 | 论坛 | 博客
  • 博客访问: 482813
  • 博文数量: 127
  • 博客积分: 7010
  • 博客等级: 少将
  • 技术积分: 1972
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-01 12:42
文章分类

全部博文(127)

文章存档

2009年(33)

2008年(94)

我的朋友

分类: LINUX

2008-08-01 17:30:53

AWStats: Advanced Web Statistics

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

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

AWStats的运行模式是这样的:

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

1. 修改Apache的配置文件 httpd.conf

默认配置CustomLog的日记格式是common,改为combined,后者是awstats推荐的方式可以用来分析客户端浏览器的类型以及访问来源等。例如:
CustomLog "| /apache/httpd/bin/rotatelogs /apache/httpd/logs/access_%Y%m%d.log 86400" combined

这个日志配置让apache每天生成一个新的日志文件,其中%Y%m%d是年月日。


2.安装awstats

一切准备妥当以后,我们就开始安装了,先进入/usr/local/awstats/tools里,运行awstats_configure.pl启动安装向导,步骤如下

[root@demo tools]# ./awstats_configure.pl 


----- AWStats awstats_configure 1.0 (build 1.3) (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  [/color]#输入你httpc.conf的路径,对于httpd2系列的一般都在/etc/httpd/conf/这个目录下面


这里将awstats的配置信息直接写入了httpd.conf

----->; Check and complete web server config file '/etc/httpd/conf/httpd.conf'

  Add ';' directive
  AWStats directives added to Apache config file.



 根据上面的httpd配置,更新了awstats.model.conf的内容,下面的.conf文件都要根据这个生成。


----->; Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
  File awstats.model.conf updated.


下面问你是否要创建一个新的配置文件,我们当然要创建了,否则装awstats干什么呀。选y没说的。

----->; 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[/color]



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

----->; Define config file name to create

What is the name of your web site or profile analysis ?
Example: 
Example: demo
Your web site, virtual server or profile name:
>; [/color]



下面是让你输入配置文件的路径,直接回车就可以了,当然你也可以自己定义

----->; 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):
>; /etc/awstats[/color]



好了,现在就在/etc/awstats下面创建了你定义的配置文件,这里是awstats..conf

----->; Create config file '/etc/awstats/awstats..conf'

 Config file /etc/awstats/awstats..conf created.



创建完配置文件以后会自动重启httpd服务。

----->; Restart Web server with '/sbin/service httpd restart'

停止 httpd                                                  [  确定  ]
启动 httpd                                                  [  确定  ]



下面的都是直接回车就可以了

----->; 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=
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..conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for '' with command:
>; perl awstats.pl -update -config=
You can also read your statistics for '' with URL:
>; http://localhost/awstats/awstats.pl?config=

Press ENTER to finish...


3.修改/etc/awstats/下面的

#vi awstats..conf
Include "common.conf"
LogFile="/var/log/apache/httpd-access.log"
LogType=W
SiteDomain=".conf"
HostAliases=".conf"
DefaultFile="index.html index.php"
DirData="/usr/local/awstats/data/"
DirIcons="/icons"
AllowToUpdateStatsFromBrowser=1


4.httpd.conf 中加入

Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /icons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/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

如果需要帐户验证,则改成:


    Order deny,allow
    Allow from all
    AuthName "awstats log "
    AuthType Basic
    AuthUserFile /usr/local/awstats/htpasswd

然后使用apache自带的工具htpasswd来生成一个用户名和口令

5.生成数据

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

6.访问


给awstats加上了Geo::IPfree插件

用途:用于awsats中关于来访者国家或地区的统计

配置Geo-IP

需要:

Geo-IP C-API ()
Geo-IP Perl-API ()
Geo::IPfree ()

安装:

Geo-IP C-API:
./configure
make
make install


Geo-IP Perl-API:
perl MakeFile.PL
make
make install


Geo::IPfree
perl MakeFile.PL
make
make install

最后,在/etc/awstats/awstats.yourdomain.conf中开启Geo::IPfree插件。

去掉 LoadPlugin="geoipfree" 前面的注释.

更新一下统计

/usr/local/awstats/tools/awstats_updateall.pl now


多网站多日志文件的合并分析和处理

用处:

1.用lvs之后,放了多台前端用的Web Server,每台Server有各自的日志.我们分开使用分析软件分析和检查是非常困难的,所以我们使用合并的方法.
2.多个域名,日志分开,使用awstats之类的分析软件进行分析很麻烦,所以需要合并
3.使用google的软件来做sitemap之类的应用,检查也会非常麻烦,所以需要合并
4.象多个节点的CDN日志,要进行流量统计和分析需要合并
5.因为日志文件过大,一个服务器生成多个日志文件.象access_log.1、access_log.2、access_log.3…以此类推,所以要合并.
等等…..

问题
对合并,进行日志排序最麻烦的一个问题就是,容易在跨天过程中生成的非正常数据.用一个前辈的话,这些不正常的日志,对awstats之类,就象吃了虫子一样,还有可能冲掉你以前的所有数据。

解决方法1(多谢东东):
在分析日志前,使用
sort -m -t " " -k 4 -o log_all log1 log2 log3
注释:
-m: 使用 merge优化算法

解决方法2:
使用 awstats 内建的工具logresolvemerge.pl 来合并日志 ,方法非常容易,主要是更改网站的设定档就好了,编辑 /etc/awstats/awstats.php-oa.conf
找到 LogFile 的地方,原来预设单个 log 的设定如下:

LogFile="/var/log/httpd/access_log"(原设置)

修改成
LogFile="/usr/local/awstats/tools/logresolvemerge.pl /var/log/httpd/access_log* |"   (合并分析新的设置)

如上,其实只要 logresolvemerge.pl 的路径还有日志的路径及使用匹配来设置即可,记的后面加一个"|"。注意上面我是要合并 access_log.1、access_log.2、access_log.3 的日志,要是你的日志名为别的,记的使用匹配符来匹配你要一起合并分析的日志.
另外.默认logresolvemerge.pl 是放在 awstats 安装路径的 tools 里面,比如我们的 awstats 是装在/usr/local/awstats 里面,所以完整路径就是 /usr/local/awstats/tools/logresolvemerge.pl 。

编辑保存后,再来执行更新记录的程序即可,如:
#/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=xxx -update

再来进去您的网址就可以看到合并后输出的结果了,如:


其它及美化
1.用Firefox浏览分析结果时,字体会显得很难看(因为Firefox和IE识别11px字体不一样),所以用Firefox浏览器的情况,可以通过修改

awstats.pl输出css的相关字体尺寸进行修改,而达到用Firefox浏览时也和IE一样能够正确显示出适当尺寸的字体。方法就是直接编

辑"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl",将文件中所有“11px”的地方都替换为 “12px。

2.如何修改报表里的文字,如参观者...等等这些信息,其实修改语言报就可以
#vi /usr/local/awstats/wwwroot/cgi-bin/lang/awstats-cn.txt 修改里面的文字就可以.



分析服务器上分析日志,并且静态化处理成为html显面显示数据.
[root@count sbin] cd /usrl/local/sbin
[root@count sbin]# vi build.sh

复制内容到剪贴板
代码:
#!/bin/sh
#build statics pages
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config= -lang=cn -

dir=/usr/local/www/apache22/data/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl


会将生成的静态页面保存在/usr/local/www/apache22/data/awstats目录下,将awstats..htm映射成index.html既可访问


阅读(1069) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~