軟件下載地址:http://awstats.sourceforge.net/
我下載的是穩定版本awstats-6.95.tar.gz
先上傳下載文件到服務器上我習慣放在/opt下面
1、解壓軟件包:
tar zxvf awstats-6.95.tar.gz
而後放到/usr/local/下面
mv awstats-6.95 /usr/local/awstats
2、接着執行 tools 目錄中的 awstats_configure.pl 配置嚮導,建立一個新的統計
[root@www tools]# perl 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 files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
>none #由於是分析nginx日誌
Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)
-----> 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 # 沒有發現web 配置文件建立一個 選擇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:
>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):
> # 默認的配置文件路徑/etc/awstats回車便可
-----> Create config file '/etc/awstats/awstats.www.test.com.conf'
Config file /etc/awstats/awstats.www.test.com.conf created.
-----> 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 build static report pages for 'www.test.com' with command:
> perl awstats.pl -output=pagetype -config=www.test.com
Press ENTER to finish...
安裝配置完成
3、編輯配置文件/etc/awstats/awstats.www.test.com.conf
找到LogFile="/var/log/httpd/mylog.log"
修改爲nginx日誌文件的正確位置
LogFile="/var/log/nginx/test.com.acc.log"
保存,退出。
4、修改Nginx 日誌文件生成格式一適應awstats的須要
標紅部分 注意:格式必定要注意,不能多一個空格,或少一個空格,不然在後面更新的時候會報告日誌格式錯誤(這個問題浪費了我一天的時間)
http {
client_header_buffer_size 16k;
large_client_header_buffers 4 64k;
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
server {
listen 80;
server_name www.test.com;
access_log /var/log/nginx/test.com.acc.log main;html
保存後重啓Nginxnginx
因爲在配置日誌分析以前網站已經運行了一段時間,因此我得把線有的日誌給清除掉,由於格式不匹配
Cat /dev/null > /var/log/nginx/test.com.acc.log
如今多刷幾回網站有了日誌記錄就好了
5、如今手動運行統計腳本:(添加到cron 任務中)
[root@www cgi-bin]#perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com
Create/Update database for config "/etc/awstats/awstats.www.test.com.conf" by AWStats version 6.95 (build 1.943)
From data in log file "/var/log/nginx/test.com.acc.log "...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 1348)
Jumped lines in file: 1348
Found 1348 already parsed records.
Parsed lines in file: 798
Found 0 dropped records,
Found 9 corrupted records,
Found 0 old records,
Found 789 new qualified records.
出現上面的輸出,表示徹底沒問題能夠繼續。
若是Nginx日誌格式不對就會報錯:以下:
This means each line in your web server log file need to have "combined log format" like this:
111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] "GET / HTTP/1.1" 200 1234 "http://www.fromserver.com/from.htm" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
And this is an example of records AWStats found in your log file (the record number 50 in your log):
220.181.27.12 - - [08/Jul/2010:04:06:32 +0800] HEAD /yiyou/27/pages/2930.swf HTTP/1.0 "200" 0 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "-"
Setup ('/etc/awstats/awstats.www.test.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).
6、都說nginx對cgi支持不是很好,我在此也就不寫關於cgi的配置了
Awstats能夠輸出靜態html格式的文件,並且靜態頁面仍是很低碳的啊,哈哈! (添加到計劃任務中)
[root@wwwcgi-bin]#perl/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.test.com -lang=cn -dir=/var/www/html -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
#這個腳本命令就是輸出靜態格式的html 頁面 -lang=cn語言,固然是中文了,-dir=/var/www/html 輸出文件的路徑。web
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
………忽略後面輸出
這時候能夠配置Nginx訪問那些靜態頁面了
http://www.test.com/awstats.www.test.com.html
訪問認證的配置網上也有不少,在這裏就免去了
到這裏也就差很少完事了!
7、在網上看到了一篇關於顯示IP地址地區的配置,在此次我也添加進去了,還不錯! :)apache
(感謝那些爲互聯網作出貢獻的人!感謝這位做者!)
具體方法:
1. 首先下載插件(qqhostinfo.pm)。把它放在、/usr/local/awstats/wwwroot/cgi-bin/plugins中。
2. 下載分析QQWry.dat的perl腳本(qqwry.pl)。放在同一目錄。
3. 修改,qqwry.pl中:
./QQWry.Dat 修改成 ${DIR}/plugins/QQWry.Dat
4. 去網上下載QQWry.Dat放在同一目錄中 下載(http://www.cz88.net/fox/),注意文件名必定要是QQWry.Dat
5. 編輯你得awstats配置文件,大概在LoadPlugin="hostinfo"的後面增長一行
LoadPlugin="qqhostinfo"
從新運行上面第5、六步。
服務器
常見錯誤解決:
1、AWStats搜索關鍵詞中文出現亂碼解決辦法
1. 修改站點配置文件awstats.www.test.com.conf
把LoadPlugin=」decodeutfkeys」前邊的#去掉
2. 安裝Perl模塊
2、[root@www nginx]#cpan
cpan> install Encode
cpan> install URI::Escape
從新運行上面第5、六步。
本文完!
app