天天看點

RHEL5.4 部署web日志分析服務之awstats+jawstats

<b>一     awstats </b><b>簡介</b>

1 awstats是一個基于跑Perl 的web日志分析工具,其可以跨平台,界面友好,分析内容詳盡,并支援多個語言操作界面,

2    awstats 優點

awstats能夠分析web統計的所有資料,包括通路量,通路這者數量,頁面,點選,高峰時段,通路者的作業系統,浏覽器類型及其版本,搜尋引擎,關鍵字,機械通路,無效連結等

3  當然awstats 不僅能夠分析web 日志,同樣能夠分析ftp日志,還能夠分析mail 日志當然這需要在其配置檔案中更改其日志類型:

    LogType來指定日志類型,

     w代表web log file 

    F 代表ftp log file

    M 代表mail log file 

   S 代表streaming log file ,

  當然awstats 還能夠合并日志并進行分析,及壓縮日志檔案如access.log.gz 等

4  awstats 的缺點,占用系統的資源較多,尤其是占用的系統的記憶體

<b>二    awstats </b><b>的安裝配置</b>

     1  在安裝前一定要确認系統上是否有perl 環境,httpd ,如果沒有需要安裝perl軟體包,當然在此就不在安裝perl ,

     2  安裝awstats

        #tar xvf awstats-7.0.tar.gz

        #mv awstats-7.0 /usr/local/awstats

        #cd /usr/local/awstats/tools

        # 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).

-----&gt; Running OS detected: Linux, BSD or Unix

-----&gt; 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):

<b>&gt; /etc/httpd/conf/httpd.conf    &lt;</b><b>------  </b><b>注: </b><b>該處是apache </b><b>主配置檔案的路徑</b>

-----&gt; 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 '&lt;Directory&gt;' directive

 AWStats directives added to Apache config file.

-----&gt; Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'

 File awstats.model.conf updated.

-----&gt; Need to create a new config file ?

Do you want me to build a new AWStats config/profile

<b>file (required if first install) [y/N] ? y  &lt;</b><b>--- </b><b>注: </b><b>選擇是不是同一建立一個新的對象配置檔案</b>

-----&gt; 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:

-----&gt; 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):

&gt; /<b>etc/awstats   &lt;</b><b>--------- </b><b>注: </b><b>将awstats </b><b>的配置檔案放在/etc/awstats </b><b>路徑下</b>

-----&gt; Create config file '/etc/awstats/awstats.www.frank.com.conf'

 Config file /etc/awstats/awstats.www.frank.com.conf created.

-----&gt; Restart Web server with '/sbin/service httpd restart'   注: 重新開機apache 伺服器

Stopping httpd: [ OK ]

Starting httpd: [ OK ]

-----&gt; 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.frank.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...    &lt;-------- <b>#</b><b>按Enter </b><b>鍵</b>

A SIMPLE config file has been created: /etc/awstats/awstats.www.frank.com.conf

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

You can then manually update your statistics for 'www.frank.com' with command:

&gt; perl awstats.pl -update -config=www.frank.com

You can also read your statistics for 'www.frank.com' with URL:

&gt; http://localhost/awstats/awstats.pl?config=www.frank.com

Press ENTER to finish...<b>  &lt;</b><b>--------- </b><b>注: </b><b>按Enter </b><b>鍵</b>

  3   修改以下各項

   #cd  /etc/awstats

   #vim   awstats.www.frank.com.conf

       LogFile="/var/log/httpd/mylog.log"

       修改為apache 的日志檔案

        LogFile=“/var/log/httpd/access_log”

   4    手動建立目錄

#mkdir /var/lib/awstats 注:該目錄為awstats的資料庫庫存放目錄

  5    建立awstats 初始化資料庫庫

          #perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl   -config=www.frank.com –update

     注 :問題

perl ../wwwroot/cgi-bin//awstats.pl -config=puppet.frank.com

Create/Update database for config "/etc/awstats/awstats.puppet.frank.com.conf" by AWStats version 7.0 (build 1.970)

From data in log file "/usr/local/awstats/tools/logresolvemerge.pl /var/log/httpd/*_log |"...

sh: /usr/local/awstats/tools/logresolvemerge.pl: Permission denied

Phase 1 : First bypass old records, searching new record...

Searching new records from beginning of log file...

Error: Command for pipe '/usr/local/awstats/tools/logresolvemerge.pl /var/log/httpd/*_log |' failed

Setup ('/etc/awstats/awstats.puppet.frank.com.conf' file, web server or permissions) may be wrong.

Check config file, permissions and AWStats documentation (in 'docs' directory)

解決方法是

#chmod u+x /usr/local/awstats/tools/*.pl 

 6   確定在apche 的主配置檔案尾部有如下配置,莫熱門情況下在安裝配置awstats 後 預設是已經配置好了

    #

# Directives to allow use of AWStats as a CGI

#

Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"

Alias /awstatscss "/usr/local/awstats/wwwroot/css/"

Alias /awstatsicons "/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.

&lt;Directory "/usr/local/awstats/wwwroot/"&gt;

    Options None

    AllowOverride None

    Order allow,deny

    Allow from all

&lt;/Directory&gt;

  這是您檢視一下awstats 對網站的分析情況

    注: config 後面為您要分析的URL

<b>三    </b><b>安裝awstats</b><b>的插件能</b>

     GeoIP和Geo::IPfree都免費的是國家/IP的映射表,比通過DNS反相解析域名得到的統計準确,而且速度快。GeoIP的API都是免費的,預設庫是免費的,收費的是它的資料更新服務。Geo::IPfree不僅代碼是公開的,而且庫資料也是公開的

      1  安裝 GeoIP

        #tar xvf GeoIP-1.4.6.tar.gz

        #cd GeoIP-1.4.6

        #./configure

        #make &amp;&amp; make install

      2  安裝Geo-IP

         #tar xvf Geo-IP-1.38.tar.gz

         #cd Geo-IP-1.38

         #perl Makefile.PL

         #make &amp;&amp; make install

      3 安裝Geo-IPfre

         #tar xvf Geo-IPfree-0.2.tar.gz

         #cd Geo-IPfree-0.2

         #make  &amp;&amp; make install

<b>四    </b><b>安裝jawstats</b>

   1   jawstats 是awstats 一款PHP外挂系統,jawstats 是在awstats生成的資料基礎上構造出更加清晰美觀的關于網站通路資料的圖表,表格,并且安裝簡便,快捷。

   2  安裝 jawstats

    #tar xvf jawstats-0.7beta.tar.gz

    #cd jawstats-0.7beta.

    #mv ./*   /usr/local/awstats/wwwroot

    #chown –R apache /usr/local/awstats/jawstats

   3   配置jawstats

     #cd /usr/local/awstats/jawstats

     #cp   config.dist.php config.php

     #vim   config.php

      修改下面幾項

     $aConfig["site1"] = array( 注: 該處site1 要修改為你的配置檔案名,如awstats.www.frank.com.conf 當然這裡就改為 www.frank.com

    "statspath"   =&gt; "/path/to/data/",     注: 該處修改為awstats資料檔案的路徑,當然在安裝awstats 時預設情況下是在/var/lib/awstats

    "updatepath" =&gt; "/path/to/awstats.pl/",     注: 該處為awstat s.pl 執行檔案所在的路徑

    "siteurl"     =&gt; "http://www.my-1st-domain.com",

    "sitename"    =&gt; "",

    "theme"       =&gt; "default",

    "fadespeed"   =&gt; 250,

    "password"    =&gt; "my-1st-password",

    "includes"    =&gt; "",

    "language"    =&gt; "en-gb"

 );

 修改為

   $aConfig["puppet.frank.com"] = array( 

    "statspath"   =&gt; "/var/lib/awstats/",

    "updatepath" =&gt; "/user/local/awstats/wwwroot/cgi-bin/awstats.pl/",

    "siteurl"     =&gt; "http://puppet.frank.com",

    "sitename"    =&gt; "This is my main website",

    "password"    =&gt; "frank",

    "language"    =&gt; "zh-cn"

 4  由于jawstats 配置有一個小一點的bug 需要需改一下

   #vim  index.php

   #修改前

  &lt;?

    // output booleans for javascript

    function BooleanToText($bValue) {

 #修改後

&lt;?php

    // output booleans for javascript 

    function BooleanToText($bValue) {      

 5  修改apache的主配置檔案

&lt;Directory "/usr/local/awstats/wwwroot"&gt;

 &lt;Directory "/usr/local/awstats/wwwroot/jawstats"&gt;

   當然如果是考慮安裝您還可以配置通過https 的web 及配置基于使用者的web 服務

    6  重新開機apache

        #service httpd restart

          在浏覽器輸入

<a target="_blank" href="http://blog.51cto.com/attachment/201012/145833416.png"></a>

本文轉自 freehat08 51CTO部落格,原文連結:http://blog.51cto.com/freehat/469848,如需轉載請自行聯系原作者