Last Updated on 2013年2月3日 by かんりにん
アクセスログ解析ツールawstatのインストールのメモ。
Software Design2006年1月号を参照。
今回はローカル上で運用しているバーチャルホストのログを解析。
※今回は導入テスト的な設定なので、詳細設定はまた今度。
【本家サイト】
http://awstats.sourceforge.net/
【参考】
ダウンロードとインストール
インストールを実施すると、/usr/local/awstats/にインストールされる。
[root@example ~]# cd /usr/src/redhat/RPMS/noarch/ [root@example noarch]# wget http://jaist.dl.sourceforge.net/sourceforge/awstats/awstats-6.5-1.noarch.rpm [root@example noarch]# rpm -ivh awstats-6.5-1.noarch.rpm Preparing... ########################################### [100%] 1:awstats ########################################### [100%] ----- AWStats 6.5 - 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 rpm -ivh awstats-6.5-1.noarch.rpm
インストール後にファイルを確認する。
[root@example noarch]# cd /usr/local/awstats/ [root@example awstats]# ls -al 合計 40 drwxr-xr-x 5 root root 4096 1月 4 12:34 . drwxr-xr-x 17 root root 4096 1月 4 12:34 .. -r--r--r-- 1 root root 6720 12月 25 06:20 README.TXT drwxr-xr-x 3 root root 4096 1月 4 12:34 docs drwxr-xr-x 4 root root 4096 1月 4 12:34 tools drwxr-xr-x 7 root root 4096 1月 4 12:34 wwwroot [root@example awstats]#
このうち、wwwrootが本体となる。
ファイルのコピー
/home/virtual/www/以下にcgi-binとcgi-bin/awstatsを作成し、
ファイルをコピー。
[root@example awstats]# mkdir -p /home/virtual/www/cgi-bin/awstats [root@example awstats]# cd wwwroot/ [root@example wwwroot]# cp -r classes/ css/ icon/ /home/virtual/www/cgi-bin/ [root@example wwwroot]# cp -r cgi-bin/* /home/virtual/www/cgi-bin/awstats/
apacheへ設定を追加
今回はhttpd.confではなく、対応するバーチャルホストのvhost.confへ追加。
[root@example awstats]# cd /etc/httpd/conf/vhosts/ [root@example vhosts]# vi virtual.conf
【追記箇所】
<Directory "/home/virtual/www/cgi-bin"> AllowOverride None Options -Indexes ExecCGI FollowSymLinks MultiViews Order allow,deny Allow from all </Directory> Alias /css/ "/home/virtual/www/cgi-bin/css/" Alias /icon/ "/home/virtual/www/cgi-bin/icon/" <Directory "/home/virtual/www/cgi-bin/css"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> <Directory "/home/virtual/www/cgi-bin/icon"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
awstatsの設定
続いてawstatsのコンフィグファイルを編集。
設定ファイルは/etc/awstatsにおいてあり、コピーして使用する。
デフォルトのファイル名はawstats.model.conf。
[root@example awstats]# cd /etc/awstats [root@example awstats]# cp awstats.model.conf awstats.virtual.conf [root@example awstats]# vi awstats.virtual.conf
【設定内容】
LogFile="/var/log/httpd/virtual-access_log " LogType=W LogFormat=1 LogSeparator=" " SiteDomain="www.virtual-company.com" HostAliases="localhost 127.0.0.1 REGEX[virtual-company\.com$]" DNSLookup=1 DirData="." DirCgi="." DirIcons="../icon"
統計データの作成
perlでawstats.plを実行。オプション-configで設定ファイルを指定する。
[root@example awstats]# perl awstats.pl -config=virtual -update Update for config "./awstats.virtual.conf" With data in log file "/var/log/httpd/virtual-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: 311 Found 0 dropped records, Found 0 corrupted records, Found 0 old records, Found 311 new qualified records.
続いてhtmlファイルの生成。
[root@example awstats]# perl awstats.pl -config=virtual -output - staticlinks > /home/virtual/www/htdocs/awstats.html
生成完了後、ブラウザから生成されたファイルを確認してみる。