前の日 / 次の日 / 最新 / 2008-09

MuraTaka 速記メモ / 2008-09-14

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

2008-09-14 Sun

CentOS に cpan2rpm をインストールしておく [CentOS]

cpan を RPM パッケージ管理してしまうツール。

- SourceForge.net: cpan2rpm

# rpm --import http://perl.arix.com/cpan2rpm/gpg.pub.asc
「ダウンロードしたRPMパッケージの改竄チェックに使用するGPGキー」をインポート。

# wget http://downloads.sourceforge.net/cpan2rpm/cpan2rpm-2.027-1.noarch.rpm?modtime=1107798682&big_mirror=0
RPM パッケージをダウンロード。

cpan2rpm をインストール。
# rpm -Uvh cpan2rpm-2.027-1.noarch.rpm 
準備中...                ########################################### [100%]
   1:cpan2rpm               ########################################### [100%]
# which cpan2rpm
/usr/bin/cpan2rpm

CentOS に AWStats をインストールしておく [CentOS]

Apache のログ解析ツールである AWStats をインストールしておく。

- AWStats - Free log file analyzer for advanced statistics (GNU GPL).

■ インストール

# yum --enablerepo=rpmforge list | grep -i awstats
awstats.noarch                           6.8-1.el5.rf           rpmforge
# yum --enablerepo=rpmforge install awstats
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * rpmforge: fr2.rpmfind.net
 * base: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
 * addons: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
.... (snip) .....
Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 awstats                 noarch     6.8-1.el5.rf     rpmforge          1.1 M
Installing for dependencies:
 perl-Compress-Zlib      i386       1.42-1.fc6       base               52 k
 perl-HTML-Parser        i386       3.56-1.el5.rf    rpmforge          146 k
 perl-HTML-Tagset        noarch     3.20-1.el5.rf    rpmforge           14 k
 perl-libwww-perl        noarch     5.805-1.1.1      base              376 k

Transaction Summary
=============================================================================
Install      5 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 1.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): perl-HTML-Tagset-3 100% |=========================|  14 kB    00:00     
(2/5): perl-Compress-Zlib 100% |=========================|  52 kB    00:00     
(3/5): perl-HTML-Parser-3 100% |=========================| 146 kB    00:01     
(4/5): awstats-6.8-1.el5. 100% |=========================| 1.1 MB    00:03     
(5/5): perl-libwww-perl-5 100% |=========================| 376 kB    00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: perl-HTML-Tagset             ######################### [1/5] 
  Installing: perl-HTML-Parser             ######################### [2/5] 
  Installing: perl-Compress-Zlib           ######################### [3/5] 
  Installing: perl-libwww-perl             ######################### [4/5] 
  Installing: awstats                      ######################### [5/5] 

Installed: awstats.noarch 0:6.8-1.el5.rf
Dependency Installed: perl-Compress-Zlib.i386 0:1.42-1.fc6 perl-HTML-Parser.i386 0:3.56-1.el5.rf perl-HTML-Tagset.noarch 0:3.20-1.el5.rf perl-libwww-perl.noarch 0:5.805-1.1.1
Complete!

■ 設定

この設定ファイルは、awstats.<サーバの FQDN>.conf である必要がある。

# mv /etc/awstats/awstats.localhost.localdomain.conf /etc/awstats/awstats.localhost.localdomain.conf.org
# cp -p /etc/awstats/awstats.model.conf /etc/awstats/awstats.centos.jp.conf
- /etc/awstats/awstats.centos.jp.conf
を編集する。

# diff -u awstats.model.conf awstats.centos.jp.conf 
--- awstats.model.conf  2008-07-26 08:44:11.000000000 +0900
+++ awstats.centos.jp.conf      2008-09-14 19:56:54.000000000 +0900
@@ -150,7 +150,8 @@
 # Example: "ftp.domain.com"
 # Example: "domain.com"
 #
-SiteDomain="localhost.localdomain"
+#SiteDomain="localhost.localdomain"
+SiteDomain="centos.jp"
 
 
 # Enter here all other possible domain names, addresses or virtual host
@@ -185,7 +186,8 @@
 # 2 - DNS Lookup is made only from static DNS cache file (if it exists)
 # Default: 2
 # 
-DNSLookup=2
+#DNSLookup=2
+DNSLookup=1
 
 
 # When AWStats updates its statistics, it stores results of its analysis in 
@@ -1315,7 +1317,7 @@
 # module, so install it from elsewhere (from www.cpan.org for example).
 # This plugin reduces AWStats speed of 10% !
 #
-#LoadPlugin="geoipfree"
+LoadPlugin="geoipfree"
 
 # Plugin: GeoIP_Region_Maxmind
 # Perl modules required: Geo::IP (from Maxmind)

上記では、LogFile の値をデフォルトのままとしているが、該当するファイル名に変更する。

■ GeoIPfree プラグインを使用するための Perl モジュールをインストール

# cpan2rpm --install Geo::IPfree

■ 日本の検索エンジンへの対応

- Apacheアクセスログ解析(AWStats) - CentOSで自宅サーバー構築
を参考にさせて頂き、
- /var/www/awstats/lib/search_engines.pm
記載。

■ Apache の設定

/etc/httpd/conf.d/ に awstats.conf が作成されている。
必要に応じて編集する。

オリジナルでは、ローカルホストからのアクセスしか許可していないので、変えておく必要はあるだろう。
allow from 127.0.0.1

■ awstats データベース作成

こちらも、
- Apacheアクセスログ解析(AWStats) - CentOSで自宅サーバー構築
を参考にさせて頂き、実施する。
- awstatsinit.sh
#!/bin/sh

logfile=`grep ^LogFile /etc/awstats/awstats.$1.conf|sed -e 's/LogFile="\([^ ]*\)"/\1/p' -e d`
for log in `ls $logfile*|sort -r`
do
    `rpm -ql awstats|grep "awstats\.pl"` \
    -config=$1 -update -logfile=$log
done

# ./awstatsinit.sh <サーバの FQDN>
引数は、awstats の設定を見に行くために必要なもの。
- awstats.<サーバの FQDN>.conf

■ Apache ログローテート設定

- /etc/logrotate.d/httpd
に、Apache がログローテートを行う際、awstats データベースに取り込みを行ってからローテートされるようにしておく。
/var/log/httpd/*log {
   rotate 55
   missingok
   notifempty
   sharedscripts
   prerotate
       `rpm -ql awstats|grep "awstats_updateall\.pl"` now -confdir="/etc/awstats" \
       -awstatsprog="`rpm -ql awstats|grep "awstats\.pl"`" >/dev/null
   endscript
   postrotate
       /sbin/service httpd reload > /dev/null 2>/dev/null || true
   endscript
}

■ awstats 動作確認

- http://<server name>/awstats/awstats.pl

で接続。




アクセス統計ページ HTML 版の作成も合わせて行う。
この作業も、
- Apacheアクセスログ解析(AWStats) - CentOSで自宅サーバー構築
をベースに行う。

HTML を生成するスクリプトをそのまま実行すると、
./awstatsreport.sh: /usr/bin/awstats_buildstaticpages.pl: /usr/bin/perl^M: bad interpreter: そのようなファイルやディレクトリはありません
....
がでてしまうので、
- No.908 awstatsreport.sh の実行エラー - Web Patio - CentOSで自宅サーバー構築
[root@centos ~]# vi /usr/bin/awstats_buildstaticpages.pl 
#!/usr/bin/perl -- <= '--'を追加
を実施しておくこと。

■ クーロンへの登録

# echo "00 00 * * * root /root/awstatsreport.sh <サーバの FQDN> /var/www/awstatsreport > /dev/null" > /etc/cron.d/awstatsreport

CentOS yum への rpmforge リポジトリの追加 [CentOS]

[2008-07-13] に書いてはいたのだが、埋もれていたので改めて。

■ rpmforge リポジトリの追加

$ wget http://dag.wieers.com/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

# rpm -ivh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

$ wget http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt

vi /etc/yum.repos.d/rpmforge.repo
enabled = 1 を enabled = 0 に。
デフォルトでは使用せず、使用したい場合には、オプションで指定を行う。

# rpm --import RPM-GPG-KEY.dag.txt
# yum --enablerepo=rpmforge list

■ 参考
- CentOS で構築する自宅サーバ : yum に RPMforge リポジトリを追加する

2009 : 01 02 03 04 05 06 07 08 09 10 11 12
2008 : 01 02 03 04 05 06 07 08 09 10 11 12
2007 : 01 02 03 04 05 06 07 08 09 10 11 12
2006 : 01 02 03 04 05 06 07 08 09 10 11 12
2005 : 01 02 03 04 05 06 07 08 09 10 11 12
2004 : 01 02 03 04 05 06 07 08 09 10 11 12

最終更新時間: 2009-10-14 00:22