︿
Top

1、前言

AWStats - Advanced Web Statistics 為一套遵循 GPL 協議的開放源始碼 Log 分析器,它能夠幫助您分析包括使用者、使用者資訊、訪問頁面數、點擊數、更新時間、作業系統、瀏覽器版本、搜索引擎、關鍵字、錯誤鏈接...等等,支援所有的 Web 伺服器所產生的 Log。


AWStats 可分析的 Log 類型如下:

  • Web Log: Apache (NCSA combined/XLF/ELF or common/CLF log format)、Microsoft's IIS (W3C log format)
  • Streaming Log: Darwin Streaming Server、Windows Media Server
  • Mail Log: Qmail、Sendmail、Postfix
  • FTP Log: FTP Server

AWStats 官網 Screenshot:






文章目錄

1、前言
2、實作環境
3、安裝及設定
          步驟1.安裝 awstats 套件
          步驟2.修改 awstats 設定檔 (awstats.conf)
          步驟3.產生分析圖表
          步驟4.解決顯示搜尋的關鍵字句亂碼問題
          步驟5.觀看成果
          步驟6.修改排程
4、參考





2、實作環境

  • FreeBSD 5.2-RELEASE
  • awstats-6.0_1





3、安裝及設定

步驟1.安裝 awstats 套件

切換至 Ports Tree 路徑安裝 awstats 套件。
cd /usr/ports/www/awstats/       //切換至安裝路徑
make install clean                //安裝並清除暫存檔案 




步驟2.修改 awstats 設定檔 (awstats.conf)

安裝完成後請複製 awstats 範例檔來進行修改,而為何下列 awstats 設定檔會命名為 awstats.mail.conf? 因為 AWStats 可以分析不同種類的 Log 所以我將分析 Mail 所以設定檔命名為 awstats.mail.conf,而 awstats_maillogconvert.pl 功用於將 Mail Log 轉換成 Awstats 可分析格式檔案。修改後的設定檔內容為紅色字體!!
cd /usr/local/www/awstat/cgi-bin/           //切換路徑
cp awstats.model.conf awstats.mail.conf    //備份設定檔
vi awstats.mail.conf                         //修改 awstats 設定檔
 LogFile="/var/log/apache/access.log"   //預設值,讀取 Log 檔路徑
 LogFile="perl /usr/local/bin/awstats_maillogconvert.pl standard < /var/log/maillog|"
 LogType=W       //預設值,指定分析 Log 類型 (W - For a web log file)
 LogType=M       //修改後,指定分析 Mail Log (M - For a mail log file)
 LogFormat = "%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
 LogFormat = "%time2 %email %email_r %host %host_r %method %url %code %bytesd"
 LevelForBrowsersDetection=0           //新增此行及下列行數
 LevelForOSDetection=0
 LevelForRefererAnalyze=0
 LevelForRobotsDetection=0
 LevelForSearchEnginesDetection=0
 LevelForFileTypesDetection=0
 ShowMenu=1
 ShowMonthStats=HB
 ShowDaysOfMonthStats=HB
 ShowDaysOfWeekStats=HB
 ShowHoursStats=HB
 ShowDomainsStats=0
 ShowHostsStats=HBL
 ShowAuthenticatedUsers=0
 ShowRobotsStats=0
 ShowEMailSenders=HBL
 ShowEMailReceivers=HBL
 ShowSessionsStats=0
 ShowPagesStats=0
 ShowFileTypesStats=0
 ShowFileSizesStats=0
 ShowBrowsersStats=0
 ShowOSStats=0
 ShowOriginStats=0
 ShowKeyphrasesStats=0
 ShowKeywordsStats=0
 ShowMiscStats=0
 ShowHTTPErrorsStats=0
 ShowSMTPErrorsStats=1
 SiteDomain=""                     //預設值,設定主機名稱  
 SiteDomain="mail.weithenn.org"    //修改後,填入您主機的 FQDN
 DirCgi= "/cgi-bin"                //預設值,設定 CGI 路徑
 DirCgi="/cgi-bin/mail"            //修改後,設定為適合您環境設定
 DirIcons="/icon"                  //預設值,指定 awstats icon 目錄            
 DirIcons="/icons"                 //修改後,設定為適合您環境設定




步驟3.產生分析圖表

請鍵入如下指令來開始產生分析圖表,而為何產生分析圖表時指定的設定檔名稱為 -config=mail ? 因為在前面設定步驟中設定檔命名為 awstats.mail.conf,因此當您執行指令時可發現 awstats 是否有正確尋找到您的設定檔。
/usr/local/www/awstats/cgi-bin/awstats.pl -config=mail -update
 Update for config "./awstats.conf"
 With data in log file "perl   /usr/local/bin/awstats_maillogconvert.pl standard <   /var/log/maillog|"...
 Phase 1 : First bypass old records, searching new record...
 Searching new records from beginning of log file...
 Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
 Jumped lines in file: 0
 Parsed lines in file: 76
 Found 0 dropped records,
 Found 0 corrupted records,
 Found 74 old records,
 Found 2 new qualified records.




步驟4.解決顯示搜尋的關鍵字句亂碼問題

若未執行此步驟的話當您觀看分析圖表時可能會發現所有中文都正常,但分析圖表下方訪客使用哪些搜尋字句連到您的網站的 搜尋的關鍵字句 項目其內容會變成 亂碼,會有此一問題為顯示的文字其編碼為 UTF-8 格式,但 Awstats 預設的網頁顯示格式為 Big5 編碼格式所以就產生此一亂碼的問題,因此我們可透過將 Awstats 翻譯檔修改及儲存為 UTF-8 格式即可解決此一問題。
cp /usr/local/www/awstats/cgi-bin/lang/awstats-tw.txt awstats-tw.txt.big5
vi /usr/local/www/awstats/cgi-bin/lang/awstats-tw.txt.big5   //修改 Big5 編碼翻譯檔
 PageCode=big5           //預設值,編碼為 Big5
 PageCode=utf-8          //修改後,編碼為 UTF-8

修改完成後因為檔案格式仍為 Big5,因此我們使用 libiconv 套件來將檔案格式轉換為 UTF-8。
cd /usr/ports/converters/libiconv ; make instlal clean        //安裝 iconv 套件
iconv -f BIG5 -t UTF-8 awstats-tw.txt.big5 > awstats-tw.txt  //轉換為 UTF-8 格式




步驟5.觀看成果

完成後您可透過如下網址來連結至 Awstats 分析圖表頁面。
ex. http://www.weithenn.org/awstats/awstats.pl?config=mail



步驟6.修改排程

修改排程使系統每天早上六點自動執行分析 Mail Log 的工作。
crontab -e
 0 6 * * * /usr/local/www/awstats/cgi-bin/awstats.pl -config=mail -update > /dev/null 2>&1






4、參考

文章標籤: