Apacheメモ
Apacheの標準的なインストール
configureスクリプトのヘルプ
ログファイルの分析 wwwstat
ログファイルの分析 Web Statistics
ログファイルの分析 SiteServerExpress 1
ログファイルの分析 SiteServerExpress 2
potatoのインストールと運用
バーチャルホストの設定
wwwstatのインストール
Webサーバの書き出すログファイルを分析するツールとして有名なwwwstatをインストールする。まず、wwwstatをhttp://www.ics.uci.edu/pub/websoft/wwwstat/から入手する。Webブラウザでアクセスすると、次の画面になる。

wwwstatの1999年3月15日時点での最新バ−ジョンは、「2.01」である。配布ファイルは「wwwstat-2.0.tar.gz」で、このファイルにパッチ「patch-2.01.txt」をあてることで、「2.01」になる。両方とも、このサイトからダウンロードする。ダウンロードは、「The wwwstat package is available as a gzip'd tar file via both HTTP and FTP. The distribution consists of the following files: 」という個所の「FTP」をクリックしてFTPでダウンロードしたほうがいいだろう。クリックすると、次の画面になる。

ここでは、ディレクトリの「wwwstat」をクリックする。次の画面になる。

ここに、wwwstatのファイル個々といっしょに圧縮されたファイル「wwwstat-2.0.tar.gz」、パッチ「patch-2.01.txt」があるので、クリックしてダウンロードする。パッチファイルは拡張子が「.txt」になっているので、クリックすると表示されてしまうという場合には、右クリックメニューから「対象をファイルに保存」を選んでダウンロードする。
ダウンロードしたら、ふたつともApacheがインストールされているLinux(にかぎらないが)に転送する。そして解凍。
$ tar zxvf wwwstat-2_0_tar.gz
wwwstat-2.0/
wwwstat-2.0/Changes
wwwstat-2.0/FAQ
wwwstat-2.0/INSTALL
wwwstat-2.0/LICENSE
wwwstat-2.0/Makefile
wwwstat-2.0/README
wwwstat-2.0/domains.pl
wwwstat-2.0/example.html
wwwstat-2.0/monthly.pl
wwwstat-2.0/oldlog2new.pl
wwwstat-2.0/splitlog.1
wwwstat-2.0/splitlog.html
wwwstat-2.0/splitlog.pl
wwwstat-2.0/splitlog.ps
wwwstat-2.0/splitlog.rc
wwwstat-2.0/wwwerrs.pl
wwwstat-2.0/wwwstat.1
wwwstat-2.0/wwwstat.html
wwwstat-2.0/wwwstat.pl
wwwstat-2.0/wwwstat.ps
wwwstat-2.0/wwwstat.rc
「wwwstat-2.0」というディレクトリができ、ファイルが解凍されている。INSTALLがインストールに注意書き。続いてパッチをあてる。
$ cd wwwstat-2.0
$ patch < ../patch-2_01.txt
patching file `Changes'
patching file `wwwstat.pl'
$
makeする。
$ make
cp wwwstat.pl wwwstat
/usr/local/bin/perl -pi -e 's#YOUR_PERL_BINARY#/usr/local/bin/perl#o;' wwwstat
chmod 755 wwwstat
cp wwwerrs.pl wwwerrs
/usr/local/bin/perl -pi -e 's#YOUR_PERL_BINARY#/usr/local/bin/perl#o;' wwwerrs
chmod 755 wwwerrs
cp monthly.pl monthly
/usr/local/bin/perl -pi -e 's#YOUR_PERL_BINARY#/usr/local/bin/perl#o;' monthly
chmod 755 monthly
cp splitlog.pl splitlog
/usr/local/bin/perl -pi -e 's#YOUR_PERL_BINARY#/usr/local/bin/perl#o;' splitlog
chmod 755 splitlog
cp oldlog2new.pl oldlog2new
/usr/local/bin/perl -pi -e 's#YOUR_PERL_BINARY#/usr/local/bin/perl#o;' oldlog2ne
w
chmod 755 oldlog2new
$
原則的にはこれでできあがる「wwwstat」(perlスクリプト)を実行すれば、分析結果ファイルがhtmlファイル形式でできるが、環境によって書きなおさないといけない。
たとえば、分析の対象となるWebブラウザのログファイルのある場所とファイル名を、
$DefaultLog = '/usr/local/etc/httpd/logs/access_log';
に設定する。それともう一箇所、
$AppendToLocalhost = '.no_where.com';
の「.no_where.com」のところに分析対象のWebサーバのドメイン名を入力しておく。ここで入力したものが、タイトルの一部として、
$OutputTitle = 'World Wide Web Access Statistics for www' .
$AppendToLocalhost;
のところで組み合わせて使われる。
以上のほかにも、
$UpdateHeader = 'Last updated: ';
などの行はhtmlファイル中の小見出しにあたるもの。適当に日本語化してもいい。
wwwstatはperlのスクリプトなので、perlのある場所が先頭に、
#!/usr/local/bin/perl
と設定されている。確認しておく。よければ、テスト。
$ ./wwwstat > test.html
エラーが表示されなければ、成功。できあがったhtmlファイルを調べて問題ないことを確認する。以上でインストールは終了だが、実際の運用には工夫がいる。ApacheなどのWebサーバは、定期的にログファイルを切り替えるようになっている。そこで、同じようにwwwstatを自動的に実行するように設定しておくと便利だ。
設定は、「/etc/crontab」に次のようにする。
crontabに
# Run any at jobs every minute
* * * * * root [ -x /usr/sbin/atrun ] && /usr/sbin/atrun
とあるが(RedHat5.xにはない)、ここに、
0 0 * * * root /xxxxx/xxxxxx/wwwstat-2.0/wwwstat > /xxxxx/wwwstat.html
と書いておくと、wwwstatが毎日0時0分になると自動的に実行される。ただし、ログの切り替えは、多くの場合、月曜日になってしばらくしたとき(真夜中)に自動的に行なわれ、月曜日になるとwwwstatの分析対象となるログが切り替わってしまい、そのため、空っぽのログを対象にしたwwwstat.htmlが上書きされてしまうのだ。そこで、時間をずらして1週間に1回wwstat.htmlをコピーするようにしておく。
2 0 * * 0 root cp /xxxxx/wwwstat.html /xxxxx/temp.html
これで、1週間はtemp.htmlという名前で保存されていることになる。
もう少し工夫して、日付を名前に使って保存するようにするには、シェルスクリプトを使って、
#!/bin/sh
set `date +%y%m%d`
cp /xxxxxx/temp.html /xxxxx/$1.html
という内容の「wwwstat.sh」というような名前のファイルを別に作り(chmod 700などして実行権を与えておく)、crontabに
10 0 * * 0 oohashi /xxxxx/wwwstat.sh > /dev/null 2>&1
としておく。こうすると「010401.html」(2001年4月1日)というように日付にもとづいた名前で、毎日曜日の0時10分に、ユーザoohashiの権限で、temp.htmlがコピー保存されるようになる。「`」は「'」(キーボードの「7」の上にあるもの)ではなく、「@」キーの上にある「`」。dateコマンドでは、「+%y%m%d」で出力形式を「西暦の2桁」「01などの2桁の月」「01などの2桁の日」としている。形式を変更したいときはdateコマンドのヘルプ(date --help)を参考に。
$ date --help
Usage: date [OPTION]... [+FORMAT]
or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.
-d, --date=STRING display time described by STRING, not `now'
-f, --file=DATEFILE like --date once for each line of DATEFILE
-I, --iso-8601[=TIMESPEC] output an ISO-8601 compliant date/time string.
TIMESPEC=`date' (or missing) for date only,
`hours', `minutes', or `seconds' for date and
time to the indicated precision.
-r, --reference=FILE display the last modification time of FILE
-R, --rfc-822 output RFC-822 compliant date string
-s, --set=STRING set time described by STRING
-u, --utc, --universal print or set Coordinated Universal Time
--help display this help and exit
--version output version information and exit
FORMAT controls the output. The only valid option for the second form
specifies Coordinated Universal Time. Interpreted sequences are:
%% a literal %
%a locale's abbreviated weekday name (Sun..Sat)
%A locale's full weekday name, variable length (Sunday..Saturday)
%b locale's abbreviated month name (Jan..Dec)
%B locale's full month name, variable length (January..December)
%c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
%d day of month (01..31)
%D date (mm/dd/yy)
%e day of month, blank padded ( 1..31)
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%p locale's AM or PM
%r time, 12-hour (hh:mm:ss [AP]M)
%s seconds since 00:00:00, Jan 1, 1970 (a GNU extension)
%S second (00..60)
%t a horizontal tab
%T time, 24-hour (hh:mm:ss)
%U week number of year with Sunday as first day of week (00..53)
%V week number of year with Monday as first day of week (01..52)
%w day of week (0..6); 0 represents Sunday
%W week number of year with Monday as first day of week (00..53)
%x locale's date representation (mm/dd/yy)
%X locale's time representation (%H:%M:%S)
%y last two digits of year (00..99)
%Y year (1970...)
%z RFC-822 style numeric timezone (-0500) (a nonstandard extension)
%Z time zone (e.g., EDT), or nothing if no time zone is determinable
By default, date pads numeric fields with zeroes. GNU date recognizes
the following modifiers between `%' and a numeric directive.
`-' (hyphen) do not pad the field
`_' (underscore) pad the field with spaces
Report bugs to <bug-sh-utils@gnu.org>.
|