搜索
熱搜: 活動 交友 discuz
查看: 3835|回復: 0
打印 上一主題 下一主題

[Linux] 【CentOS】Lightsquid-利用SquidLog達成流量統計圖表化

[複製鏈接]
跳轉到指定樓層
1#
發表於 2008-3-7 00:58:57 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
【前言】

[LightSquid - lite and fast log analizer for squid proxy]為利用 Squid Access Log 來分析 Proxy Client 使用情形。當然能分析 Squid Log 的軟體不只一套有興趣的話可到 [Squid-cache.org Squid: Logfile Analysis List] 看看。

LightSquid 特色如下: [LightSquid Analysis ScreenShot]

* fast and simple install
* fast log parser generatesmall per user data file
* perl based cgi script for dynamic generated report pages
* html template for design
* no database required
* no additional perl module
* various reports
* user groups support
* graphics report (v 1.6+)
* real name (v 1.6+)
* multilangual interface

【作業環境】

CentOS 5.1 (Linux 2.6.18-53.1.4.el5)

lighttpd-1.4.18-1.el5.rf

lightsquid-1.7.1.tgz

perl-GD-2.35-1.el5.rf (支援 GD 圖顯示)

【安裝及設定】

Step1.下載 lightsquid 及安裝 perl-GD 套件

  1. #yum -y install perl-GD                             //安裝 perl-GD 套件
複製代碼


至 [LightSquid - lite and fast log analizer for squid proxy] 下載 lightsquid-1.7.1.tgz 並上傳到本機家目錄上。

  1. #tar zxvf lightsquid-1.7.1.tgz                      //解?#125;壓縮檔
  2. #cp -r ~/lightsquid-1.7.1 /home/web/lightsquid      //複製至網頁根目錄下
  3. #cp lightsquid.cfg lightsquid.cfg.default           //複製一個預?#93;檔 (免得日後修錯忘了預?#93;值是什)
複製代碼


Step2.修改 lightsquid 設定檔

以下僅列出跟預設值不同的設定 (要更進階的請自行研究吧!!),因為預設是安裝到 /usr/local/www/lightsquid 但我習慣把東西放在 /home 下集中,所以就把目錄 cp -rp 到 /home 下吧。

  1. #vi /home/web/lightsquid/lightsquid.cfg
  2. $cfgpath             ="/home/web/lightsquid";           //指定 lightsquid.cfg ?#93;定檔路徑
  3. $tplpath             ="/home/web/lightsquid/tpl";       //指定 tpl 路徑 (存取屆時顯示 html、圖檔)
  4. $langpath            ="/home/web/lightsquid/lang";      //指定語系檔路徑
  5. $reportpath          ="/home/web/lightsquid/report";    //指定分析完資料放置路徑
  6. $logpath             ="/home/log/squid";                //指定要讀取 squid log 路徑
  7. $ip2namepath         ="/home/web/lightsquid/ip2name";   //指定要讀取 ip2name 路徑
複製代碼


修改完設定檔後我們可以跑一下檢查語法正確性的指令

  1. #chmod 755 check-setup.pl                                //改變一下權限吧,預?#93;為 644
  2. #/usr/local/www/lightsquid/check-setup.pl                    
  3. LightSquid Config Checker, (c) 2005 Sergey Erokhin GNU GPL
  4. LogPath   : /home/log/squid
  5. reportpath: /home/web/lightsquid/report
  6. Lang      : /home/web/lightsquid/lang/eng
  7. Template  : /home/web/lightsquid/tpl/base
  8. Ip2Name   : /home/web/lightsquid/ip2name/ip2name.simple
  9. all check passed, now try access to cgi part in browser  //檢查 OK
複製代碼


Step3.產生 lightsquid 分析圖表

接下來為利用 lightparser.pl 分析 Squid Access Log 若分析成功會有分析資料輸出到你指定的 reportpath (此例我設的路徑為 /home/web/lightsquid/report),注意不用打路徑只要打 access log 名稱就好,因為會自動幫你套設定的 LogPath 路徑

  1. #/home/web/lightsquid/lightparser.pl access.log.0            //access log 不用在打路徑了 (套用 LogPath: /home/log/squid)
複製代碼


Step4.連結分析結果網頁

http://your_host/lightsquid/index.cgi

因為 lightsquid 是使用 Perl Language 撰寫的而我使用的 web server 是 lighttpd 所以也要設定一下支援 CGI Module 才連得上 index.cgi 不然會變成下載 index.cgi 檔案,設定 lighttpd.conf 內容如下修改完後記得 restart lighttpd 哦!!

  1. #vi /usr/local/etc/lighttpd.conf
  2. server.modules = (
  3.                    "mod_cgi",                                              //這行的 mark 要拿掉 (支援 CGI Module)
  4.                   )
  5. index-file.names            = ( "index.php", "index.html",
  6.                                 "index.htm", "index.cgi", "default.htm" )  //?#91;上 index.cgi
  7. #### CGI module
  8. cgi.assign                 = ( ".pl"  => "/usr/bin/perl",                 //這行的 mark 要拿掉
  9.                                 ".cgi" => "/usr/bin/perl" )                //這行的 mark 要拿掉
複製代碼


Step5.加入排程自動分析

我們定於每天凌晨三點執行 squid rotate 來產生 squid access.log.0 然後凌晨四點使用 lightsquid 來分析 squid log 檔並產生統計圖表
  1. #crontab -e
  2. 0 3 * * * root /usr/local/sbin/squid -k rotate   
  3. 0 4 * * * root /usr/local/www/lightsquid/lightparser.pl access.log.0
複製代碼


【參考】

[LightSquid - lite and fast log analizer for squid proxy]

[LightSquid Home Site : How It Work]

[LightSquid Home Site : Ip2Name]

[Squid: Logfile Analysis]

[LightSquid Home Site : graph report]

【Log】
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

本論壇為非營利之網路平台,所有文章內容均為網友自行發表,不代表論壇立場!若涉及侵權、違法等情事,請告知版主處理。


Page Rank Check

廣告刊登  |   交換連結  |   贊助我們  |   服務條款  |   免責聲明  |   客服中心  |   中央分站

手機版|中央論壇

GMT+8, 2026-5-26 11:45 , Processed in 0.041948 second(s), 17 queries .

Powered by Discuz!

© 2005-2015 Copyrights. Set by YIDAS

快速回復 返回頂部 返回列表