VineLinuxパフォーマンスアッププロジェクト:0148
■Webalizerをインストールしてみよう!■
Webサーバを運用する際につきものなのがアクセス解析。アクセス解析ソフトはいろいろあります。以前、そのうちの1つとしてAnalogをインストールしてみよう!を紹介しましたが今回はもう1つ有名なWebalizerのインストール方法を紹介したいと思います。
※ここでは事前にApache Webサーバがインストールされており、ドキュメントルートディレクトリが/home/httpd/html以下になっていることが前提となっています。
▼Webalizerのインストールと設定
WebalizerはVineLinuxではVinePlusにて提供されていますので、インストールは簡単です。rootユーザ権限で
apt-get install webalizer
と実行するか直接パッケージをダウンロードしてrpmコマンドでインストールしてください。
では設定に移ります。Webalizerの設定ファイルは/etc/webalizer.confにありますのでこれをテキストエディタ等で開き、以下の赤字部分を修正します。基本的な設定はファイル前半の修正のみでOKです。
#
# Sample Webalizer configuration file
# Copyright 1997-2000 by Bradford L. Barrett (brad@mrunix.net)
#
# Distributed under the GNU General Public License. See the
# files "Copyright" and "COPYING" provided with the webalizer
# distribution for additional information.
#
# This is a sample configuration file for the Webalizer (ver 2.00)
# Lines starting with pound signs '#' are comment lines and are
# ignored. Blank lines are skipped as well. Other lines are considered
# as configuration lines, and have the form "ConfigOption Value" where
# ConfigOption is a valid configuration keyword, and Value is the value
# to assign that configuration option. Invalid keyword/values are
# ignored, with appropriate warnings being displayed. There must be
# at least one space or tab between the keyword and its value.
#
# As of version 0.98, The Webalizer will look for a 'default' configuration
# file named "webalizer.conf" in the current directory, and if not found
# there, will look for "/etc/webalizer.conf".
# LogFile defines the web server log file to use. If not specified
# here or on on the command line, input will default to STDIN. If
# the log filename ends in '.gz' (ie: a gzip compressed file), it will
# be decompressed on the fly as it is being read.
LogFile access_logまでの絶対パス(フルパス名)
# LogType defines the log type being processed. Normally, the Webalizer
# expects a CLF or Combined web server log as input. Using this option,
# you can process ftp logs as well (xferlog as produced by wu-ftp and
# others), or Squid native logs. Values can be 'clf', 'ftp' or 'squid',
# with 'clf' the default.
#LogType clf
# OutputDir is where you want to put the output files. This should
# should be a full path name, however relative ones might work as well.
# If no output directory is specified, the current directory will be used.
OutputDir 解析結果を出力するディレクトリへの絶対パス
# TrueTypeFont is True Type font file for text in output image.
# It's necessary to make gd to support the freetype library.
#TrueTypeFont /usr/share/fonts/alias/TrueType/gothic-mr-jisx0208.1983-0.ttf
TrueTypeFont /usr/local/share/fonts/ipag.ttf
# HistoryName allows you to specify the name of the history file produced
# by the Webalizer. The history file keeps the data for up to 12 months
# worth of logs, used for generating the main HTML page (index.html).
# The default is a file named "webalizer.hist", stored in the specified
# output directory. If you specify just the filename (without a path),
# it will be kept in the specified output directory. Otherwise, the path
# is relative to the output directory, unless absolute (leading /).
HistoryName /home/httpd/html/log/webalizer/webalizer.hist
# Incremental processing allows multiple partial log files to be used
# instead of one huge one. Useful for large sites that have to rotate
# their log files more than once a month. The Webalizer will save its
# internal state before exiting, and restore it the next time run, in
# order to continue processing where it left off. This mode also causes
# The Webalizer to scan for and ignore duplicate records (records already
# processed by a previous run). See the README file for additional
# information. The value may be 'yes' or 'no', with a default of 'no'.
# The file 'webalizer.current' is used to store the current state data,
# and is located in the output directory of the program (unless changed
# with the IncrementalName option below). Please read at least the section
# on Incremental processing in the README file before you enable this option.
Incremental yes
# IncrementalName allows you to specify the filename for saving the
# incremental data in. It is similar to the HistoryName option where the
# name is relative to the specified output directory, unless an absolute
# filename is specified. The default is a file named "webalizer.current"
# kept in the normal output directory. If you don't specify "Incremental"
# as 'yes' then this option has no meaning.
IncrementalName /home/httpd/html/log/webalizer/webalizer.current
# ReportTitle is the text to display as the title. The hostname
# (unless blank) is appended to the end of this string (seperated with
# a space) to generate the final full title string.
# Default is (for english) "Usage Statistics for".
ReportTitle 解析結果出力ページのタイトル名
# HostName defines the hostname for the report. This is used in
# the title, and is prepended to the URL table items. This allows
# clicking on URL's in the report to go to the proper location in
# the event you are running the report on a 'virtual' web server,
# or for a server different than the one the report resides on.
# If not specified here, or on the command line, webalizer will
# try to get the hostname via a uname system call. If that fails,
# it will default to "localhost".
HostName サーバのドメイン名
# HTMLExtension allows you to specify the filename extension to use
# for generated HTML pages. Normally, this defaults to "html", but
# can be changed for sites who need it (like for PHP embeded pages).
#HTMLExtension html
# PageType lets you tell the Webalizer what types of URL's you
# consider a 'page'. Most people consider html and cgi documents
# as pages, while not images and audio files. If no types are
# specified, defaults will be used ('htm*', 'cgi' and HTMLExtension
# if different for web logs, 'txt' for ftp logs).
PageType htm*
PageType cgi
#PageType phtml
#PageType php3
#PageType pl
PageType php
:
:
:
赤字部分の説明を以下に載せておきましたので参考にしてください。
●LogFile記述
ここにはApacheで設定したaccess_logというファイルの出力先までのパスを記述します。例えば
/var/log/apache2/access_log
などです。
●OutputDir記述
ここにはWebalizerの解析結果を出力するディレクトリを指定します。例えば
/home/httpd/html/log/webalizer
などです。自動的にディレクトリは作成されませんのであらかじめこの出力先ディレクトリは作っておいてくださいね。
●TrueTypeFont記述
解析結果は日本語出力されますのでそのための日本語フォントをここでは指定します。
VineLinux3.2以前のバージョンではデフォルトでさざなみフォント、VineLinux4.0からはデフォルトでVLゴシックフォントがそれぞれインストールされていますのでそれを指定します。
上記の例ではオプションでインストールしたIPAゴシックフォントを指定していますがデフォルトフォントは/usr/X11R6/lib/X11/fonts/TrueType/以下にありますのでお好きなフォントを指定してください。
●ReportTitle記述
解析結果ページのタイトル名を指定します。一目でアクセス解析結果ページだと分かるようなタイトルがいいと思います。日本語使用もOKです。
●HostName記述
ここにはご使用のサーバのドメイン名を指定してください。具体的には"http://www."以降のURLを記述します("www"がない場合は"http://"以降の記述です)。
●PageType記述
解析対象のページの拡張子をここでは指定します。デフォルトでは".htm"や".html"や".cgi"が設定されていますが、phpなどでWebページを構築されている方は上記赤字のように別途phpを指定してください。
▼アクセス解析の自動化
アクセス解析を自動化させるためにシェルスクリプトを作成する必要があります。参考にこちらにそのスクリプトを置いておきますのでご自由にダウンロードしてください。ただしダウンロード先は/etc/cron.hourlyなどにしてください。既にファイルが存在している場合は上書き保存してください。
シェルスクリプトのため、ダウンロードしたら実行権限をつける必要があります。
chmod 755 webalizer.cron
とターミナル上で入力してください。
最後にapacheとcronを再起動させます。
/etc/rc.d/init.d/apache2 restart
/etc/rc.d/init.d/crond restart
で完了です。