2008/09/18

[ FBSD ] FreeBSD install AWStats to Analysis Mail and Web log

如何在 FreeBSD 安裝 AWStats 統計分析軟體?

1. 安裝 AWStats

# cd /usr/ports/www/awstats # 使用 ports 安裝 awstats
# make install clean

# vi /usr/loca/eta/apache/httpd.conf # 在已裝好的 Apache 中增加下面設定

Alias /awstatsclasses "/usr/local/www/awstats/classes/"
Alias /awstatscss "/usr/local/www/awstats/css/"
Alias /awstatsicons "/usr/local/www/awstats/icons/"
ScriptAlias /awstats/ "/usr/local/www/awstats/cgi-bin/"

<Directory "/usr/local/www/awstats/">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>


# apachectl restart # 重啟 Apache

# vi /usr/local/www/awstats/tools/awstats_configure.pl # 查看設定檔目錄
# mkdir /var/lib/awstats # 建立存放分析完後的 log 目錄
# chmod 777 /var/lib/awstats # 改變目錄權限
# cp /usr/local/www/awstats/cgi-bin/awstats.model.conf /etc/awstats/ # Copy 設定檔範例

2. 分析統計 Postfix 的 Maillog

# /usr/local/www/awstats/tools/awstats_configure.pl # 手動建立 maillog 設定檔

----- 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
Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/var/log
to standard directory:
/usr/local/awstats
And then, run configure.pl from this location.
Do you want to continue setup from this NON standard directory [yN] ? y

-----> 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

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 '/etc/awstats/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
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:
> mail.ntut.idv.tw

-----> 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

-----> Create config file '/etc/awstats/awstats.mail.ntut.idv.tw.conf'
Config file /etc/awstats/awstats.mail.ntut.idv.tw.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:
/var/log/wwwroot/cgi-bin/awstats.pl -update -config=mail.ntut.idv.tw
Or if you have several config files and prefer having only one command:
/var/log/tools/awstats_updateall.pl now
Press ENTER to continue... ENTER

A SIMPLE config file has been created: /etc/awstats/awstats.mail.ntut.idv.tw.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'mail.ntut.idv.tw' with command:
> perl awstats.pl -update -config=mail.ntut.idv.tw
You can also build static report pages for 'mail.ntut.idv.tw' with command:
> perl awstats.pl -output=pagetype -config=mail.ntut.idv.tw

Press ENTER to finish... ENTER

# vi /etc/awstats/awstats.mail.ntut.idv.tw.conf # 修改 maillog 設定檔格式

LogFile="bzip2 -cd /var/log/maillog.0.bz2 | /usr/local/www/awstats/tools/maillogconvert.pl standard |"
LogType=M
LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"
Lang="tw"

# /usr/local/www/awstats/cgi-bin/awstats.pl -config=mail.ntut.idv.tw -update # 手動執行 maillog 分析及更新
Create/Update database for config "/etc/awstats/awstats.mail.ntut.idv.tw.conf" by AWStats version 6.8 (build 1.910)
From data in log file "perl /usr/local/www/awstats/tools/maillogconvert.pl standard < /var/log/maillog |"...
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)...
Jumped lines in file: 0
Parsed lines in file: 109
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 109 new qualified records.

直接查看統計報表: http://Host-IP/awstats/awstats.pl?config=mail.ntut.idv.tw

3. 分析統計 Apache Web log

# /usr/local/www/awstats/tools/awstats_configure.pl # 手動建立欲分析之 log 設定檔

# vi /etc/awstats/awstats.www.ntut.idv.tw.conf # 修改剛才建立之設定檔

LogFile="zcat < /var/log/httpd-access.log.0.bz2 |"
LogType=W
LogFormat=1
Lang="tw"

# /usr/local/www/awstats/cgi-bin/awstats.pl -config=www.ntut.idv.tw -update # 手動更新統計
Create/Update database for config "/etc/awstats/awstats.www.ntut.idv.tw.conf" by AWStats version 6.8 (build 1.910)
From data in log file "/var/log/httpd-access.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)...
Jumped lines in file: 0
Parsed lines in file: 1542
Found 0 dropped records,
Found 1248 corrupted records,
Found 0 old records,
Found 294 new qualified records.

http://Host-IP/awstats/awstats.pl?config=www.ntut.idv.tw # 開個瀏覽器查看流量統計

# crontab -e # 新增 crontabe每天 12 點 55 分去分析統計前一天的 log
55 0 * * * /usr/local/www/awstats/tools/awstats_updateall.pl now > /dev/null 2>&1

0 意見: