wget http://nchc.dl.sourceforge.net/sourceforge/awstats/awstats-6.9.tar.gz
tar zxvf awstats-6.9.tar.gz
mv awstats-6.9/ /usr/local/
cd /usr/local/awstats-6.9/tools/
./awstats_configure.pl
Do you want to continue setup from this NON standard directory [yN] ?
y
Config file path ('none' to skip web server setup):
>none
file (required if first install) [y/N] ?
y
Example: demo
Your web site, virtual server or profile name:
>test.openx.cn
-----> 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)
vim /etc/awstats/awstats.test.openx.cn.conf
替換下面配置:
LogFile="/home/wwwlogs/access_%YYYY-24%MM-24%DD-24.log"
三,開始分析、產生結果
最後,可以執行分析了。
使用這個命令:
/usr/local/awstats-6.9/tools/wwwroot/cgi-bin/awstats.pl -update -config=test.openx.cn
這個命令會把結果產生到/var/lib/awstats 目錄下 awstatsXXXX.www.XXXX.com.txt檔案。
當然這樣看起來不太方便,可以再用下面的命令來產生html頁面,更加直觀。
/usr/local/awstats-6.9/tools/awstats_buildstaticpages.pl -update -config=test.openx.cn -lang=cn -dir=/data/awstats -awstatsprog=/usr/local/awstats-6.9/wwwroot/cgi-bin/awstats.pl
/usr/local/awstats-6.9/tools/awstats_buildstaticpages.pl -update \
-config=www.xxxxoke.com -lang=cn \
-dir=/html/awstats \
-awstatsprog=/usr/local/awstats-6.9/tools/wwwroot/cgi-bin/awstats.pl
這樣就會在/html/awstats目錄下產生很直觀的分析結果頁。
四,自動化
要是每天都去伺服器上運行幾條命令肯定是件令人煩燥的事情,幸虧Linux的世界裡有crontab,
下面是從網友那找的 crontab
1 0 * * * sh /home/zyf/sh/cut_nginx_log.sh
0 1 * * * /usr/local/awstats-6.9/wwwroot/cgi-bin/awstats.pl -update -config=www.xxxxke.com
0 2 * * * /usr/local/awstats-6.9/tools/awstats_buildstaticpages.pl -update -config=www.xxxxke.com -lang=cn -dir=/html/awstats -awstatsprog=/usr/local/awstats-6.9/tools/wwwroot/cgi-bin/awstats.pl
LogFile="/home/wwwlogs/access_%YYYY-24%MM-24%DD-24.log"
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';