天天看點

日志分析軟體awstats的安裝使用指南

1. 下載下傳位址

    http://sourceforge.net/projects/awstats/  

    http://voxel.dl.sourceforge.net/sourceforge/awstats/awstats-6.4-1.noarch.rpm

2. 安裝    

    2.1 rpm安裝

[[email protected] tools]# rpm -ivh awstats-6.4-1.noarch.rpm  

Preparing...                 ########################################### [100%]

    1:awstats                 ########################################### [100%]

----- AWStats 6.4 - Laurent Destailleur -----

AWStats 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

    2.2 tar包安裝

        直接解壓就行了,因為awstats是由perl編寫的。其實都一樣。

3. 運作配置腳本生成awstats的配置檔案

    cd /usr/local/awstats/tools

    perl awstats_configure.pl  

    配置腳本詢問域名等問題,假設回答的域名為www.abcd.com

    3.1 生成的配置檔案會放在/etc/awstats/下面

    3.2 生成的配置檔案的名稱為awstats.www.adcd.com.conf

    3.3 配置腳本隻能修改主要的log日志為combined,如果設定了虛拟主機,需要分别修改虛拟主機中的日志配置。

        格式設定 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

         自定義的日志采用什麼格式 CustomLog logs/testmysite-access_log combined

         建立日志 TransferLog logs/testmysite-access_log

4. 編輯awstats.www.abcd.com.conf,保證awstats的正常運作

    4.1 設定web server的logfile位置

        編輯LogFile為web server的log檔案位置

        LogFile=/usr/local/apache2/logs/abcd-access_log

        一定保證和httpd.conf中的log檔案保證一緻,httpd.conf中log名稱為

        logs/abcd-access_log

    4.2 設定要分析的服務日志類型

        LogType=W   

        w表示為WEB日志

    4.3 設定日志格式

        LogFormat=1  

        1表示采用NCSA apache combined/ELF/XLF log format

    4.4 設定所要分析網站域名

        SiteDomain="www.testmysite.com.cn"

        引号中一定要填上域名,或者伺服器主機名

    4.5 設定awstats的資料庫存放目錄

        DirData="/usr/local/awstats/data"

5. 建立awstats初始化資料庫

    perl awstats.pl -config=www.abcd.com -update  

6. 建立awstats的初始化靜态統計頁面

    perl awstats.pl -config=bbs.testmysite.com.cn -output -staticlinks > awstats.bbs.html  

7. 通過浏覽器重新整理統計頁面

    7.1 修改awstats.www.testmysite.com.cn.conf中

        AllowToUpdateStatsFromBrowser=1

    7.2 修改awstats的存放資料目錄的屬性為apache的運作使用者可讀寫

        chown -R nobody /usr/local/awstats/data

    7.3 檢查/usr/local/awstats/wwwroot/cgi-bin/*.pl 是否有執行權限

        chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl     

        注:rpm安裝包裡面的*.pl都具有執行權限,tar包裡面的*.pl卻沒有。

8. 設定需要認證才能通路流量統計頁面

    8.1 設定使用者admin有權通路該頁面

        cd /usr/local/apache2/bin

        ./htpasswd   -c /usr/local/apache2/passwords admin

        按提示連續輸入兩次密碼,這樣就建立了admin使用者才能通路流量統計頁面。

    8.2 設定httpd.conf中的awstats條目增加如下内容

            AuthType Basic

            AuthName "Restricted Files"

            AuthUserFile /usr/local/apache2/passwords

            Require user admin

9. 兩種觀看日志分析方法的比較

    9.1 靜态頁面分析方法的優點

        a. 安全性高,因為分析過程可以在背景通過crontab來執行,不需要執行cgi.

        b. 統計分析頁面響應速度快,因為是自動生成的靜态頁面,是以速度快過動态生成的頁面。

        c. 對伺服器的負載影響可控,自動生成的腳本執行次數一定,對伺服器的負載影響也是一定的。

    9.2 動态頁面分析方法的優點

        a. 實時檢視,可以随時在頁面動态重新整理統計分析結果。

    9.3 上面兩種方法的缺點就是他們優點的反面。

10. awstats在apache虛拟主機下的配置     

    10.1 虛拟主機有3個

         www.testmysite.com.cn

         bbs.testmysite.com.cn

         diy.testmysite.com.cn

    10.2 生成并修改對應虛拟主機的配置檔案

         cd /etc/awstats

         cp awstats.www.testmysite.com.cn.conf awstats.bbs.testmysite.com.cn.conf

         cp awstats.www.testmysite.com.cn.conf awstats.diy.testmysite.com.cn.conf

    10.3 修改配置檔案中的下列各項   

         LogFile=/usr/local/apache2/logs/bbs-accesss_log

         修改為實際的虛拟主機的log檔案位置

         SiteDomain="bbs.testmysite.com.cn"

         修改為實際各虛拟主機的域名

    10.4 修改httpd.conf各虛拟主機中的配置

         <VirtualHost 202.108.59.23>

         。。。。。。

         CustomLog logs/testmysite-access_log combined

         TransferLog logs/testmysite-access_log

         。。。。。。

         </VirtualHost>  

         主要是修改日志格式保證apache輸出的日志格式和awstats配置檔案中配置一緻。

12. 觀看流量統計方法

     12.1 使用者名&密碼

          admin/testmysiteok

     12.2 在浏覽器輸入

          檢視首頁流量分析

          http://www.testmysite.com.cn/awstats/awstats.pl?config=www.testmysite.com.cn

          檢視bbs流量分析

          http://www.testmysite.com.cn/awstats/awstats.pl?config=bbs.testmysite.com.cn

          檢視diy流量分析

          http://www.testmysite.com.cn/awstats/awstats.pl?config=diy.testmysite.com.cn

          為了便于使用可以将以上連接配接加入收藏夾。

問題:awstats and selinux

I have been futzing with this problem all day. I installed "awstats" to

start getting better stats on my web server usage. It worked like a

charm on my test box but failed on my production box. After looking too

long in the wrong places I finally found the problem. It is selinux.

Symptoms were, when I attempted to look at the awstats page, which is a

perl script, I got the following in my Apache error_log:

...(13)Permission denied: exec of

'/usr/local/awstats/wwwroot/cgi-bin/awstats.pl' failed

...Premature end of script headers: awstats.pl

I checked all of the permissions of everything and everything was right.

Finally I found a post that mentioned looking for errors

in /var/log/messages. I look there for other things I don't know I never

thought to look there for this. Anyway, when I looked there I saw:

...kernel: audit(1146243585.213:27): avc: denied { execute } for

pid=20973 comm="httpd" name="awstats.pl" dev=dm-0 ino=1082675

scontext=root:system_r:httpd_t tcontext=system_u:object_r:usr_t

tclass=file

I turned off selinux with the "setenforce 0 " command and it started

working.

Now, the problem here is that I really do not want to run my production

server without selinux turned on and was not able to figure out how to

correct the conflict. Anybody that could offer a pointer in the right

direction will be my new best friend :)

配置都沒有問題了。隻有隻讀屬性我想是linux中的selinux引起的,你關掉試試好了。
關閉SELinux的方法:
修改/etc/selinux/config檔案中的SELINUX="" 為 disabled ,然後重新開機。
如果不想重新開機系統,使用指令setenforce 0
注:
setenforce 1 設定SELinux 成為enforcing模式
setenforce 0 設定SELinux 成為permissive模式 
在lilo或者grub的啟動參數中增加:selinux=0,也可以關閉selinux 。      

繼續閱讀