このサイトではアクセス解析のため、Google Analyticsを使っていますが、いまいちよく分からないところがあるので探してみると、AWStatsがよさそうだったので導入してみることに。Debian etchにあるものは6.5で、日本語に未対応のところもありそうだったので、AWStats日本語化バージョンからAWStats_ja version 6.7をダウンロード。ここを見ながら、まずは
$ unzip awstats_ja-6.7.zip $ sudo mkdir /usr/lib/cgi-bin/awstats $ sudo cp -r awstats_ja-6.7/wwwroot/cgi-bin/* /usr/lib/cgi-bin/awstats/ $ mkdir /xxx/www/awstats-icon $ sudo cp -r awstats_ja-6.7/wwwroot/icon/* /xxx/www/awstats-icon/ $ sudo chmod 755 /usr/lib/cgi-bin/awstats/awstats.pl $ sudo touch awstats.conf.local
として、awstats.confのいちばん後ろに
Include "./awstats.conf.local" # Added by MKT
を追加します。awstats.conf.localには
LogFile="/var/log/apache2/access.log.enc" DirData="/var/lib/awstats" DirIcons="/awstats-icon" DirCgi="/cgi-bin/awstats" SiteDomain="mktlab.info" Lang="jp" DNSLookup=1 SkipHosts="127.0.0.1 localhost mktlab.info REGEX[^192.168.] 218.45.247.2018243
と書きました。このあたりは、aptからAWStatsを試しにインストールしたときにできた、/etc/awstatsの設定を真似してます。ここで、AWStatsを実行してみます。
$ su # cd /var/lib/cgi-bin/awstats # perl conv_weblog_to_utf8.pl < /var/log/apache2/access.log > /var/log/apache2/access.log.enc # perl awstats.pl -config=local -update # perl awstats.pl -config=local -output -staticlink > /xxx/www/awstats.html
http://xxx/awstats.htmlで結果が見られればOK。アーカイブされている過去のログについても見てみたいので、ここやここを参考に
# rm /var/lib/awstats/* # mkdir temp # cd temp # cp -p /var/log/apache2/access.log.1 ./ # cp -p /var/log/apache2/access*gz ./ # gzip -d * # cat `ls -tr access.log*` > access.log # perl /usr/lib/cgi-bin/awstats/conv_weblog_to_utf8.pl < access.log > /var/log/apache2/access.log.enc # perl /usr/lib/cgi-bin/awstats/awstats.pl -config=local -update # perl /usr/lib/cgi-bin/awstats/awstats.pl -config=local -output -staticlink > /xxx/www/awstats.html
としました。conv_weblog_to_utf8.plにはおさかなラボさんのconv_weblog_to_utf8.patchをパッチ。
patch < conv_weblog_to_utf8.patch
定期的に実行させるために、awstats.cronを
#!/bin/sh /usr/bin/perl /usr/lib/cgi-bin/awstats/conv_weblog_to_utf8.pl < /var/log/apache2/access.log > /var/log/apache2/access.log.enc /usr/bin/perl /usr/lib/cgi-bin/awstats/awstats.pl -config=local -update > /dev/null /usr/bin/perl /usr/lib/cgi-bin/awstats/awstats.pl -config=local -output -staticlink > /home/igarashi/www/awstats.html chown www-data:www-data /xxx/www/awstats.html
と修正して
# cp awstats.cron /etc/cron.hourly # chmod 755 /etc/cron.hourly/awstats.cron
を実行。最後に、/etc/apache2/sites-enabled/000-defaultに
# Added by MKT for AWStats SetEnvIf Request_URI "default.ida" wormlog SetEnvIf Request_URI "cmd.exe" wormlog SetEnvIf Request_URI "root.exe" wormlog SetEnvIf Request_URI "Admin.dll" wormlog SetEnvIf Request_URI "NULL.IDA" wormlog SetEnvIf Request_URI "NULL.printer" wormlog SetEnvIf Request_URI "mem_bin" wormlog SetEnvIf Request_URI "vti_bin" wormlog SetEnvIf Request_URI "MSADC" wormlog CustomLog /var/log/apache2/access.log combined env=!wormlog CustomLog /var/log/apache2/worm.log combined env=wormlog LogFormat "%h %l %u %t "%!414r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
を追加して終了です。

0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment