awstats 6.4のインストール(導入メモ)

rpm版をダウンロードしてきてrootでインストール。

[root@nomano work]# rpm -Uvh awstats-6.4-1.noarch.rpm
Preparing... ########################################### [100%]
1:awstats ########################################### [100%]

----- AWStats 6.4 - Laurent Destailleur -----
AWStats files have been installed in /usr/local/awstats

If first install, follow instructions in documentation
(/usr/local/awstats/docs/index.html) to setup AWStats in 3 steps:
Step 1 : Install and Setup with awstats_configure.pl (or manually)
Step 2 : Build/Update Statistics with awstats.pl
Step 3 : Read Statistics

コンフィグは以下の通りに行います。基本的にはデフォルトで進めます。

[root@nomano tools]# perl awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 1.4) (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
Found Web server Apache config file '/usr/local/apache/conf/httpd.conf'
Found Web server Apache config file '/usr/local/apache2/conf/httpd.conf'

(注:すでに今後のmod_perl化、reverse proxy用に apache -> apache1.3, apache2.0 -> apache2と2つ入れてあるために両方を見つけたようです)

-----> Check and complete web server config file '/usr/local/apache2/conf/httpd.conf'
Warning: You Apache config file contains directives to write 'common' log files
This means that some features can't work (os, browsers and keywords detection).
Do you want me to setup Apache to write 'combined' log files [y/N] ? y
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 '' directive
AWStats directives added to Apache config file.

-----> Check and complete web server config file '/usr/local/apache/conf/httpd.conf'
Warning: You Apache config file contains directives to write 'common' log files
This means that some features can't work (os, browsers and keywords detection).
Do you want me to setup Apache to write 'combined' log files [y/N] ? y
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 '' directive
AWStats directives added to Apache config file.

-----> 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:
> nomano.shiwaza.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):
>

-----> Create config file '/etc/awstats/awstats.nomano.shiwaza.com.conf'
Config file /etc/awstats/awstats.nomano.shiwaza.com.conf created.

-----> Restart Web server with '/sbin/service httpd restart'
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]

-----> 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=nomano.shiwaza.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now

現在は/usr/local/apache(apache1.3)を利用。スクリプトでは /etc/init.d/httpdが再起動されていたので、これをstop。
# /etc/init.d/httpd status
# /etc/init.d/httpd stop

combinedのログにするために、httpd再起動(すでにconfファイルは書き変わっていたため)。
# /usr/local/apache/bin/apachectl start (またはrestart)

ログが通常のものと、combineのものとで混じるが、混じったものだと正常に動作しないためにログを強制ローテート
# cd /usr/local/apache/logs

# mv access_log access_log.1
# mv error_log error_log.1
# /bin/kill -HUP `cat /usr/local/apache/logs/httpd.pid 2> /dev/null`

手動でCGIスクリプトを動作させて動作チェック。

[root@nomano logs]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=nomano.shiwaza.com -update
Update for config "/etc/awstats/awstats.nomano.shiwaza.com.conf"
With data in log file "/usr/local/apache/logs/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: 16
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 16 new qualified records.

上記のようになれば成功。

現状のままだと誰でもアクセスが可能なので、アクセスコントロール
まずhttpd.confを.htaccessが利用可能なように変更(詳細省略)

パスワードファイルを作成。これを参照するように .htaccessを記述
# htpasswd -c passwdfile username

サーバー再起動で有効化
# /usr/local/apache/bin/apachectl restart

現状だと検索文字列の日本語が化けるものがでるため、パッチをあてる。

[root@nomano cgi-bin]# diff awstats.pl awstats.pl.org
4280d4279
< use Jcode;
4285d4283
< Jcode::convert(\$stringtodecode, "utf8");

上記のように変更した。