http日志分析工具Awstat安装详解

来源:互联网 发布:图片推荐算法 编辑:程序博客网 时间:2024/04/30 15:15

转自:http://www.linuxidc.com/Linux/2011-09/42673.htm

Awstat的功能:


  AWStats是在Sourceforge上发展很快的一个基于Perl的WEB日志分析工具。它可以统计您站点的如下信息:
  一:访问量,访问次数,页面浏览量,点击数,数据流量等
  二:精确到每月、每日、每小时的数据
  三:访问者国家
  四:访问者IP
  五:Robots/Spiders的统计
  六:纺客持续时间

  七:对不同Files type 的统计信息
  八:Pages-URL的统计
  九:访客操作系统浏览器等信息
  十:其它信息(搜索关键字等等)


安装:
awstats-7.0.zip下载地址:

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /pub/2011/09/11/http日志分析工具Awstat安装详解/

安装之前首先启动apache,并查看进程
/usr/local/apache/bin/apachectl start

解压包:
unzip  awstats-7.0.zip

创建存放目录
mkdir -p /usr/local/awstats
mv  awstats-7.0/*   /usr/local/awstats

确定系统已经安装perl
 whereis perl
perl: /usr/bin/perl /usr/share/man/man1/perl.1.gz

编译awstats:
perl awstats_configure.pl


----- AWStats awstats_configure 1.0 (build 1.9) (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


#如果系统中没有安装apache的话会提示要求你输入apache配置文件的路径
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):
>                                                               


#如果系统已安装apache的话,自动会检测到配置文件
-----> Check for web server install
  Found Web server Apache config file '/usr/local/apache/conf/httpd.conf'


-----> Check and complete web server config file '/usr/local/apache/conf/httpd.conf'
Warning: You Apache config file contains directives to write 'common' log files
This means that some features can't work (os, browsers and keywords detection).
#输入y,将日志记录方式由'command'改为更详细的‘combined’
Do you want me to setup Apache to write 'combined' log files [y/N] ?  y
  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.


-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
  File awstats.model.conf updated.
-----> Need to create a new config file ?
#输入y创建一个新的配置文件
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:


#输入配置文件的名字
> AnalyzeApacheLog


-----> 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.AnalyzeApacheLog.conf'
 Config file /etc/awstats/awstats.AnalyzeApacheLog.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=AnalyzeApacheLog
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.AnalyzeApacheLog.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'AnalyzeApacheLog' with command:
> perl awstats.pl -update -config=AnalyzeApacheLog
You can also read your statistics for 'AnalyzeApacheLog' with URL:
#查看分析报告的链接如下:
> http://localhost/awstats/awstats.pl?config=AnalyzeApacheLog


Press ENTER to finish...


修改配置文件:
vi /etc/awstats/awstats.AnalyzeApacheLog.conf
#LogFile="/var/log/httpd/mylog.log"
LogFile="/home/wwwlog/www.pcstars.com_access.log"

注:
(1)如果同时分析多个日志
LogFile="/opt/awstats/tools/logresolvemerge.pl /var/apachelogs/30.0206.vblog.log /var/apachelogs/31.0206.vblog.log|"

LogFile="/opt/awstats/tools/logresolvemerge.pl /var/apachelogs/*.0206.vblog.log|"


(2)分析使用gzip压缩过的日志文件
LogFile="gzip -d </var/log/apache/access.log.gz|"

最后重启apache,通过web访问 http://localhost/awstats/awstats.pl?config=AnalyzeApacheLo
前提条件是apache对应的端口没有防火墙限制或者SELinux的限制,否则可能会报403错误
如果出现这种情况最好找系统管理员解决,不要擅自修改系统文件

AWStats did not find any valid log lines that match your LogFormat paramet



本来认为安装完awstats之后就无所事实,万事大吉了,没想到后续工作还是挺让我头疼的

根据上篇的URL访问web:
http://211.100.97.250/awstats/awstats.pl?config=ApacheLog

出现了如下报错:

原来/var/lib/awstats这个目录不存在,它是统计结果存放的目录,那么创建该目录 mkdir -P /var/lib/awstats

刷新页面,顺利进入web界面了

没想到web界面上各项统计数据均为零

回到后台看了一下access_log文件并不为空,有数以万行的访问记录,不应该是现在的局面

我尝试这运行了这个更新程序的命令:
 /usr/local/awstats/tools/awstats_updateall.pl now

出现如下提示(也包括报错):


报错内容的主要意思是:
access_log中的日至格式与http.conf配置文件中指定的日志格式不一致

我修改httpd.conf配置文件如下:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog "logs/access_log" combined

并将access_log日志文件清空,为了重新生成日志文件,特意访问了一下http://211.100.97.250/zabbix/
再次运行上述操作:


发现没有了报错提示之后,我重新访问web:http://211.100.97.250/awstats/awstats.pl?config=ApacheLog

意外发现,出现了统计数据: