使用awstats分析网站日志-强大的日志分析工具

运营需要网站的数据统计,本来想用JS的方式来统计所有请求的情况,但是由于时间紧迫,所以重新部署awstats这个工具!

AWStats是一个基于PerlWEB日志分析工具,主页:http://awstats.sourceforge.net

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的运行模式

1、统计分析日志:将结果保存在一个txt文件中,最新版本支持xml数据格式。

2、输出分析结果:利用cgi程序输出,或生成静态html文件进行浏览。

 

AWStats的安装与配置

先创建如下两个目录:

/etc/awstats -- 网站统计的配置文件存放位置

/var/lib/awstats -- 网站统计的数据文件

awstats默认的目录是/usr/local/,所以下载下来请保存至此。

awstats采用perl来进行安装,所以服务器一定要有perl环境 yum install perl ;

 

  1. cd /usr/local; 
  2. wget http://prdownloads.sourceforge.net/awstats/awstats-7.0.tar.gz 
  3. tar zxvf awstats-7.0.tar.gz; 
  4. mv awstats-7.0  awstats; 
  5. chown apache:apache awstats -R  #设置web服务能访问此目录 
  6. perl /usr/local/awstats/tools/awstats_configure.pl #执行awstats安装 
  7.  
  8. 安装过程如下: 
  9. ----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur ----- 
  10. This tool will help you to configure AWStats to analyze statistics for 
  11. one web server. You can try to use it to let it do all that is possible 
  12. in AWStats setup, however following the step by step manual setup 
  13. documentation (docs/index.html) is often a better idea. Above all if: 
  14. - You are not an administrator user, 
  15. - You want to analyze downloaded log files without web server, 
  16. - You want to analyze mail or ftp log files instead of web log files, 
  17. - You need to analyze load balanced servers log files, 
  18. - You want to 'understand' all possible ways to use AWStats... 
  19. Read the AWStats documentation (docs/index.html). 
  20.  
  21. -----> Running OS detected: Linux, BSD or Unix 
  22. Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'. 
  23. If you want to use standard directory, you should first move all content 
  24. of AWStats distribution from current directory: 
  25. /root 
  26. to standard directory: 
  27. /usr/local/awstats 
  28. And then, run configure.pl from this location. 
  29. Do you want to continue setup from this NON standard directory [yN] ?    
  30. #这个选项告知你awstats默认应该安装在/usr/local/awstats下,问你是否采用默认的目录,默认即可 
  31.  
  32. -----> Check for web server install 
  33.  
  34. Enter full config file path of your Web server. 
  35. Example: /etc/httpd/httpd.conf 
  36. Example: /usr/local/apache2/conf/httpd.conf 
  37. Example: c:\Program files\apache group\apache\conf\httpd.conf 
  38. Config file path ('none' to skip web server setup): 
  39. >  
  40. #这个选项是问你的apache默认配置文件在哪,awstats会在你的配置文件中增加相关配置选项。
  41. 如果你用Nginx等其他web 跳过此选项,我的配置是: /etc/httpd/conf/httpd.conf 
  1. -----> Check and complete web server config file '/usr/local/apache2/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).
    Do you want me to setup Apache to write 'combined' log files [y/N] ?y
    #AWStats推荐使用combined格式的日志,apache默认使用common格式.
  2. 所以这个地方提示要不要修改apache的配置文件将日志格式改为combined,当然回答yes
  3.  
  4. -----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
  5. Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
  6. 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/"'
  7. Add '<Directory>' directive
    AWStats directives added to Apache config file.
  8. #apache的配置文件里面增加了上述内容,里面是一些目录和别名的设置.这部分一般加到了文件的最后面.
  9.  
  10. -----> Need to create a new config file ? 
  11. Do you want me to build a new AWStats config/profile 
  12. file (required if first install) [y/N] ?  这个选项是询问是否要要生成独立的 conf 文件的名称,
  13. 因为 conf 文件的名称都是 awstats.yourdomainname.conf 格式的,所以这里要求你输入你要监测的域名,
  14. 其实这个域名只是与其他域名相区分的,并不一定非要真实的。
  15.  
  16. -----> 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/

  17. -----> Create config file '/etc/awstats/awstats.www.sonkwo.com.conf'
    Config file /etc/awstats/awstats.www.sonkwo.com.conf created.

  18. -----> Create config file '/etc/awstats/awstats.www.sonkwo.com.conf'
    Config file /etc/awstats/awstats.www.sonkwo.com.conf created.

    -----> Restart Web server with '/sbin/service httpd restart'
    Stopping httpd: [ OK ]
    Starting httpd: [ OK ]
  19. -----> 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=www.sonkwo.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...
  20. #上面是告知你你可以在crontab中单独增加
    /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.sonkwo.com来定期刷新域:
    www.sonkwo.com域的日志统计,也可以使用/usr/local/awstats/tools/awstats_updateall.pl now 来刷新
    所有域的(/etc/awstats下)的统计
    
    A SIMPLE config file has been created: /etc/awstats/awstats.www.sonkwo.com.conf You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'www.sonkwo.com' with command: > perl awstats.pl -update -config=www.sonkwo.com You can also read your statistics for 'www.sonkwo.com' with URL: > http://localhost/awstats/awstats.pl?config=www.sonkwo.com #配置文件创建完成,可以通过 perl awstats.pl -update -config=www.sonkwo.com来刷新你的日志统计 访问方式 http://$awstats_ip/awstats/awstats.pl?config=www.sonkwo.com

AWStats配置文件

  1. #vi /etc/awstas/awstats.yourdomain.conf 
  2. 更改: 
  3. LogFile (要分析的日志的绝对路径) 
  4. DirData  (指定AWSTATS生成数据的存放目录,可以任意指定,但注意目录 
  5.            目录要具有读写权限,可以设置为777或755) 
  6. DirCgi   (cgi的路径,是相对于网站根目录的绝对路径,Default: "/cgi-bin"  
  7. DirIcons  (icon的路径,是相对于网站根目录的绝对路径:/icon) 
  8. SiteDomain (输入你的域名:yourdomain) 
  9. HostAliases (主机别名,如果还有其他的二级域名或三级域名,请在此添加。) 
  10. AllowToUpdateStatsFromBrowser (是否允许用户从浏览器中实时更新统计。0:不允许;1:允许) 
  11. Lang="cn" (设置网页显示语言为简体中文。) 

 

问题解决

  1. 问题1:Error: Failed to open '/root/wwwroot/cgi-bin/awstats.model.conf' for read. 
  2. 解决:进入awstats程序目录,本例为:/usr/local/awstats ,然后在运行

    perl /usr/local/awstats/tools/awstats_configure.pl

  3.  

    问题2: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.sonkwo.com.conf' file, web server or permissions) may be wrong.
    Check confi
    g file, permissions and AWStats documentation (in 'docs' directory).

    解决:确保存在/var/lib/awstats 目录,如果存在改变权限 chmod 777 /var/lib/awstats -R

  4.  

  5. 问题3:如何修改首页LOGO 和 链接地址

  6. 解决:在 /etc/awstas/awstats.yourdomain.conf 中找到如下两个选项

  7. Logo="awstats_logo6.png" #logo图片要放在awstats/wwwroot/icon/other/下
    LogoLink="http://www.sonkwo.com"

  8.  

  9. 问题4:如何修改统计页面的中文字体

  10. 解决:要根据你在/etc/awstas/awstats.yourdomain.conf中设置的语言,如果你选择的是

    Lang="cn" 则修改/usr/local/awstats/wwwroot/cgi-bin/lang/awstats-cn.txt文件即可

  11.  

  12. 问题5:统计中,“用以搜索的关键字” “用以搜索的词语”字体乱码,如何解决?

  13. 分析:因为现在的搜索引擎都是使用UTF8,而Awstats是使用decodeUTFkeys这个plugin来处理搜索引擎的UTF8关键字,

  14. 默认是没有打开的,所以在显示上会出现乱码

  15. 解决:启用 DecodeUTFKeys,在 /etc/awstas/awstats.yourdomain.conf 把 LoadPlugin="decodeutfkeys"

  16. 的注释去掉,根据插件的描述(如下)还要安装Encode and URI::Escape 的perl模块,使用cpan安装

  17. cpan> install Encode ; cpan> install URI::Escape

  18. # PLUGIN: DecodeUTFKeys
    # REQUIRED MODULES: Encode and URI::Escape
    # PARAMETERS: None
    # DESCRIPTION: Allow AWStats to show correctly (in language charset)
    # keywords/keyphrases strings even if they were UTF8 coded by the
    # referer search engine.
    #

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章