︿
Top

1、前言

LightSquid 為針對 Squid Log 進行分析以充份瞭解 Squid Clients 使用情形。當然仍有許多可以分析 Squid Log 的軟體,有興趣的話可參考 Squid: Logfile Analysis


LightSquid 特色如下:

  • 簡單且快速的安裝方式
  • 快速分析每個使用者資料
  • 以 Perl 為基礎的 CGI 腳本動態產生分析報告
  • HTML 範本設計
  • 不需使用資料庫 (Database)
  • 不需安裝額外的 Perl 模組 (Module)
  • 各種使用者資料報告 
  • 支援使用者及群組功能
  • 版本 1.6 以後支援圖形分析報告
  • 版本 1.6 以後支援使用者名稱報告
  • 支援多國語系介面

LightSquid 成果截圖:






文章目錄

1、前言
2、實作環境
3、安裝及設定
          步驟1.安裝 lightsquid 套件
          步驟2.修改 lightsquid 設定檔 (lightsquid.cfg)
          步驟3.產生 lightsquid 分析圖表
          步驟4.修改 Web Server 設定檔
          步驟5.連結分析結果網頁
          步驟6.設定排程
4、參考





2、實作環境

  • FreeBSD 6.2-RELEASE
  • lighttpd-1.4.18_1
  • lightsquid-1.7.1_1





3、安裝及設定

步驟1.安裝 lightsquid 套件

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




步驟2.修改 lightsquid 設定檔 (lightsquid.cfg)

因為預設是安裝到 /usr/local/www/lightsquid 但個人習慣將資源集中在 /home 下,以下僅列出基本修改,詳細內容請參考官網 LightSquid
vi /usr/local/etc/lightsquid/lightsquid.cfg
 $cfgpath ="/usr/local/etc/lightsquid";         //指定 lightsquid.cfg 設定檔路徑
 $tplpath ="/home/web/lightsquid/tpl";          //指定 tpl 路徑 (屆時顯示 html、圖檔)
 $langpath ="/usr/local/share/lightsquid/lang"; //指定語系檔路徑
 $reportpath ="/home/web/lightsquid/report";    //指定分析完資料放置路徑
 $logpath ="/home/log/squid";                   //指定要讀取 Squid Log 路徑


修改完 lightsquid 設定檔之後,可鍵入如下指令檢查設定檔內語法正確性。
/usr/local/www/lightsquid/check-setup.pl                  
 LightSquid Config Checker, (c) 2005 Sergey Erokhin GNU GPL
 LogPath   : /home/log/squid
 reportpath: /home/web/lightsquid/report
 Lang      : /usr/local/share/lightsquid/lang/eng
 Template  : /home/web/lightsquid/tpl/base
 Ip2Name   : /usr/local/libexec/lightsquid/ip2name.simple
 all check passed, now try access to cgi part in browser  //顯示檢查結果正確無誤




步驟3.產生 lightsquid 分析圖表

檢查 lightsquid 設定檔內語法皆正確之後即可透過 lightparser.pl 分析 Squid Access Log 分析完成後其資料即存放至您指定的 reportpath (此次實作路徑為 /home/web/lightsquid/report),請注意分析 Squid Access Log 時不需鍵入檔案路徑只需 Log 名稱即可,因為 lightparser.pl 處理時會自動幫您加上您所設定的 LogPath 路徑。
# /home/web/lightsquid/lightparser.pl access.log.0   //Log 不需鍵入路徑



步驟4.修改 Web Server 設定檔

此次實作 Web Server 為採用 Lighttpd,因此必須設定 Lighttpd 支援 CGI Module 才能連結 Lightsquid 的分析網頁 (index.cgi),若未設定 Lighttpd 支援 CGI Module 的話則觀看分析結果網頁時會變成下載 index.cgi 檔案,修改好 Lighttpd 設定檔 lighttpd.conf 之後請記得重新載入 Lighttpd 服務。關於 Lighttpd 詳細設定內容可參考站內文章 LigHttpd-輕量級 Web Server
vi /usr/local/etc/lighttpd.conf
 server.modules = (
                   "mod_cgi",                    //移除註解符號 (支援 CGI Module)
                  )
 index-file.names = ( "index.php", "index.html",
                      "index.htm", "index.cgi")  //加上 index.cgi
#### CGI module
 cgi.assign = ( ".pl"  => "/usr/bin/perl",       //移除註解符號
                ".cgi" => "/usr/bin/perl" )      //移除註解符號
# /usr/local/etc/rc.d/lighttpd reload             //重新載入 Lighttpd 服務




步驟5.連結分析結果網頁

完成後可在瀏覽器輸入類似下列網址,連結至 lightsquid 分析結果首頁。
ex. http://www.weithenn.org/lightsquid/index.cgi



步驟6.設定排程

此次實作設定系統於每天凌晨 3 點產生 Squid Logs (Rotate) 名稱為 access.log.0 然後凌晨 4 點執行 lightparser.pl 進行分析 Squid Log 檔並產生統計圖表。
crontab -e
 0 3 * * * root /usr/local/sbin/squid -k rotate
 0 4 * * * root /usr/local/www/lightsquid/lightparser.pl access.log.0






4、參考

文章標籤: