Webサーバ用ログ解析ツールのAWStatsをMac OS Xにインストールしたときの作業メモ.
動作環境など
- ApacheはMac OS X付属のものを利用 (MacPorts版ではない)
- MacPortsは使わずソースからインストール
- インストール先は/Library/Webserver/awstats-7.0
- AWStatsの統計情報のURLはhttp://example.com/awstats
Apacheのログ出力設定の変更
Mac OS X付属Apacheのアクセスログはデフォルトでcommon形式となっているが,AWStatsでApacheのログを解析するには出力形式をcommonからcombinedに変更する必要がある.
$ sudo vim /etc/apache2/httpd.conf
- CustomLog "/private/var/log/apache2/access_log" common + CustomLog "/private/var/log/apache2/access_log" combined
common形式のログとcombined形式のログが同じファイルに混ざるとAWStatsで解析できないので,新しくログファイルを作り直す.
$ cd /var/log/apache2 $ sudo /usr/sbin/apachectl stop $ sudo mv access_log access_log.bak $ sudo /usr/sbin/apachectl start
なお,Mac OS X 10.6.5以降のApacheだとapachectl実行時に以下のエラーが表示されることがある.これはこちらの方法で解消できる(かも).
/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument
ソースのダウンロード・展開とディレクトリの配置
ここからソースをダウンロードして展開・設置する.
$ wget 'http://downloads.sourceforge.net/project/awstats/AWStats/7.0/awstats-7.0.tar.gz?r=http%3A%2F%2Fawstats.sourceforge.net%2F&ts=1294972864&use_mirror=jaist' $ tar zxvf awstats-7.0.tar.gz $ sudo mv awstats-7.0 /Library/Webserver
awstats_configure.plによる設定
awstats_configure.plを使うと対話的に初期設定を行うことができて便利.実行にはroot権限が必要.
$ cd /Library/Webserver/awstats-7.0/tools $ sudo perl awstats_configure.pl ----- AWStats awstats_configure 1.0 (build 1.9) (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).
AWStatsのディレクトリが標準の場所でない場合は最初にWarningが出てくる.Yesと答えて問題ない.
-----> Running OS detected: Mac OS Warning: AWStats standard directory on Mac OS X is '/Library/WebServer/awstats'. If you want to use standard directory, you should first move all content of AWStats distribution from current directory: /Library/WebServer/awstats-7.0 to standard directory: /Library/WebServer/awstats And then, run configure.pl from this location. Do you want to continue setup from this NON standard directory [yN] ? y
AWStatsを動かすApacheのhttpd.confのパスを入力する.
-----> 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
必要なAliasや
-----> Check and complete web server config file '/etc/apache2/httpd.conf' Add 'Alias /awstatsclasses "/Library/WebServer/awstats-7.0/wwwroot/classes/"' Add 'Alias /awstatscss "/Library/WebServer/awstats-7.0/wwwroot/css/"' Add 'Alias /awstatsicons "/Library/WebServer/awstats-7.0/wwwroot/icon/"' Add 'ScriptAlias /awstats/ "/Library/WebServer/awstats-7.0/wwwroot/cgi-bin/"' Add '<Directory>' directive AWStats directives added to Apache config file. -----> Update model config file '/Library/WebServer/awstats-7.0/wwwroot/cgi-bin/awstats.model.conf' File awstats.model.conf updated.
新しい設定ファイルを作るかどうか.AWStatsを初めてインストールするのでYesにする.
-----> 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: > example.com
設定ファイルの生成,Apacheの再起動が行われる
-----> Create config file '/Library/WebServer/awstats-7.0/wwwroot/cgi-bin/awstats.example.com.conf' Config file /Library/WebServer/awstats-7.0/wwwroot/cgi-bin/awstats.example.com.conf created. -----> Restart Web server with '/usr/sbin/apachectl restart'
awstats_configure.plがcronに統計情報のアップデート処理を自動登録しようとするが失敗.後でメッセージにある通りに手動でcronに登録する.
-----> 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: /Library/WebServer/awstats-7.0/wwwroot/cgi-bin/awstats.pl -update -config=example.com Or if you have several config files and prefer having only one command: /Library/WebServer/awstats-7.0/tools/awstats_updateall.pl now Press ENTER to continue...
自動生成された設定ファイルを確認しろよ〜などのメッセージが表示されて終了.
A SIMPLE config file has been created: /Library/WebServer/awstats-7.0/wwwroot/cgi-bin/awstats.example.com.conf You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'example.com' with command: > perl awstats.pl -update -config=example.com You can also read your statistics for 'example.com' with URL: > http://localhost/awstats/awstats.pl?config=example.com Press ENTER to finish...
設定ファイルの確認と編集
自動生成された設定ファイルを確認し,必要があれば修正する.
$ sudo vim /Library/WebServer/awstats-7.0/wwwroot/cgi-bin/awstats.example.com.conf
# Apacheのログファイルへのパスを修正 - LogFile="/var/log/httpd/mylog.log" + LogFile="/var/log/apache2/access_log"
テスト実行
コマンドラインから統計情報を更新してみる.
$ cd ../wwwroot/cgi-bin $ sudo awstats.pl -update -config=example.com Error: AWStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable. Setup ('wwwroot/cgi-bin/awstats.example.com.conf' file, web server or permissions) may be wrong. Check config file, permissions and AWStats documentation (in 'docs' directory).
AWStatsの統計情報を保存するディレクトリが存在しなかったので作成して再実行.
$ sudo mkdir /var/lib/awstats $ sudo wwwroot/cgi-bin/awstats.pl -update -config=example.com Create/Update database for config "wwwroot/cgi-bin/awstats.example.com.conf" by AWStats version 7.0 (build 1.971) From data in log file "/var/log/apache2/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: 267 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 267 new qualified records.
エラーが出なければOK.
Webブラウザでアクセス
ブラウザでAWStatsにアクセスして動作を確認する.
http://example.com/awstats/awstats.pl?config=example.com
無事統計情報が表示されればインストール完了.
cronに登録
cronを使って統計情報を定期的に自動更新させるようにする.
$ sudo crontab -e
# 6時間ごとに統計情報を更新 0 */6 * * * /Library/WebServer/awstats-7.0/wwwroot/cgi-bin/awstats.pl -update -config=example.com
以上.
参考資料
公式サイトのインストールドキュメントはこちら.
Mac OS X付属のApache + MacPortsのAWStatsとしたい場合は以下のサイトが参考になりそう.