歡迎您光臨本站 註冊首頁

完整安裝配置awstats的方法(V0.5版)

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

完整安裝配置awstats的方法(V0.5版)

作者:蘇小勇
http://www.bestunix.net

關鍵詞: awstats 日誌分析

說明:下面的完全安裝步驟幾乎完全是按照文檔一步步來的,並沒什麼新意,但我在網上搜了一下,這樣的操作說明還算是獨一無二的了,謹以此文獻給跟我一樣菜的菜鳥們。本文還不太成熟,有什麼問題歡迎大家反饋。轉載請保留作者聯繫信息,謝謝。

首先,去http://awstats.sourceforge.net/下載awstats的安裝包,解壓縮該包,並把它複製到你希望安裝的位置,awstats默認讓你安裝到/usr/local/awstats下面,當然你也可以安裝到別的地方,不過這樣的話系統會讓你確認安裝的路徑。我們這裡以安裝到/usr/local/awstats為例。
另外,awstats要求將http.conf中的CustomLog /yourlogpath/yourlogfile common 改為
CustomLog /yourlogpath/yourlogfile combined ,我看了一下,我默認的就是combined,可能現在新版本默認的都是這個吧,那就不用改了。
一切準備妥當以後,我們就開始安裝了,先進入/usr/local/awstats/tools里,運行awstats_configure.pl啟動安裝嚮導,步驟如下
# ./awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 1.3) (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  #輸入你httpc.conf的路徑,對於httpd2系列的一般都在/etc/httpd/conf/這個目錄下面
這裡將awstats的配置信息直接寫入了httpd.conf
----->; Check and complete web server config file '/etc/httpd/conf/httpd.conf'
  Add '<Directory>;' directive
  AWStats directives added to Apache config file.

根據上面的httpd配置,更新了awstats.model.conf的內容,下面的.conf文件都要根據這個生成。

----->; Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
  File awstats.model.conf updated.
下面問你是否要創建一個新的配置文件,我們當然要創建了,否則裝awstats幹什麼呀。選y沒說的。
----->; Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) ? y

下面是要生成conf文件的名稱了,因為conf文件的名稱都是awstats.yourdomainname.conf格式的,所以這裡要求你輸入你要監測的域名,其實這個域名只是與其他域名相區分的,並不一定非要真實的。我這裡輸入的是www.bestunix.net
----->; 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:
>; www.bestunix.net

下面是讓你輸入配置文件的路徑,直接回車就可以了,當然你也可以自己定義
----->; 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):
>; /etc/awstats

好了,現在就在/etc/awstats下面創建了你定義的配置文件,這裡是awstats.www.bestunix.net.conf
----->; Create config file '/etc/awstats/awstats.www.bestunix.net.conf'
Config file /etc/awstats/awstats.www.bestunix.net.conf created.

創建完配置文件以後會自動重啟httpd服務。
----->; 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.bestunix.net
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.www.bestunix.net.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.bestunix.net' with command:
>; perl awstats.pl -update -config=www.bestunix.net
You can also read your statistics for 'www.bestunix.net' with URL:
>; http://localhost/awstats/awstats.pl?config=www.bestunix.net

Press ENTER to finish...

剩下的工作我們就需要手工完成了。
第一,        在crontab裏手工加進去
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.bestunix.net,因為這個程序是通過分析日誌來進行流量統計的,如果你的日誌文件很大的話是很耗系統資源的。還好,我的流量不大,我設定的是每個小時運行一次,你如果伺服器比較繁忙的話也可以每天夜裡運行一次。當然你也可以手工運行上面的命令來進行更新統計信息。
第二,conf文件的配置:

LogFile
指定你要分析的日誌文件,默認是/var/log/httpd/mylog.log,可以根據你的需要調整,如果你要分析httpd的全部日誌的就是/var/log/httpd/access_log,我們一般就選這個了。

LogType
log類型,默認是web log,不用修改,如果你不是的話就自己照說明改了。

LogFormat
log格式,一般情況下如果是apache的話就是1,iis就是2,默認不用修改,你也可以照說明自定義,呵呵,我還不太清楚怎麼定義。

LogSeparator
log中的分隔符,默認不用修改,如果上面的格式是你自定義的話這裡也要修改了

DNSLookup
默認不用修改

DirData
生成的日誌分析結果的保存路徑,默認是/var/lib/awstats,你如果要使用默認的路徑的話,這個目錄是需要手工創建的,注意這個路徑必須是可讀寫的。
下面四項都是在配置時,不用修改。

DirCgi cgi的路徑,這裡都是相對於網站根目錄的絕對路徑
DirIcons icon的路徑
SiteDomain 域名:www.bestunix.net
HostAliases 主機別名

AllowToUpdateStatsFromBrowser
下面這項是是否允許從瀏覽器里更新統計文件,默認是0不允許,如果我們改為1的話,就需要apache的屬主用戶對/var/lib/awstats目錄有讀寫許可權,並對/var/log/httpd目錄有讀取許可權

AllowFullYearView

這個不用修改默認值。awstats默認是以月為單位進行日誌分析,如果我們要分析整年的日誌的可以在這裡設置,因為分析整年的日誌的話可能要消耗很多系統資源。如果你需要對年日誌進行分析的話,建議手工啟動。

這樣最基本的配置就完成了,我們可以通過http://www.bestunix.net awstats/awstats.pl?config=www.bestunix.net來查看統計信息。



常見問題:

問題一,在第一次進行日誌分析時候就出錯了
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.bestunix.net
Error: AWStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable.
Setup ('/etc/awstats/awstats.www.bestunix.net.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).
這個是因為在/etc/awstats/awstats.www.bestunix.net.conf中DirData中定義的目錄啟動apache的用戶沒有寫得許可權,更改目錄或更改許可權都可以解決。
問題二,出來的頁面里所有的流量統計都是空的。
同樣是/etc/awstats/awstats.www.bestunix.net.conf的問題,在這個文件里有一行
LogFile="/var/log/httpd/mylog.log"
我們一般情況下把這個路徑改為」/var/log/apache/access.log」就可以了,如果你設了很多虛擬主機,每個主機都配置了不同的log的話,在這裡指定你要統計的那個主機的log文件就可以了。
問題三,瀏覽頁面時提示沒有許可權,出現403錯誤,如下
Forbidden
You don't have permission to access /awstats/awstats.pl on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request
因為/usr/local/awstats這個目錄默認屬主是root,其他用戶沒有執行的許可權,我把這個目錄的許可權改為755就可以了。但是理論上應該只需要改wwwroot的許可權就可以了,很奇怪。

更改默認的index文件,默認是index.html,我們可以根據自己的需要修改,比如我改為了
DefaultFile="index.html index.php index.htm"
《解決方案》

完整安裝配置awstats的方法(V0.5版)

好,支持!
《解決方案》

完整安裝配置awstats的方法(V0.5版)

問題三,瀏覽頁面時提示沒有許可權,出現403錯誤,如下
代碼:
Forbidden
You don't have permission to access /awstats/awstats.pl on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request

因為/usr/local/awstats這個目錄默認屬主是root,其他用戶沒有執行的許可權,我把這個目錄的許可權改為755就可以了。但是理論上應該只需要改wwwroot的許可權就可以了,很奇怪。


我把awstats包括子目錄和文件都改成755還是不行,還是這個提示
《解決方案》

我的把awstats整個目錄設置成755就可以了啊
《解決方案》

好文章,是原創嗎?
轉貼到我的論壇上去:mrgreen:
《解決方案》

請教問題,

如果你設了很多虛擬主機,每個主機都配置了不同的log的話,在這裡指定你要統計的那個主機的log文件就可以了。


你好!我按照你的 前步都裝好了。就是到 虛擬主機這塊卡住了。能具體說下嗎?比如我有 www.home.com 這個虛擬主機改在哪 設置啊?是在虛擬主機設置里,還是還在awstats的配置文件里啊?
《解決方案》

原帖由 gron 於 2008-8-4 20:56 發表 http://bbs.chinaunix.net/images/common/back.gif
如果你設了很多虛擬主機,每個主機都配置了不同的log的話,在這裡指定你要統計的那個主機的log文件就可以了。


你好!我按照你的 前步都裝好了。就是到 虛擬主機這塊卡住了。能具體說下嗎?比如我有 www.h ...
http://bbs.chinaunix.net/viewthread.php?tid=641101&highlight=awstats
《解決方案》

:P :P
《解決方案》

回復 #1 sxybit 的帖子

你好朋友:

我統計比較大一點的日誌,大約600M的日誌是出現下面提示:

From data in log file "/opt/nfs2/svrlog/case0801-09/all/case0801.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)...
Flush history file on disk (unique url reach flush limit of 5000)
Flush history file on disk (unique url reach flush limit of 5000)
Flush history file on disk (unique url reach flush limit of 5000)

哪位朋友 遇到過這個問題啊?請賜教!我的QQ  158863748 MSN: arong521@hotmail.com

[火星人 ] 完整安裝配置awstats的方法(V0.5版)已經有1026次圍觀

http://coctec.com/docs/service/show-post-28158.html