awstats 線上web服務器訪問統計

awstats 強大的線上web服務器訪問統計
suse  11  

165738939.jpg一 安裝awstats.
#zypper in httpd
#cd /srv/www/htdocs
#chown -R wwwrun:www *
修改/etc/apache2/httpd.conf 如下字段:
<Directory "I:/build/dist">
#開啓目錄列表索引模式
Options Indexes
Order allow,deny
IndexOptions NameWidth=25 Charset=UTF-8
Allow from all
</Directory>

<Directory />
   Options Indexes FollowSymLinks
   AllowOverride None
   Order deny,allow
   Allow from all
</Directory>

修改/etc/apache2/default-server.conf:
DocumentRoot "/media/sources"
<Directory "/media/sources">
       Options All
       AllowOverride None
       Order allow,deny
       Allow from all
</Directory>
啓動http服務:
#/etc/init.d/apache2 restart

1. 安裝包下載地址:http://awstats.sourceforge.net/

2. 上傳awstats-7.0.tar.gz到/usr/local目錄下。

3. 賦予執行權限。
#chmod +x awstats-7.0.tar.gz
4. 解壓文件。
#tar zxvf awstats-7.0.tar.gz

5. 解壓完後會生成awstats7.0文件夾,包含docs README.TXT tools wwwroot。

6. 將awstats7.0重命名爲awstats
#mv awstats7.0 awstats

7. 運行腳本生成awstats的配置文件.
#cd /usr/local/awstats/tools
#perl awstats_configure.pl

8. 配置過程.
-----> 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/apache2/httpd.conf  //apache配置文件位置
-----> 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 '<Directory>' directive
AWStats directives added to Apache config file.
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.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
2
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.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.com www.test.com //輸入網站域名
-----> 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):
>Enter //回車使用默認的配置/etc/awstats(最好使用默認配置,否則會出現很多意想不到的錯誤)
-----> 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.www.test.com.conf' //生成awstats的配置文件,注意路徑和文件名
Config file /etc/awstats/awstats.www.test.com.conf created.
-----> Restart Web server with '/sbin/service httpd restart'
httpd: apr_sockaddr_info_get() failed for test
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Stopping httpd: [ OK ]
Starting httpd: [ OK ] //重啓apache
-----> 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.test.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.www.test.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.test.com' with command:
> perl awstats.pl -update -config=www.test.com
You can also read your statistics for 'www.test.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.test.com
Press ENTER to finish...
配置完成。


二 編輯配置文件

9. 編輯awstats配置文件
#vi /etc/awstats/awstats.www.test.com.conf
更改如下配置
LogFile=/var/log/apache2/access_log
設置apache的logfile位置,一定要保證和httpd.conf中的log文件保證一致,httpd.conf中log名稱爲CustomLog logs/access_log combined
LogType=W
設置要分析的服務日誌類型,W表示爲WEB日誌
LogFormat=1
設置日誌格式,1表示採用NCSA apache combined/ELF/XLF log format
SiteDomain="www.test.com"
設置所要分析網站域名 ,引號中一定要填上域名,或者服務器主機名
DirData="/usr/local/awstats/data"
設置awstats的數據庫存放目錄

三 創建數據庫文件
10. 創建數據庫存放目錄
#mkdir -p /usr/local/awstasts/data
#chmod -R 755 /usr/local/awstasts/data
11. 更改腳本權限
#chmod 755 /usr/local/awstats/wwwroot/cgi-bin/*.pl
12. 創建awstats初始化數據庫
#cd /usr/local/awstats/wwwroot/cgi-bin
#./awstats.pl -update -config=www.test.com
13. 執行成功會顯示如下信息
Create/Update database for config "/etc/awstats/awstats.www.test.com.conf" by AWStats version 7.0 (build 1.971)
From data in log file "/etc/httpd/logs/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 0
Found 0 dropped records,
4
Found 0 comments,
Found 0 blank records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.
14. 執行過程中可能會遇到錯誤:日誌的格式不匹配
解決方式:刪掉access_log,重新啓動apache,會在相應位置再次生成access_log
四 創建頁面文件
15. 創建awstats文件夾
#cd /var/www/html
#mkdir awstats
16. 執行awstats_buildstaticpages.pl腳本,生成頁面文件
#cd /usr/local/awstats/tools/
#./awstats_buildstaticpages.pl -update -config=www.test.com -lang=cn -dir=/srv/www/htdocs/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
執行成功會顯示如下信息
Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -update -configdir=
Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output
Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=alldomains
Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=allhosts
Build lasthosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=lasthosts
Build unknownip page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl"
5
-config=www.test.com -staticlinks -lang=cn -output=unknownip
Build allrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=allrobots
Build lastrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=lastrobots
Build session page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=session
Build urldetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=urldetail
Build urlentry page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=urlentry
Build urlexit page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=urlexit
Build osdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=osdetail
Build unknownos page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=unknownos
Build browserdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=browserdetail
Build unknownbrowser page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=unknownbrowser
Build refererse page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=refererse
Build refererpages page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=refererpages
Build keyphrases page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=keyphrases
Build keywords page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl"
6
-config=www.test.com -staticlinks -lang=cn -output=keywords
Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=errors404
20 files built.
Main HTML page is 'awstats.www.test.com.html'.
18. 設置awstats文件夾權限
#chmod -R 755 /var/www/html/awstats

五 添加定期執行腳本
19. 加入定期執行腳本,每分鐘更新一次
#crontab -e
*/1 * * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.test.com -update
20. 查看主頁流量分析
http://www.test.com/awstats/awstats.pl?config=www.test.com

如果遇到訪問拒絕錯誤,請確認awstats目錄及其所含文件的權限,
關閉selinux並重啓系統。

六 爲awstats加入認證功能
//創建存放密碼的目錄
#mkdir –p /etc/httpd/password
//生成密碼文件,用戶名:admin
#cd /usr/bin
#./htpasswd -c /etc/httpd/password/passwords admin
New password: 輸入密碼
Re-type new password: 再次輸入密碼
7
Adding password for user admin
//在文件/etc/httpd/conf/httpd.conf,加入如下紅字內容
<Directory "/usr/local/awstats/wwwroot">
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/httpd/password/passwords
Require user admin
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章