使用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.
    #

 

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