>> HOME >> FC5 MENU >> Apacheアクセスログ解析(AWStats)
Awstats とは非常に格好良く、かつ優れた Webアクセスを解析するソフトです。ログ解析は Webalizer で十分だったのですが、Awstats の方が性能がいいという噂ですので、導入し、Webサイトへのアクセス統計を Webブラウザから参照できるようにします。

1. AWStats インストール
2. AWStats 設定
1 ) AWStats 設定スクリプト /usr/share/awstats/tools/awstats_configure.pl 実行
2 ) AWStats プロファイル /etc/awstats/awstats.mountainbigroad.jp.conf の編集
3 ) 日本の検索エンジンが検索エンジンとして集計されるように設定
4 ) レポートの日付が、「月 11月 2004」となっている為、awstats.pl を修正し正しく表示されるように設定
3. Apache の設定
1 ) Apache 設定ファイル /etc/httpd/conf/httpd.conf の編集
2 ) Apache の AWStats アクセス設定ファイル /etc/httpd/conf.d/awstats.conf の編集
2 ) Apache への設定反映
4. AWStats データベースの作成/更新
1 ) Apache のログを utf-8 にデコード
2 ) AWStats データベースの作成/更新
5. アクセスログの自動集計(本格運用のための設定)
1 ) 閲覧用レポートのディレクトリ作成
2 ) 閲覧用レポート自動生成シェルスクリプトを作成
3 ) 閲覧用レポート自動生成シェルスクリプトの実行
4 ) スケジューラ(cron)への登録
5 ) /etc/cron.hourly/awstats の削除
1. AWStats インストール
[root@linux ~]# yum -y install awstats 
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
core                                                                 [1/3]
core                      100% |=========================| 1.1 kB    00:00
updates                                                              [2/3]
updates                   100% |=========================|  951 B    00:00
extras                                                               [3/3]
extras                    100% |=========================| 1.1 kB    00:00
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for awstats to pack into transaction set.
awstats-6.5-5.fc5.noarch. 100% |=========================|  81 kB    00:00
---> Package awstats.noarch 0:6.5-5.fc5 set to be updated
--> Running transaction check
--> Processing Dependency: perl(LWP::UserAgent) for package: awstats
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for perl-libwww-perl to pack into transaction set.
perl-libwww-perl-5.805-1. 100% |=========================|  23 kB    00:00
---> Package perl-libwww-perl.noarch 0:5.805-1.1 set to be updated
--> Running transaction check
--> Processing Dependency: perl(Compress::Zlib) for package: perl-libwww-perl
--> Processing Dependency: perl(HTML::Entities) for package: perl-libwww-perl
--> Processing Dependency: perl-HTML-Parser >= 3.33 for package: perl-libwww-perl
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for perl-Compress-Zlib to pack into transaction set.
perl-Compress-Zlib-1.41-1 100% |=========================| 5.2 kB    00:00
---> Package perl-Compress-Zlib.i386 0:1.41-1.2.2 set to be updated
---> Downloading header for perl-HTML-Parser to pack into transaction set.
perl-HTML-Parser-3.51-1.F 100% |=========================| 8.9 kB    00:00
---> Package perl-HTML-Parser.i386 0:3.51-1.FC5 set to be updated
--> Running transaction check
--> Processing Dependency: perl(HTML::Tagset) for package: perl-HTML-Parser
--> Processing Dependency: perl-HTML-Tagset >= 3.03 for package: perl-HTML-Parser
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for perl-HTML-Tagset to pack into transaction set.
perl-HTML-Tagset-3.10-2.1 100% |=========================| 3.5 kB    00:00
---> Package perl-HTML-Tagset.noarch 0:3.10-2.1 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 awstats                 noarch     6.5-5.fc5        extras            1.1 M
Installing for dependencies:
 perl-Compress-Zlib      i386       1.41-1.2.2       core               52 k
 perl-HTML-Parser        i386       3.51-1.FC5       updates            92 k
 perl-HTML-Tagset        noarch     3.10-2.1         core               14 k
 perl-libwww-perl        noarch     5.805-1.1        core              379 k

Transaction Summary
=============================================================================
Install      5 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 1.6 M
Downloading Packages:
(1/5): perl-Compress-Zlib 100% |=========================|  52 kB    00:00
(2/5): perl-HTML-Parser-3 100% |=========================|  92 kB    00:00
(3/5): perl-HTML-Tagset-3 100% |=========================|  14 kB    00:00
(4/5): perl-libwww-perl-5 100% |=========================| 379 kB    00:01
(5/5): awstats-6.5-5.fc5. 100% |=========================| 1.1 MB    00:03
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]
chcon: can't apply partial context to unlabeled file /usr/share/awstats/wwwroot/cgi-bin
chcon: can't apply partial context to unlabeled file /var/lib/awstats

Installed: awstats.noarch 0:6.5-5.fc5
Dependency Installed: perl-Compress-Zlib.i386 0:1.41-1.2.2 perl-HTML-Parser.i386 0:3.51-1.FC5 perl-HTML-Tagset.
noarch 0:3.10-2.1 perl-libwww-perl.noarch 0:5.805-1.1

Complete!
2. AWStats 設定
1 ) AWStats 設定スクリプト /usr/share/awstats/tools/awstats_configure.pl 実行
[root@linux ~]# /usr/share/awstats/tools/awstats_configure.pl 


----- AWStats awstats_configure 1.0 (build 1.3) (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/local/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/local/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/local/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 /wstatsicons "/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:
# プロファイル名を指定(ドメイン名を指定する)
> mountainbigroad.jp 

-----> 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.mountainbigroad.jp.conf'
 Config file /etc/awstats/awstats.mountainbigroad.jp.conf created.

-----> Restart Web server with '/sbin/service httpd restart'
[Fri Jul 07 05:54:13 2006] [warn] The Alias directive in /etc/httpd/conf/httpd.conf at line 1027 will
probably never match because it overlaps an earlier Alias.
[Fri Jul 07 05:54:13 2006] [warn] The Alias directive in /etc/httpd/conf/httpd.conf at line 1028 will
probably never match because it overlaps an earlier Alias.
[Fri Jul 07 05:54:13 2006] [warn] The Alias directive in /etc/httpd/conf/httpd.conf at line 1029 will
probably never match because it overlaps an earlier Alias.
[Fri Jul 07 05:54:13 2006] [warn] The ScriptAlias directive in /etc/httpd/conf/httpd.conf at line 1030
 will probably never match because it overlaps an earlier ScriptAlias.
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:
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mountainbigroad.jp
Or if you have several config files and prefer having only one command:
/usr/share/awstats/tools/awstats_updateall.pl now
Press ENTER to continue... 


A SIMPLE config file has been created: /etc/awstats/awstats.mountainbigroad.jp.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'mountainbigroad.jp' with command:
> perl awstats.pl -update -config=mountainbigroad.jp
You can also read your statistics for 'mountainbigroad.jp' with URL:
> http://localhost/awstats/awstats.pl?config=mountainbigroad.jp
Press ENTER to finish... 
2 ) AWStats プロファイル /etc/awstats/awstats.mountainbigroad.jp.conf の編集
[root@linux ~]# vi /etc/awstats/awstats.mountainbigroad.jp.conf 

  :
  :
# "LogFile" contains the web, ftp or mail server log file to analyze.
# Possible values: A full path, or a relative path from awstats.pl directory.
# Example: "/var/log/apache/access.log"
# Example: "../logs/mycombinedlog.log"
# You can also use tags in this filename if you need a dynamic file name
# depending on date or time (Replacement is made by AWStats at the beginning
# of its execution). This is available tags :
#   %YYYY-n  is replaced with 4 digits year we were n hours ago
#   %YY-n    is replaced with 2 digits year we were n hours ago
#   %MM-n    is replaced with 2 digits month we were n hours ago
#   %MO-n    is replaced with 3 letters month we were n hours ago
#   %DD-n    is replaced with day we were n hours ago
#   %HH-n    is replaced with hour we were n hours ago
#   %NS-n    is replaced with number of seconds at 00:00 since 1970
#   %WM-n    is replaced with the week number in month (1-5)
#   %Wm-n    is replaced with the week number in month (0-4)
#   %WY-n    is replaced with the week number in year (01-52)
#   %Wy-n    is replaced with the week number in year (00-51)
#   %DW-n    is replaced with the day number in week (1-7, 1=sunday)
#                              use n=24 if you need (1-7, 1=monday)
#   %Dw-n    is replaced with the day number in week (0-6, 0=sunday)
#                              use n=24 if you need (0-6, 0=monday)
#   Use 0 for n if you need current year, month, day, hour...
# Example: "/var/log/access_log.%YYYY-0%MM-0%DD-0.log"
# Example: "C:/WINNT/system32/LogFiles/W3SVC1/ex%YY-24%MM-24%DD-24.log"
# 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のアクセスログの場所
# 検索系サイトよりキーワードで検索されてきた場合、文字化が発生することがあります。
# これは、AWStats が utf-8 で作られているものの、キーワードが euc でログに出力される為に発生します。
# 対応として、apacheのアクセスログを utf-8にデコードした後に集計を行うようにします。
# access_log.utf8は一時的にデコードしたログを保存するファイルの名前です。
LogFile="/var/log/httpd/access_log.utf8"

  :
  :
# If you want to have hosts reported by name instead of ip address, AWStats
# need to make reverse DNS lookups (if not already done in your log file).
# With DNSLookup to 0, all hosts will be reported by their IP addresses and
# not by the full hostname of visitors (except if names are already available
# in log file).
# If you want/need to set DNSLookup to 1, don't forget that this will reduce
# dramatically AWStats update process speed. Do not use on large web sites.
# Note: Reverse DNS lookup is done on IPv4 only (Enable ipv6 plugin for IPv6).
# Note: Result of DNS Lookup can be used to build the Country report. However
# it is highly recommanded to enable the plugin 'geoipfree' or 'geoip' to
# have an accurate Country report with no need of DNS Lookup.
# Possible values:
# 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
#
# アクセス元の名前解決を行う
DNSLookup=1

  :
  :
# When AWStats updates its statistics, it stores results of its analysis in
# files (AWStats database). All those files are written in the directory
# defined by the "DirData" parameter. Set this value to the directory where
# you want AWStats to save its database and working files into.
# Warning: If you want to be able to use the "AllowToUpdateStatsFromBrowser"
# feature (see later), you need "Write" permissions by web server user on this
# directory (and "Modify" for Windows NTFS file systems).
# Example: "/var/lib/awstats"
# Example: "../data"
# Example: "C:/awstats_data_dir"
# Default: "."          (means same directory as awstats.pl)
#
# データの保存先をスクリプトの場所と同じにする
DirData="."

  :
  :
# Do not include access from clients that match following criteria.
# If your log file contains IP adresses in host field, you must enter here
# matching IP adresses criteria.
# If DNS lookup is already done in your log file, you must enter here hostname
# criteria, else enter ip address criteria.
# The opposite parameter of "SkipHosts" is "OnlyHosts".
# Note: Use space between each value. This parameter is not case sensitive.
# Note: You can use regular expression values writing value with REGEX[value].
# Change : Effective for new updates only
# Example: "127.0.0.1 REGEX[^192\.168\.] REGEX[^10\.]"
# Example: "localhost REGEX[^.*\.localdomain$]"
# Default: ""
#
# ローカルとLAN内(192.168.1.*)のアクセスは除外
SkipHosts="127.0.0.1 REGEX[^192\.168\.1\.]"

  :
  :
# Set your primary language (ISO-639-1 language codes).
# Possible value:
#  Albanian=al, Bosnian=ba, Bulgarian=bg, Catalan=ca,
#  Chinese (Taiwan)=tw, Chinese (Simpliefied)=cn, Croatian=hr, Czech=cz,
#  Danish=dk, Dutch=nl, English=en, Estonian=et, Euskara=eu, Finnish=fi,
#  French=fr, Galician=gl, German=de, Greek=gr, Hebrew=he, Hungarian=hu,
#  Icelandic=is, Indonesian=id, Italian=it, Japanese=jp, Korean=ko,
#  Latvian=lv, Norwegian (Nynorsk)=nn, Norwegian (Bokmal)=nb, Polish=pl,
#  Portuguese=pt, Portuguese (Brazilian)=br, Romanian=ro, Russian=ru,
#  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

  :
  :
3 ) 日本の検索エンジンが検索エンジンとして集計されるように設定
[root@linux ~]# vi /usr/share/awstats/lib/search_engines.pm 

  :
 :
@SearchEnginesSearchIDOrder_list1=(
# 以下を追加
# Japanese Search Engines
'google\.co\.jp',
'66\.249\.(89\.99|93\.104)',
'66\.102\.(7\.104|9\.104|11\.104)',
'64\.233\.(161\.104|179\.104|167\.104|183\.104|187\.104)',
'72\.14\.(203|207|209|221|235)\.104',
'216\.239\.(39\.104|41\.104|51\.104|57\.104|59\.104)',
'search\.biglobe\.ne\.jp',
'goo\.ne\.jp',
'nifty\.com',
'search\.msn\.co\.jp',
'search\.odn\.ne\.jp',
'excite\.ne\.jp',
'naver\.co\.jp',
'fresheye\.com',
'tocc\.co\.jp',
'infoseek\.co\.jp',
'cache\.yahoofs\.jp',
'ask\.jp',
'search\.livedoor\.com',
'www\.ceek\.jp',
 :
 :
%NotSearchEnginesKeys=(
# 以下を追加
# For Japanese Search Engines
'infoseek\.co\.jp'=>'at\.imfoseek\.co\.jp',
'goo\.ne\.jp'=>'members\.goo\.ne\.jp',
 :
 :
%SearchEnginesHashID = (
# 以下を追加
# Japanese Search Engines
'google\.co\.jp','googlejapan',
'66\.249\.(89\.99|93\.104)',,'googlejapan',
'66\.102\.(7\.104|9\.104|11\.104)','googlejapan',
'64\.233\.(161\.104|179\.104|167\.104|183\.104|187\.104)','googlejapan',
'72\.14\.(203|207|209|221|235)\.104','googlejapan',
'216\.239\.(39\.104|41\.104|51\.104|57\.104|59\.104)','googlejapan',
'search\.biglobe\.ne\.jp','biglobe',
'goo\.ne\.jp','goo',
'nifty\.com','nifty',
'search\.msn\.co\.jp','msnjapan',
'search\.odn\.ne\.jp','odn',
'excite\.co\.jp','excitejapan',
'naver\.co\.jp','naver',
'fresheye\.com','fresheye',
'tocc\.co\.jp','tocc',
'infoseek\.co\.jp','infoseek',
'cache\.yahoofs\.jp','yahoocache',
'ask\.jp','askjapan',
'search\.livedoor\.com','livedoor',
'www\.ceek\.jp','ceek',
 :
 :
%SearchEnginesKnownUrl=(
# 以下を追加
# Japanese Search Engines
'googlejapan','(p|q)=',
'biglobe','q=',
'goo','MT=',
'nifty','Text=',
'msnjapan','(q|MT)=',
'odn','Querystring=',
'excitejapan','search=',
'naver','query=',
'fresheye','kw=',
'tocc','QRY=',
'infoseek','qt=',
'yahoocache','w=',
'askjapan','q=',
'livedoor','q=',
'ceek','q=',
'clusty','query=',
 :
 :
# 以下を変更
@WordsToCleanSearchUrl= ('act=', 'annuaire=', 'btng=', 'cat=', 'categoria=', 'cfg=', 'cof=', 'cou=', 'count=',
    'cp=', 'dd=', 'domain=', 'dt=', 'dw=', 'enc=', 'exec=', 'geo=', 'hc=', 'height=', 'hits=', 'hl=', 'hq=',
    'hs=', 'id=', 'kl=', 'lang=', 'loc=', 'lr=', 'matchmode=', 'medor=', 'message=', 'meta=', 'mode=',
    'order=', 'page=', 'par=', 'pays=', 'pg=', 'pos=', 'prg=', 'qc=', 'refer=', 'sa=', 'safe=', 'sc=',
    'sort=', 'src=', 'start=', 'style=', 'stype=', 'sum=', 'tag=', 'temp=', 'theme=', 'type=', 'url=', 'user=',
    'width=', 'what=', '\\.x=', '\\.y=', 'y=', 'look=', 'target=', 'collection=', 'showSummary=', 'perPage=',
    'next=', 'DB=', 'OPE=', 'Max=', 'base=', 'submit=', 'SearchType=', 'SESSIONID=', 'QUERYRULE=', 'DISPLAYMIN=',
    'RELURLSWITCH=', 'SORT=', 'start=', 'direct=', 'relwd=', 'lk=', 'svx=', 'nh=', 'internet=', 'DC=',
    'submit0=', 'DEST=', 'where=', 'CCM=', 'NRS=', 'UNI=', 'UD0=', 'FRS=', 'sv=', 'rf=', 'oq=', 'col=',
    'act\.search=');
 :
 :
%SearchEnginesHashLib=(
# 以下を追加
# Japanese Search Engines
'googlejapan','Google Japan',
'biglobe','Biglobe',
'goo','Goo',
'nifty','Nifty',
'msnjapan','MSN Japan',
'odn','ODN',
'excitejapan','Excite Japan',
'naver','Naver',
'fresheye','Fresheye',
'tocc','TOCC/Search',
'infoseek','Infoseek',
'yahoocache','Yahoo Cache',
'askjapan','Ask Jeeves Japan',
'livedoor','Livedoor',
'ceek','CEEK.JP',
 :
 :
4 ) レポートの日付が、「月 11月 2004」となっている為、awstats.pl を修正し正しく表示されるように設定
[root@linux ~]# vi /usr/share/awstats/wwwroot/cgi-bin/awstats.pl 

# 7701行目付近
            else {
                print ">span style=\"font-size: 14px;\"<";
                if ($MonthRequired eq 'all') { print "$Message[6] $YearRequired"; }
                #else { print "$Message[5] $MonthNumLib{$MonthRequired} $YearRequired"; }
                else { print "$YearRequired $Message[6]".$MonthNumLib{$MonthRequired}; }
                print "</span>";
            }
3. Apache の設定
awstats.pl は、実行するたびに AWStats のデータベースからログ情報を入力してアクセス統計ページを作成するため、サーバーに負荷がかかることから、アクセス統計ページを HTML で作成し、閲覧するようにします。
1 ) Apache 設定ファイル /etc/httpd/conf/httpd.conf の編集
[root@linux ~]# vi /etc/httpd/conf/httpd.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 "/root/wwwroot/classes/"
#Alias /awstatscss "/root/awstats/wwwroot/css/"
#Alias /awstatsicons "/root/awstats/wwwroot/icon/"
#ScriptAlias /awstats/ "/root/wwwroot/cgi-bin/"

#
# This is to permit URL access to scripts/files in AWStats directory.
#
# コメントする
#<Directory "/root/wwwroot">
#    Options None
#    AllowOverride None
#    Order allow,deny
#    Allow from all
#</Directory>
2 ) Apache の AWStats アクセス設定ファイル /etc/httpd/conf.d/awstats.conf の編集
[root@linux ~]# 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
#</Directory>

# Additional Perl modules
# コメントにする
#<IfModule mod_env.c>
#    SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins
#</IfModule>
3 ) Apache への設定反映
[root@linux ~]# service httpd reload 
httpd を再読み込み中:                                      [  OK  ]
4. AWStats データベースの作成/更新
1 ) Apache のログを utf-8 にデコード
検索系サイトよりキーワードで検索されてきた場合、文字化が発生することがあります。これは、AWStats が utf-8 で作られているものの、キーワードが euc でログに出力される為に発生します。対応として、apacheのアクセスログを utf-8にデコードした後に集計を行うようにします。
※ デコードスクリプトは、nayuta氏 が公開している「conv_weblog_to_utf8.pl」を使用させて頂きました。

conv_weblog_to_utf8.pl をダウンロードし、/usr/share/awstats/wwwroot/cgi-bin へ保存します。
# 実行権限の付与
[root@linux ~]# chmod 700 /usr/share/awstats/wwwroot/cgi-bin/conv_weblog_to_utf8.pl 

# デコードの実行
[root@linux ~]# /usr/share/awstats/wwwroot/cgi-bin/conv_weblog_to_utf8.pl \
< /etc/httpd/logs/access_log \
> /etc/httpd/logs/access_log.utf8 
2 ) AWStats データベースの作成/更新
[root@linux ~]# /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp -update 
Update for config "/etc/awstats/awstats.mountainbigroad.jp.conf"
With data in log file "/var/log/httpd/access_log.utf8"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 0
Found 1821 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 121226 new qualified records.
5. アクセスログの自動集計(本格運用のための設定)
1 ) 閲覧用レポートのディレクトリ作成
[root@linux ~]# mkdir /var/www/html/awstats 
2 ) 閲覧用レポート自動生成シェルスクリプトを作成
[root@linux ~]# vi awstats.sh 

#!/bin/sh

YEAR=`date --date '1 days ago' +%Y`
MONTH=`date --date '1 days ago' +%m`

# httpのログファイルをデコードした上で一時ディレクトリに格納します。
# access_log.utf8は一時的にデコードしたログを保存するファイルの名前です。
/usr/share/awstats/wwwroot/cgi-bin/conv_weblog_to_utf8.pl \
< /var/log/httpd/access_log \
> /var/log/httpd/access_log.utf8

# AWStats データベースの作成/更新
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp -update

# 閲覧用レポート自動生成
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output -year=$YEAR -month=$MONTH -staticlinks > \
/var/www/html/awstats/$YEAR-$MONTH.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=alldomains -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.alldomains.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=allhosts -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.allhosts.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=lasthosts -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.lasthosts.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=unknownip -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.unknownip.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=alllogins -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.alllogins.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=lastlogins -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.lastlogins.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=allrobots -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.allrobots.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=lastrobots -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.lastrobots.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=urldetail -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.urldetail.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=urlentry -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.urlentry.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=urlexit -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.urlexit.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=browserdetail -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.browserdetail.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=unknownbrowsers -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.unknownbrowsers.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=unknownos -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.unknownos.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=refererse -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.refererse.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=refererpages -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.refererpages.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=keyphrases -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.keyphrases.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=keywords -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.keywords.html

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=mountainbigroad.jp \
-output=errors404 -staticlinks > \
/var/www/html/awstats/awstats.mountainbigroad.jp.errors404.html

# インデックスHTML
if [ "$YEAR$MONTH" = $(date +%Y%m) ]; then
  mv /var/www/html/awstats/$YEAR-$MONTH.html /var/www/html/awstats/index.html
fi
[root@linux ~]# chmod 700 awstats.sh 
3 ) 閲覧用レポート自動生成シェルスクリプトの実行
[root@linux ~]# ./awstats.sh 
Update for config "/etc/awstats/awstats.mountainbigroad.jp.conf"
With data in log file "/var/log/httpd/access_log.utf8"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 0
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.
4 ) スケジューラ(cron)への登録
[root@linux ~]# crontab -e 

# 毎日 00:00 に自動実行します。
00 00 * * * /root/awstats.sh > /dev/null 2>&1
5 ) /etc/cron.hourly/awstats の削除
1時間おきにAWStatsデータベース更新処理が実行されるように、インストール時に自動的に設定されていますので、これを削除しておきます。
[root@linux ~]# rm -f /etc/cron.hourly/awstats