アクセスログ解析(Awstats)
2009, 02, 15
Awstats は視覚的に綺麗で、見やすいログ解析ツールだ。
日別・時間別・アクセス先など様々な統計情報を把握することが出来る。
■Awstatsのインストール
以下のコマンドでAwstatsをインストールする。
awstatsを使うには、perlも必要。perl -vと入力して、
以下のような情報が返ってくれば、perlはインストールされている。
■ Awstatsの設定ファイルの編集
■ awstats.plアクセス制限
会社等からアクセスする場合、自分の会社の接続環境(IPアドレス)を調べ、/etc/hosts.allowへ登録する必要がある。そんな時は診断くんで確認できる。
■ httpdの設定ファイルの編集
■ ログファイルからデータファイルの作成
これで、/etc/cron.hourly/awstats が一時間毎に実行される。セットアップして1時間たってから、 http://サーバーアドレス/awstats/awstats.pl にアクセスすれば、解析結果が見れるようになっているはず。
日別・時間別・アクセス先など様々な統計情報を把握することが出来る。
■Awstatsのインストール
以下のコマンドでAwstatsをインストールする。
[root@linux ~]# yum -y install awstats
awstatsを使うには、perlも必要。perl -vと入力して、
以下のような情報が返ってくれば、perlはインストールされている。
[root@linux ~]# perl -v This is perl, v5.8.8 built for i386-linux-thread-multi Copyright 1987-2006, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.
■ Awstatsの設定ファイルの編集
まず不要な設定ファイルを削除しておく [root@linux ~]# rm -f /etc/awstats/awstats.localhost.localdomain.conf awstatsへ移動。 [root@linux ~]# cd /etc/awstats etc/awstats/のawstats.server.yokensaka.com.conf を awstats.conf に変更。 [root@linux awstats]# mv awstats.linux.yokensaka.com.conf awstats.conf 続いて、root権限で、このawstats.confを編集。 [root@linux awstats]# su - [root@linux ~]# vi /etc/awstats/awstats.conf SiteDomain="linux.yokensaka.com" ↓ SiteDomain="yokensaka.com" ←独自ドメイン名に変更 DNSLookup=2 ↓ DNSLookup=1 ← 1に変更(DNSの逆引きにする設定に変更) DirIcons="/awstatsicons" ↓ DirIcons="/icon" ← アイコンのディレクトリー名を変更 SkipHosts="127.0.0.1" ↓ 内部のクライアントはスキップするように変更 SkipHosts="127.0.0.1 REGEX[^192\.168\.1\.]" Lang="auto" ↓ Lang="jp" ← jpに変更 #LoadPlugin="tooltips" ↓ #を削除(該当する部分にマウスを当てるとヘルプが表示される。) LoadPlugin="tooltips" ※ 最後にこのままだとアイコンが表示されないので、アイコンの入ってるフォルダ /usr/share/awstats/wwwroot/icon を /var/www/html へコピーしておく。
■ awstats.plアクセス制限
[root@linux ~]# vi /etc/httpd/conf.d/awstats.conf
最終行へ追加
<Files "awstats.pl">
Order deny,allow
Deny from all
Allow from 127.0.0.1 ← サーバー自身からのアクセスを許可
Allow from 192.168.1. ← 内部ネットワークからのアクセスを許可
Allow from xxx.xxx.xxx.xxx ← 特定の外部IP(xxx.xxx.xxx.xxx)からのアクセスを許可
</Files>
Apache設定反映
[root@linux ~]# /etc/rc.d/init.d/httpd reload
httpd を再読み込み中: [ OK ]会社等からアクセスする場合、自分の会社の接続環境(IPアドレス)を調べ、/etc/hosts.allowへ登録する必要がある。そんな時は診断くんで確認できる。
■ httpdの設定ファイルの編集
httpdの設定ファイルの編集
[root@linux ~]# vi /etc/httpd/conf/httpd.conf
長すぎるURI(414 Error)はログに記録しない
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
↓
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
ログの記録内容変更
# logged therein and *not* in this file.
#
#CustomLog logs/access_log common
この下に以下を追加
SetEnvIf Request_URI "default\.ida" no_log
SetEnvIf Request_URI "cmd\.exe" no_log
SetEnvIf Request_URI "root\.exe" no_log
SetEnvIf Request_URI "Admin\.dll" no_log
SetEnvIf Request_URI "NULL\.IDA" no_log
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" no_log
SetEnvIf Remote_Addr 192.168. no_log
CustomLog logs/access_log combined env=!no_log
以上で設定は完了ですので、一度httpdを再起動させる。
[root@linux ~]# service httpd restart
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]■ ログファイルからデータファイルの作成
続いて、ログファイルからデータファイルの作成。 [root@linux ~]# /usr/share/awstats/tools/awstats_updateall.pl now Running '"/usr/share/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=default -configdir="/etc/awstats"' to update config default Create/Update database for config "/etc/awstats/awstats.conf" by AWStats version 6.7 (build 1.892) From data in log file "/var/log/httpd/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: 3 Found 3 dropped records, Found 0 corrupted records, Found 0 old records, Found 0 new qualified records.
これで、/etc/cron.hourly/awstats が一時間毎に実行される。セットアップして1時間たってから、 http://サーバーアドレス/awstats/awstats.pl にアクセスすれば、解析結果が見れるようになっているはず。