2009年3月17日 星期二

[Linux]AWSTATS 安裝設定教學

AWStats是一套免費及功能強大的Log分析軟體產生報表。
官方網址 ( http://awstats.sourceforge.net/)
解壓縮 awstats-6.6.tar.gz(http://prdownloads.sourceforge.net/awstats/awstats-6.6.tar.gz)
# tar zxvf awstats-6.6.tar.gz
將解壓縮出來的 tools 及 wwwroot 目錄移至到 /usr/local/awstats 目錄下
切換目錄至 /usr/local/awstats 目錄
# cd /usr/local/awstats
執行 tools 目錄下的 awstats_configure.pl
#cd tool
#./awstats_configure.pl
設定config檔
----- AWStats awstats_configure 1.0 (build 1.6) (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 files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/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 '' directive
AWStats directives added to Apache config file.
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.mode l.conf'
File awstats.model.conf updated.
-----> 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
Your web site, virtual server or profile name:
> 你的網站
-----> 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):
>
-----> Create config file '/etc/awstats/awstats.你的網站.conf'
Config file /etc/awstats/awstats.你的網站.conf created.
-----> Restart Web server with '/sbin/service httpd restart'
停止 httpd: [ 確定 ]
啟動 httpd: [ 確定 ]
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.nauticaltech.o rg
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.你的網站 .conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for '你的網站' with com mand:
> perl awstats.pl -update -config=你的網站
You can also read your statistics for '你的網站' with URL:
> http://localhost/awstats/awstats.pl?config=你的網站
Press ENTER to finish...

以上步驟完成後,會在/etc/awstats目錄下建立一檔案- awstats.你的網站.conf
建立 /var/lib/awstats 目錄,並設定 777權限
#mkdir /var/lib/awstats
#chmod 777 /var/lib/awstats

檢查在httpd.conf中是否有以下設定,並且重新啟動httpd服務
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
Options None
AllowOverride None
Order allow,deny
Allow from all
--------------------------
#service httpd restart
設定httpd的log format為combined,請編輯 httpd.conf,將CustomLog設定為combined
CustomLog logs/access_log combined

設定awstats.你的網站.conf
LogFile="/var/log/httpd/access_log" <----請指定apache log file的絕對路徑及log名稱
LogType=W <---- W分析類型為web log
LogFormat=1 <---- 1代表Apache or Lotus Notes/Domino native combined log format
SiteDomain="你的網站" <----指定定從log檔中過濾符合SiteDomain的記錄(不同的Virtual Domain就須指定為不同的SiteDomain)
HostAliases="你的網站"
設定完畢,請存檔
執行awstats.pl
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=你的網站 -update
如果出現以下訊息,就代表執行成功
Update for config "/etc/awstats/awstats.你的網站.conf"
With data in log file "/var/log/httpd/access_log.1"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 4311)
Jumped lines in file: 251
Found 4311 already parsed records.
Parsed lines in file: 0
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.
開啟瀏覽器,輸入 http://你的網站/awstats/awstats.pl?config=你的網站,便可檢視你剛剛所產生的報表了。
將 /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=你的網站 -update的指令設定在crontab,讓它定期產生產生資料更新

這給大家參考一下 滿有用的

摘自:http://maizao.com/dz/thread-39-1-1.html


補充1:HOW TO ROTATE MY LOGS WITHOUT LOSING DATA

/usr/local/apache/logs/*log
{
notifempty
daily
rotate 7
compress
sharedscripts
prerotate
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mydomainconfig
endscript
postrotate
/usr/bin/killall -HUP httpd
endscript
}


補充2:讓Awstats中搜尋的關鍵字正常顯示的方法!!]
AWStats分析報表中,有關搜尋的關鍵字句會變成亂碼的主因,是因為現在的搜尋引擎都是使用UTF8,而Awstats是使用Big5,所以在顯示上會出現亂碼。

要解決此問題,就是把awstats設定中的LoadPlugin="decodeutfkeys"啟動。就可以了


# Plugin: DecodeUTFKeys
# Perl modules required: Encode and URI::Escape
# Allow AWStats to show correctly (in language charset) keywords/keyphrases
# strings even if they were UTF8 coded by the referer search engine.
#
LoadPlugin="decodeutfkeys"

沒有留言:

wibiya widget