|
|
【前言】
[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 套件
- #yum -y install perl-GD //安裝 perl-GD 套件
複製代碼
至 [LightSquid - lite and fast log analizer for squid proxy] 下載 lightsquid-1.7.1.tgz 並上傳到本機家目錄上。
- #tar zxvf lightsquid-1.7.1.tgz //解?#125;壓縮檔
- #cp -r ~/lightsquid-1.7.1 /home/web/lightsquid //複製至網頁根目錄下
- #cp lightsquid.cfg lightsquid.cfg.default //複製一個預?#93;檔 (免得日後修錯忘了預?#93;值是什)
複製代碼
Step2.修改 lightsquid 設定檔
以下僅列出跟預設值不同的設定 (要更進階的請自行研究吧!!),因為預設是安裝到 /usr/local/www/lightsquid 但我習慣把東西放在 /home 下集中,所以就把目錄 cp -rp 到 /home 下吧。
- #vi /home/web/lightsquid/lightsquid.cfg
- $cfgpath ="/home/web/lightsquid"; //指定 lightsquid.cfg ?#93;定檔路徑
- $tplpath ="/home/web/lightsquid/tpl"; //指定 tpl 路徑 (存取屆時顯示 html、圖檔)
- $langpath ="/home/web/lightsquid/lang"; //指定語系檔路徑
- $reportpath ="/home/web/lightsquid/report"; //指定分析完資料放置路徑
- $logpath ="/home/log/squid"; //指定要讀取 squid log 路徑
- $ip2namepath ="/home/web/lightsquid/ip2name"; //指定要讀取 ip2name 路徑
複製代碼
修改完設定檔後我們可以跑一下檢查語法正確性的指令
- #chmod 755 check-setup.pl //改變一下權限吧,預?#93;為 644
- #/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 : /home/web/lightsquid/lang/eng
- Template : /home/web/lightsquid/tpl/base
- Ip2Name : /home/web/lightsquid/ip2name/ip2name.simple
- 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 路徑
- #/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 哦!!
- #vi /usr/local/etc/lighttpd.conf
- server.modules = (
- "mod_cgi", //這行的 mark 要拿掉 (支援 CGI Module)
- )
- index-file.names = ( "index.php", "index.html",
- "index.htm", "index.cgi", "default.htm" ) //?#91;上 index.cgi
- #### CGI module
- cgi.assign = ( ".pl" => "/usr/bin/perl", //這行的 mark 要拿掉
- ".cgi" => "/usr/bin/perl" ) //這行的 mark 要拿掉
複製代碼
Step5.加入排程自動分析
我們定於每天凌晨三點執行 squid rotate 來產生 squid access.log.0 然後凌晨四點使用 lightsquid 來分析 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
複製代碼
【參考】
[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】 |
|