| はじめての自宅サーバ構築 - Fedora/CentOS - | Last Update | 2008/05/16 | |
| It opened to 2004/09/19. 当サイトはFedora9で運用しています |
Visitors Pageviews Today(IP/PV) |
3,250,872 11,998,782 1,341/7,439 |
|
デルではおとくなキャンペーン実施中! |
レノボ Web 広告限定ストア(キャンペーン&新着情報) |
apacheの出力ログの確認
# vi /etc/httpd/conf/httpd.conf
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
|
awstatsパッケージのダウンロード
# wget http://nchc.dl.sourceforge.net/sourceforge/awstats/awstats-6.6-1.noarch.rpm
--14:08:50-- http://nchc.dl.sourceforge.net/sourceforge/awstats/awstats-6.6-1.noarch.rpm
=> `awstats-6.6-1.noarch.rpm'
nchc.dl.sourceforge.net をDNSに問いあわせています... 完了しました。
nchc.dl.sourceforge.net[211.79.61.10]:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 1,139,488 [text/plain]
100%[====================================>] 1,139,488 48.02K/s ETA 00:00
14:09:14 (48.02 KB/s) - `awstats-6.6-1.noarch.rpm' を保存しました [1139488/1139488]
ダウンロードしたawstatsパッケージのインストール
# rpm -ivh awstats-6.6-1.noarch.rpm
Preparing... ########################################### [100%]
1:awstats ########################################### [100%]
----- AWStats 6.6 - 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
|
# yum -y install awstats |
awstatsのセットアップスクリプト起動
# /usr/share/awstats/tools/awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.6) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix
Warning: AWStats standard directory on Linux OS is '/usr/share/awstats'.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/root
to standard directory:
/usr/share/awstats
And then, run configure.pl from this location.
awstatsのインストール先を標準インストール先にする
Do you want to continue setup from this NON standard directory [yN] ? y
-----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/share/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
apacheの設定ファイルをフルパスで指定
> /etc/httpd/conf/httpd.conf
-----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
Add 'Alias /awstatsclasses "/root/wwwroot/classes/"'
Add 'Alias /awstatscss "/root/wwwroot/css/"'
Add 'Alias /awstatsicons "/root/wwwroot/icon/"'
Add 'ScriptAlias /awstats/ "/root/wwwroot/cgi-bin/"'
Add '<Directory>' directive
AWStats directives added to Apache config file.
-----> Update model config file '/etc/awstats/awstats.model.conf'
File awstats.model.conf updated.
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
awstatsのプロファイルを作成する
file (required if first install) [y/N] ? y
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
プロファイル名を指定(ドメイン名を指定する)
> kajuhome.com
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
デフォルトの為、空エンターキー押下
>
-----> Create config file '/etc/awstats/awstats.kajuhome.com.conf'
Config file /etc/awstats/awstats.kajuhome.com.conf created.
-----> Restart Web server with '/sbin/service httpd restart'
httpdを停止中: [ OK ]
httpdを起動中: [ OK ]
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/root/wwwroot/cgi-bin/awstats.pl -update -config=kajuhome.com
Or if you have several config files and prefer having only one command:
/root/tools/awstats_updateall.pl now
エンターキー押下
Press ENTER to continue...
A SIMPLE config file has been created: /etc/awstats/awstats.kajuhome.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'kajuhome.com' with command:
> perl awstats.pl -update -config=kajuhome.com
You can also read your statistics for 'kajuhome.com' with URL:
> http://localhost/awstats/awstats.pl?config=kajuhome.com
エンターキー押下
Press ENTER to finish...
作成されたawstatsのプロファイルの詳細を設定する
# vi /etc/awstats/awstats.kajuhome.com.conf
# You can also use a pipe if log file come from a pipe :
# Example: "gzip -d </var/log/apache/access.log.gz |"
# If there is several log files from load balancing servers :
# Example: "/pathtotools/logresolvemerge.pl *.log |"
#
apacheのアクセスログ
LogFile="/var/log/httpd/access_log"
# 0 - No DNS Lookup
# 1 - DNS Lookup is fully enabled
# 2 - DNS Lookup is made only from static DNS cache file (if it exists)
# Default: 2
#
DNS名取得
DNSLookup=2
# Example: "/var/lib/awstats"
# Example: "../data"
# Example: "C:/awstats_data_dir"
# Default: "." (means same directory as awstats.pl)
#
データの保存先をスクリプトの場所と同じにする
DirData="."
# Change : Effective for new updates only
# Example: "127.0.0.1 REGEX[^192\.168\.] REGEX[^10\.]"
# Example: "localhost REGEX[^.*\.localdomain$]"
# Default: ""
#
#SkipHosts=""
ローカルとLAN内(192.168.1.*)のアクセスは除外
SkipHosts="127.0.0.1 REGEX[^192\.168\.1\.]"
LevelForKeywordsDetection=2 # 0 disables Keyphrases/Keywords detection.
# 2 reduces AWStats speed by 1%
LevelForFileTypesDetection=2 # 0 disables File types detection.
# 2 reduces AWStats speed by 1%
Wormsも対象にする
LevelForWormsDetection=2 # 0 disables Worms detection.
# 2 reduces AWStats speed by 15%
# Serbian=sr, Slovak=sk, Slovenian=si, Spanish=es, Swedish=se, Turkish=tr,
# Ukrainian=ua, Welsh=cy.
# First available language accepted by browser=auto
# Default: "auto"
#
表示を日本語化
Lang="jp"
# Choose if you want the week report to start on sunday or monday
# Possible values:
# 0 - Week start on sunday
# 1 - Week start on monday
# Default: 1
#
週の始めを日曜日にする
FirstDayOfWeek=0
|
awstatsの各モジュールが配置されているパスに変更または確認
************************************************************************************
* 【「rpm -ivh」でインストールした場合】
************************************************************************************
# vi /etc/httpd/conf/httpd.conf
#
# Directives to allow use of AWStats as a CGI
#
#Alias /awstatsclasses "/root/wwwroot/classes/"
#Alias /awstatscss "/root/wwwroot/css/"
#Alias /awstatsicons "/root/wwwroot/icon/"
#ScriptAlias /awstats/ "/root/wwwroot/cgi-bin/"
↓ ↓ ↓ ↓
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
#<Directory "/root/wwwroot">
↓ ↓
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
************************************************************************************
* 【「yum」でインストールした場合】
************************************************************************************
# vi /etc/httpd/conf.d/awstats.conf
#
# Content of this file, with correct values, can be automatically added to
# your Apache server by using the AWStats configure.pl tool.
#
#
# Directives to add to your Apache conf file to allow use of AWStats as a CGI.
# Note that path "/usr/share/awstats/" must reflect your AWStats install path.
#
Alias /awstatsclasses "/usr/share/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/share/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/share/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/share/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/share/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
# Additional Perl modules
<IfModule mod_env.c>
SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins
</IfModule>
設定を有効化する為、apache(httpd)を再起動する
# /etc/rc.d/init.d/httpd restart
httpdを停止中: [ OK ]
httpd を起動中: [ OK ]
|
スクリプトの作成 # vi awstats.sh #!/bin/bash /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=kajuhome.com パーミッション変更(実行権付与) # chmod 700 awstats.sh |
作成したスクリプトの実行 # ./awstats.sh Update for config "/etc/awstats/awstats.kajuhome.com.conf" With 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: 64 Found 0 dropped records, Found 19 corrupted records, Found 0 old records, Found 45 new qualified records. |

レポート作成スクリプトの修正
行番号を明記してありますが、Awstatsのバージョンによって異なります。
以下は、2007年02月06日現在で Ver 6.6 (build 1.887)の場合
# vi /usr/share/awstats/wwwroot/cgi-bin/awstats.pl
print "<span style=\"font-size: 14px;\">";
if ($MonthRequired eq 'all') { print "$Message[6] $YearRequired"; }
【7769行目】
#else { print "$Message[5] $MonthNumLib{$MonthRequired} $YearRequired"; }
↓ ↓ ↓
else { print "$YearRequired $Message[6]".$MonthNumLib{$MonthRequired}; }
print "</span>";
【8916行目】
#print ($MonthRequired eq 'all'?"$Message[6] $YearRequired":"$Message[5] ".$MonthNumLib{$MonthRequired}." $YearRequired");
↓ ↓ ↓
print ($MonthRequired eq 'all'?"$YearRequired $Message[6]":"$YearRequired $Message[6]".$MonthNumLib{$MonthRequired});
|
コンバートスクリプトを以下のパスに保存し実行権を付与します。
私は、awstatsと同じ所に保存しました。
/usr/share/awstats/wwwroot/cgi-bin/conv_weblog_to_utf8.pl
実行権の付与
# chmod 700 /usr/share/awstats/wwwroot/cgi-bin/conv_weblog_to_utf8.pl
apacheログファイルのコンバート実行
# /usr/share/awstats/wwwroot/cgi-bin/conv_weblog_to_utf8.pl < /etc/httpd/logs/access_log > /etc/httpd/logs/access_log.enc
awstats設定ファイルの修正
# vi /etc/awstats/awstats.kajuhome.com.conf
# You can also use a pipe if log file come from a pipe :
# Example: "gzip -d </var/log/apache/access.log.gz |"
# If there is several log files from load balancing servers :
# Example: "/pathtotools/logresolvemerge.pl *.log |"
#
utf-8コードにコンバートされたapacheのアクセスログに変更
#LogFile="/var/log/httpd/access_log"
↓ ↓ ↓
LogFile="/etc/httpd/logs/access_log.enc"
|
シェルスクリプトを作成
# vi /root/awstats.sh
#!/bin/sh
echo "Job Name (awstats.sh)"
year="`date +"%Y"`"
month="`date +"%m"`"
day="`date +"%d"`"
echo "作成年月($year年$month月)"
echo " 開始(`date +"%k時%M分%S秒"`)"
echo " 開始(`date +"%k時%M分%S秒"`)[convert]"
/usr/share/awstats/wwwroot/cgi-bin/conv_weblog_to_utf8.pl \
< /etc/httpd/logs/access_log \
> /etc/httpd/logs/access_log.enc
echo " 開始(`date +"%k時%M分%S秒"`)[update]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com -update
echo " 開始(`date +"%k時%M分%S秒"`)[$year-$month.html]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output -year=$year -month=$month -staticlinks > \
/var/www/html/awstats/$year-$month.html
echo " 開始(`date +"%k時%M分%S秒"`)[alldomains]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=alldomains -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.alldomains.html
echo " 開始(`date +"%k時%M分%S秒"`)[allhosts]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=allhosts -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.allhosts.html
echo " 開始(`date +"%k時%M分%S秒"`)[lasthosts]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=lasthosts -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.lasthosts.html
echo " 開始(`date +"%k時%M分%S秒"`)[unknownip]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=unknownip -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.unknownip.html
echo " 開始(`date +"%k時%M分%S秒"`)[allrobots]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=allrobots -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.allrobots.html
echo " 開始(`date +"%k時%M分%S秒"`)[lastrobots]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=lastrobots -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.lastrobots.html
echo " 開始(`date +"%k時%M分%S秒"`)[urldetail]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=urldetail -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.urldetail.html
echo " 開始(`date +"%k時%M分%S秒"`)[urlentry]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=urlentry -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.urlentry.html
echo " 開始(`date +"%k時%M分%S秒"`)[urlexit]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=urlexit -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.urlexit.html
echo " 開始(`date +"%k時%M分%S秒"`)[osdetail]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=osdetail -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.osdetail.html
echo " 開始(`date +"%k時%M分%S秒"`)[unknownos]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=unknownos -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.unknownos.html
echo " 開始(`date +"%k時%M分%S秒"`)[browserdetail]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=browserdetail -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.browserdetail.html
echo " 開始(`date +"%k時%M分%S秒"`)[unknownbrowser]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=unknownbrowser -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.unknownbrowser.html
echo " 開始(`date +"%k時%M分%S秒"`)[refererse]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=refererse -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.refererse.html
echo " 開始(`date +"%k時%M分%S秒"`)[refererpages]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=refererpages -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.refererpages.html
echo " 開始(`date +"%k時%M分%S秒"`)[keyphrases]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=keyphrases -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.keyphrases.html
echo " 開始(`date +"%k時%M分%S秒"`)[keywords]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=keywords -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.keywords.html
echo " 開始(`date +"%k時%M分%S秒"`)[errors404]"
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=kajuhome.com \
-output=errors404 -staticlinks > \
/var/www/html/awstats/awstats.kajuhome.com.errors404.html
echo " 終了(`date +"%k時%M分%S秒"`)"
上記スクリプト内のコンフィグファイル名『kajuhome.com』と
出力ファイル名『awstats.kajuhome.com.xxxxx.html』の
【kajuhome.com】部分は、あなたの設定ファイル名に変更して下さい。
作成したシェルスクリプトに実行権を与える
# chmod 700 /root/awstats.sh
自動集計スクリプトがHTMLを生成するパスを作成
# mkdir /var/www/html/awstats
オーナ・グループ設定
# chown apache:apache /var/www/html/awstats
プログラムを定期的に実行するcrondの設定ファイルを編集する
# crontab -e
毎日3時間毎に集計を行う
00 0-23/3 * * * /root/awstats.sh
cronジョブで送られてくるメールが文字化けを起こす場合は、以下を追加する
00 0-23/3 * * * /root/awstats.sh | nkf -j
nkfは文字コードを変換します。
JISコードに変換する事により文字化けを回避する事が可能。
nkfのパラメータは以下の様になります
-e EUCコードに変換
-s シフトJISコードに変換
-j JISコードに変換
|
awstatsアクセス設定ファイルの変更
# vi /etc/httpd/conf.d/awstats.conf
#
# Content of this file, with correct values, can be automatically added to
# your Apache server by using the AWStats configure.pl tool.
#
#
# Directives to add to your Apache conf file to allow use of AWStats as a CGI.
# Note that path "/usr/share/awstats/" must reflect your AWStats install path.
#
先頭に"#"を追加しコメント化
#Alias /awstatsclasses "/usr/share/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/share/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/share/awstats/wwwroot/icon/"
先頭に"#"を追加しコメント化
#ScriptAlias /awstats/ "/usr/share/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
先頭に"#"を追加しコメント化
#<Directory "/usr/share/awstats/wwwroot">
# Options None
# AllowOverride None
# Order allow,deny
# Allow from 127.0.0.1
#</Directory>
# Additional Perl modules
<IfModule mod_env.c>
SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins
</IfModule>
設定を有効化する為、apache(httpd)を再起動する
# /etc/rc.d/init.d/httpd restart
httpdを停止中: [ OK ]
httpd を起動中: [ OK ]
現段階の集計実行
# /root/awstats.sh
|

プログラムを定期的に実行するcrondの設定ファイルを編集する
# crontab -e
毎日3時間毎に集計を行う
00 0-23/3 * * * /root/awstats.sh
cronジョブで送られてくるメールが文字化けを起こす場合は、以下を追加する
00 0-23/3 * * * /root/awstats.sh | nkf -j
nkfは文字コードを変換します。
JISコードに変換する事により文字化けを回避する事が可能。
nkfのパラメータは以下の様になります
-e EUCコードに変換
-s シフトJISコードに変換
-j JISコードに変換
|