AWStats配置與應(yīng)用詳解
【原創(chuàng)】【A WStats 】配置 Apache/Windows IIS 的日志分析工具2009年08月20日 星期四 12:09RHEL-5.3===========================
【原創(chuàng)】【A WStats 】配置 Apache/Windows IIS 的日志分析工具
2009年08月20日 星期四 12:09
RHEL-5.3
===================================================================================
【簡介】
奇碼科技的美國空間是帶有詳細(xì)的統(tǒng)計流量工具 awstats ,A WStats 是一套免費(fèi)基于 Perl 的網(wǎng)站日志分析工具。這個工具界面較為友好,執(zhí)行速度快,擴(kuò)展功能眾多,在國外空間使用 apache 服務(wù)器的,A WStats 是當(dāng)之無愧的首選。
A wstats 是一個免費(fèi)非常簡潔而且強(qiáng)大有個性的統(tǒng)計工具。它可以統(tǒng)計您站點(diǎn)的如下信息: ① 訪問量,訪問次數(shù),頁面瀏覽量,點(diǎn)擊數(shù),數(shù)據(jù)流量等
② 精確到每月、每日、每小時的數(shù)據(jù)
③ 訪問者國家
④ 訪問者 IP
⑤ Robots/Spiders 的統(tǒng)計
⑥ 紡客持續(xù)時間
⑦ 對不同 Files type 的統(tǒng)計信息
⑧ Pages-URL 的統(tǒng)計
⑨ 訪客操作系統(tǒng)瀏覽器等信息
其它信息(搜索關(guān)鍵字等等)
A WStats 是一個免費(fèi)的強(qiáng)大而有個性的工具,帶來先進(jìn)的網(wǎng)絡(luò)流量,F(xiàn)TP 或郵件服務(wù)器統(tǒng)計圖。 本日志分析器作為 CGI 或從命令行在數(shù)個圖形網(wǎng)頁中顯示你日志中包含的所有可能信息。 它利用一部分檔案資料就能經(jīng)常很快地處理大量日志檔案,它能分析日志文件來自從各大服務(wù)器工具,如 Apache 日志檔案(NCSA combined/XLF/ELF log format or common/CLF log format ), WebStar ,IIS (W3C 的日志格式)及許多其他網(wǎng)站,Proxy (代理服務(wù)器)、Wap 、流量服務(wù)器、郵件服務(wù)器和一些 FTP 服務(wù)器。
看一看這個比較表在最著名統(tǒng)計工具(A WStats, Analog, Webalizer,...)之間有何特點(diǎn)和不同的想法.
A WStats 是一個在 GNU 通用公共許可證下發(fā)行的免費(fèi)軟件。你可以看看這個許可證圖表而知道你可以/不可以做。
由于A WStats 工程來自網(wǎng)上信息,但也作為CGI 、 它可以與允許進(jìn)入Perl ,CGI 與日志的大型網(wǎng)站主辦提供商一起工作。
===================================================================================
【下載·安裝】
打開頁面: http://sourceforge.net/projects/awstats/
# wget http://jaist.dl.sourceforge.net/project/awstats/AWStats/6.9/awstats-6.9.tar.gz
也可下載
# wget http://jaist.dl.sourceforge.net/project/awstats/AWStats/6.9/awstats-6.9-1.noarch.rpm
,# rpm -ivh awstats-6.9-1.noarch.rpm
Preparing... ########################################### [100] 1:awstats ########################################### [100]
----- AWStats 6.9 - Laurent Destailleur -----
A WStats files have been installed in /usr/local/awstats
If first install, follow instructions in documentation
(/usr/local/awstats/docs/index.html) to setup AWStats in 3 steps:
Step 1 : Install and Setup with awstats_configure.pl (or manually)
Step 2 : Build/Update Statistics with awstats.pl
Step 3 : Read Statistics
# whereis awstats
awstats:
/usr/etc/awstats
/usr/local/awstats
===================================================================================
【配置 awstats 】
awstats 要求將 http.conf 中的 CustomLog /yourlogpath/yourlogfile common 改為 CustomLog /yourlogpath/yourlogfile combined ,我看了一下,我默認(rèn)的就是 combined ,可能現(xiàn)在新版本默認(rèn)的都是這個吧,那就不用改了。
再進(jìn)入 /usr/local/awstats/tools 里,運(yùn)行./awstats_configure.pl 啟動安裝向?qū)В?/p>
# cd /usr/local/awstats/tools
# ./awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.8) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix
-----> Check for web server install
,Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:Program filesapache groupapacheconfhttpd.conf
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf
輸入你 httpd.conf 的路徑。對于 httpd2 系列的一般都在/etc/httpd/conf/ 這個目錄下面,這里將 awstats 的配置信息直接寫入了 httpd.conf 。
-----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
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/"'
Add '
A WStats directives added to Apache config file.
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Y our web site, virtual server or profile name:
> qu6zhi.com
下面是要生成 conf 文件的名稱了,因?yàn)?conf 文件的名稱都是 awstats.yourdomainname.conf 格式的,所以這里要求你輸入你要監(jiān)測的域名,其實(shí)這個域名只是與其他域名相區(qū)分的,并不一定非要真實(shí)的。
-----> 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):
>
這里是讓你輸入配置文件的路徑,直接回車會執(zhí)行默認(rèn)的,當(dāng)然你也可以自己定義。
-----> Create config file '/etc/awstats/awstats.qu6zhi.com.conf'
Error: Failed to open '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf' for read.
那是因?yàn)樵撀窂秸也坏?awstats.model.conf 文件可以修改,而該文件所在的目錄是
,/usr/local/www/awstats/cgi-bin,既然程序只讀固定的路徑,那就按照它要讀取的路徑進(jìn)行相關(guān)設(shè)置,然后重新配置一次。
# cp /usr/etc/awstats/awstats.model.conf /usr/local/awstats/wwwroot/cgi-bin/
# ./awstats_configure.pl
-----> Create config file '/etc/awstats/awstats.qu6zhi.com.conf'
Config file /etc/awstats/awstats.qu6zhi.com.conf created.
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
Y ou can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=qu6zhi.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...
A SIMPLE config file has been created: /etc/awstats/awstats.qu6zhi.com.conf
Y ou should have a look inside to check and change manually main parameters.
Y ou can then manually update your statistics for 'qu6zhi.com' with command:
> perl awstats.pl -update -config=qu6zhi.com
Y ou can also read your statistics for 'qu6zhi.com' with URL:
> http://localhost/awstats/awstats.pl?config=qu6zhi.com
Press ENTER to finish...
------------------------------------------------------------------------------------------------------------------------------------
更新數(shù)據(jù)
#/usr/local/awstats/wwwroot/cgi-bin/awstats.pl --update -config=qu6zhi.com
Error: A WStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable.
Setup ('/etc/awstats/awstats.qu6zhi.com.conf' file, web server or permissions) may be wrong. Check config file, permissions and AWStats documentation (in 'docs' directory).
對于 /var/lib/awstats 目錄沒有寫入權(quán)限造成的
# chmod 777 /var/lib/awstats
chmod: cannot access `/var/lib/awstats': No such file or directory
# mkdir /var/lib/awstats
# chmod 777 /var/lib/awstats
更新數(shù)據(jù)
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl --update -config=qu6zhi.com
Create/Update database for config "/etc/awstats/awstats.qu6zhi.com.conf" by AWStats version 6.9 (build 1.925)
From data in log file "/var/log/httpd/mylog.log"...
,Error: Couldn't open server log file "/var/log/httpd/mylog.log" : No such file or directory Setup ('/etc/awstats/awstats.qu6zhi.com.conf' file, web server or permissions) may be wrong. Check config file, permissions and AWStats documentation (in 'docs' directory).
日志路徑錯位造成的
# vi /etc/awstats/awstats.qu6zhi.com.conf
將
LogFile="/var/log/httpd/mylog.log"
改成
LogFile="/var/log/httpd/access_log"
更新數(shù)據(jù)
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl --update -config=qu6zhi.com
Create/Update database for config "/etc/awstats/awstats.qu6zhi.com.conf" by AWStats version 6.9 (build 1.925)
From data in log file "/var/log/httpd/access_log"...
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: 8
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 8 new qualified records.
# cp /usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf /etc/awstats/common.conf # vi /etc/awstats/awstats.qu6zhi.com.conf
Include "common.conf"
#LogFile="/var/log/httpd/mylog.log"
LogFile="/var/log/httpd/access_log.YYYY-24MM-24?-24"
# YYYY-24MM-24?-24是指用24小時前的年月日日志文件名,如access_log.20061206 # LogFile="gzip -d < /qu6zhi.com/data/awstats/src/YYYY-24/MM-24/?-24.log.gz |"
SiteDomain="qu6zhi.com"
HostAliases="qu6zhi.com www.qu6zhi.com 127.0.0.1 localhost"
DefaultFile="index.html"
DirData="/var/lib/awstats"
DirData="/home/cgi-bin/awstats/data/"
添加定時分析指令
,# crontab -e
20 1 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl --update -config=qu6zhi.com ===================================================================================
【配置 apache 】
# vi /etc/httpd/conf/httpd.conf
281 DocumentRoot "/var/www/html/"
282 DocumentRoot "/usr/local/awstats/wwwroot"
這里將 awstats 的配置信息直接寫入了 httpd.conf
*****************************************************************
Please add the following to your apache config, and restart.
#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses “/usr/local/www/awstats/classes/”
Alias /awstatscss “/usr/local/www/awstats/css/”
Alias /awstatsicons “/usr/local/www/awstats/icons/”
ScriptAlias /awstats/ “/usr/local/www/awstats/cgi-bin/”
#
# This is to permit URL access to scripts/files in AWStats directory.
#
Options None
AllowOverride None
Order allow,deny
Allow from all
*****************************************************************
對要分析的虛擬主機(jī),將 CustomLog logs/access_xxx_log common 中的 common 改成 combined 。
從新啟動apache
# service httpd restart
------------------------------------------------------------------------------------------------------------------------------------
用瀏覽器訪問:http://server/awstats/awstats.pl?config=mysite
,The server encountered an internal error or misconfiguration and was unable to complete your request.
------------------------------------------------------------------------------------------------------------------------------------
當(dāng)你的 web 程序出現(xiàn)上述錯誤后,很有可能是文件的權(quán)限設(shè)置的不對,linux 下文件單個文件需要設(shè)置為755,當(dāng)你設(shè)置的是777就會這樣!
------------------------------------------------------------------------------------------------------------------------------------
SELinux 有提示
根據(jù) SELinux 的提示,更改配置
# chcon -t httpd_sys_content_t '/usr/local/awstats/wwwroot/cgi-bin/awstats.pl'
===================================================================================
用瀏覽器再次訪問:http://218.241.143.254/awstats/awstats.pl?config=qu6zhi.com
,===================================================================================
把圖標(biāo)等文件目錄復(fù)制到 WEB 的 HTML 文件發(fā)布目錄下,例如:/home/apache/htdocs/ 下發(fā)布更多的批量更新腳本等在 tools 目錄下,可以一并放到 cgi-bin/awstats/ 目錄下升級國內(nèi)主要搜索引擎和蜘蛛定義,安裝 GeoIP 的應(yīng)用庫:C
perl -MCPAN -e 'install "Geo::IP"' 或者使用純 Perl 包 perl -MCPAN -e 'install "Geo::IP::PurePerl"'
,下載 GeoIP/GeoIPCityLite 包:解包并部署到 awstats 目錄下:
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
將缺省 awstats.model.conf 命名成 common.conf
修改其中的一些配置選項:
LoadPlugin="decodeutfkeys"
LoadPlugin="geoip GEOIP_STANDARD /home/apache/chedong.com/cgi-bin/awstats/GeoIP.dat" LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /home/apache/chedong.com/cgi-bin/awstats/GeoLiteCity.dat"
創(chuàng)建 awstats 下創(chuàng)建:data 目錄用于統(tǒng)計數(shù)據(jù)輸出,缺省的統(tǒng)計輸出是按月匯總的;對于日志非常大的最好選擇按天統(tǒng)計輸出,并修改awstats.pl: 設(shè)置LIMITFLUSH 加10倍; $LIMITFLUSH =
50000; # Nb of records in data arrays after how we need to flush data on disk
可以有效提高統(tǒng)計的速度(減少磁盤IO ),并避免按月匯總數(shù)據(jù)導(dǎo)致的統(tǒng)計文件過大;
按照一下樣例設(shè)置配置文件:
Include "common.conf"
LogFile="/home/apache/logs/access_log.YYYY-24MM-24?-24"
SiteDomain="www.chedong.com"
HostAliases="chedong.com"
DefaultFile="index.html"
DirData="/home/apache/cgi-bin/awstats/data/"
------------------------------------------------------------------------------------------------------------------------------------
內(nèi)容摘要:
A WStats 的使用簡介和配置一些改進(jìn)說明。很高興看到在 A WStats 6.3 版本開始:中文用戶基本上已經(jīng)只需要將配置文件中將 LoadPlugin="decodeutfkeys" 啟用基本上就沒有什么中文搜索引擎的統(tǒng)計問題了,目前增加了多個國內(nèi)主要搜索引擎廠商。包含了針對國內(nèi)主要搜索引擎和蜘蛛定義的補(bǔ)丁(解包后覆蓋 lib 目錄下的原程序目錄即可) ,其中也包含了本站的樣例配置文件
日志統(tǒng)計系統(tǒng)在站點(diǎn)的用戶行為分析中扮演了重要的角色,尤其是對于來自搜索引擎的關(guān)鍵詞訪問統(tǒng)計:是很有效的用戶行為分析數(shù)據(jù)來源。隨著互聯(lián)網(wǎng)多年的發(fā)展,WEB 日志統(tǒng)計工具已經(jīng)越來越成熟,功能也越來越豐富。其中有很多是開放源代碼的, A WStats 就是其中非常優(yōu)秀的一款。
A WStats: Advanced Web Statistics
A WStats 是在Sourceforge 上發(fā)展很快的一個基于 Perl 的 WEB 日志分析工具。相對于另外一個非常優(yōu)秀的開放源代碼的日志分析工具Webalizer ,A WStats 的優(yōu)勢在于:
1. 界面友好:可以根據(jù)瀏覽器直接調(diào)用相應(yīng)語言界面(有簡體中文版)
參考輸出樣例:http://www.chedong.com/cgi-bin/awstats/awstats.pl?config=chedong