最終更新日: 2017.11.25




[root@centos ~]# wget http://prdownloads.sourceforge.net/awstats/awstats-7.3-1.noarch.rpm ← AWStatsダウンロード


[root@centos ~]# rpm -ivh awstats-7.3-1.noarch.rpm ← AWStatsインストール

[root@centos ~]# rm -f awstats-7.3-1.noarch.rpm ← ダウンロードしたファイルを削除

[root@centos ~]# vi `rpm -ql awstats|grep "awstats\.pl"` ← awstats.pl編集
※レポートの日付形式を「月 2月 2010」から「2010年 2月」へ変更
                                if ( $MonthRequired eq 'all' ) {
                                        print "$Message[6] $YearRequired";
                                else {
                                          #"$Message[5] $MonthNumLib{$MonthRequired} $YearRequired"; ← 行頭に#を追加してコメントアウト
                                          "$YearRequired$Message[6] ".$MonthNumLib{$MonthRequired}; ← 追加(日付をYYYY年 MM月形式にする)

                        print( $MonthRequired eq 'all'
                                ? "$Message[6] $YearRequired"
                                #: "$Message[5] " ← 行頭に#を追加してコメントアウト
                                  #. $MonthNumLib{$MonthRequired} ← 行頭に#を追加してコメントアウト
                                  #. " $YearRequired" ← 行頭に#を追加してコメントアウト
                                : "$YearRequired$Message[6] $MonthNumLib{$MonthRequired}" ← 追加(日付をYYYY年 MM月形式にする)

                                        #print "$MonthNumLib{$monthix}<br />$YearRequired"; ← 行頭に#を追加してコメントアウト
                                        print "$YearRequired$Message[6]<br />$MonthNumLib{$monthix}"; ← 追加(日付をYYYY年 MM月形式にする)
                                        #print "$MonthNumLib{$monthix} $YearRequired"; ← 行頭に#を追加してコメントアウト
                                        print "$YearRequired$Message[6] $MonthNumLib{$monthix}"; ← 追加(日付をYYYY年 MM月形式にする)


[root@centos ~]# touch /etc/httpd/conf.d/awstats.conf ← Apache用AWStats設定ファイル作成

[root@centos ~]# cd /usr/local/awstats/ ← AWStats設定スクリプト格納ディレクトリへ移動

[root@centos awstats]# perl /usr/local/awstats/tools/awstats_configure.pl ← AWStats設定スクリプト実行

----- AWStats awstats_configure 1.0 (build 20140126) (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

-----> 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):
> /etc/httpd/conf.d/awstats.conf ← Apache用AWStats設定ファイル名応答

-----> Check and complete web server config file '/etc/httpd/conf.d/awstats.conf'
  Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
  Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
  Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
  Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
  Add '' 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
file (required if first install) [y/N] ? y ← y応答(AWStats設定ファイル作成)

-----> 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:
> centossrv.jp ← サイト名応答(例:centossrv.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):
> ← 空ENTER(AWStats設定ファイル作成先はデフォルト=/etc/awstats)

-----> Create config file '/etc/awstats/awstats.centossrv.jp.conf'
 Config file /etc/awstats/awstats.centossrv.jp.conf created.

-----> Restart Web server with '/sbin/service httpd restart'
Redirecting to /bin/systemctl restart  httpd.service

-----> 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/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=centossrv.jp
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...

A SIMPLE config file has been created: /etc/awstats/awstats.centossrv.jp.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'centossrv.jp' with command:
> perl awstats.pl -update -config=centossrv.jp
You can also read your statistics for 'centossrv.jp' with URL:
> http://localhost/awstats/awstats.pl?config=centossrv.jp

Press ENTER to finish...

[root@centos awstats]# cd ← ディレクトリ移動(ホームへ戻る)

[root@centos ~]# vi /etc/awstats/awstats.centossrv.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 are several log files from load balancing servers :
# Example: "/pathtotools/logresolvemerge.pl *.log |"
LogFile="/var/log/httpd/access_log" ← Apacheアクセスログファイル名を指定

# Enter here all other possible domain names, addresses or virtual host
# aliases someone can use to access your site. Try to keep only the minimum
# number of possible names/addresses to have the best performances.
# You can repeat the "SiteDomain" value in this list.
# This parameter is used to analyze referer field in log file and to help
# AWStats to know if a referer URL is a local URL of same site or an URL of
# another site.
# Note: Use space between each value.
# Note: You can use regular expression values writing value with REGEX[value].
# Note: You can also use @/mypath/myfile if list of aliases are in a file.
# Example: "www.myserver.com localhost REGEX[mydomain\.(net|org)$]"
HostAliases=" localhost REGEX[^192\.168\.1\.]" ← 自ホストおよび内部(例:192.168.1.x)からのアクセスをアクセス元(リファラ)から除外する

# Do not include access from clients that match following criteria.
# If your log file contains IP addresses in host field, you must enter here
# matching IP addresses 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: " REGEX[^192\.168\.] REGEX[^10\.]"
# Example: "localhost REGEX[^.*\.localdomain$]"
# Default: ""
SkipHosts=" localhost REGEX[^192\.168\.1\.]" ← 自ホストおよび内部(例:192.168.1.x)からのアクセスをアクセス元(クライアント)から除外する

# 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 ← アクセス元の名前解決を行う(アクセス元をIPアドレスではなくホスト名で表示する)

# Plugin: GeoIPfree
# Perl modules required: Geo::IPfree version 0.2+ (from Graciliano M.P.)
# Country chart is built from an Internet IP-Country database.
# This plugin is useless for intranet only log files.
# Note: You must choose between using this plugin (need Perl Geo::IPfree
# module, database less up to date) or the GeoIP plugin (need Perl Geo::IP
# module from Maxmind, database more up to date).
# Note: Activestate provide a corrupted version of Geo::IPfree 0.2 Perl
# module, so install it from elsewhere (from www.cpan.org for example).
# This plugin reduces AWStats speed of 10% !
LoadPlugin="geoipfree" ← コメント解除(アクセス元国情報を詳細に取得)

# When AWStats builds HTML links in its report pages, it starts those links
# with "http://". However some links might be HTTPS links, so you can enter
# here the root of all your HTTPS links. If all your site is a SSL web site,
# just enter "/".
# This parameter is not used if ShowLinksOnUrl is 0.
# Example: "/shopping"
# Example: "/"
# Default: ""
UseHTTPSLinkForUrl="/" ← /を指定Webサーバー間通信内容暗号化を導入している場合のみ

[root@centos ~]# yum -y install perl-CPAN ← perl-CPANインストール

[root@centos ~]# perl -MCPAN -e shell ← perl-CPAN起動

CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.

Would you like to configure as much as possible automatically? [yes] ← 空ENTER

Autoconfigured everything but 'urllist'.

Now you need to choose your CPAN mirror sites.  You can let me
pick mirrors for you, you can select them from a list or you
can enter them by hand.

Would you like me to automatically choose some CPAN mirror
sites for you? (This means connecting to the Internet) [yes] ← 空ENTER
Trying to fetch a mirror list from the Internet
Fetching with LWP:

Looking for CPAN mirrors near you (please be patient)
.......................... done!

New urllist

Autoconfiguration complete.

commit: wrote '/root/.cpan/CPAN/MyConfig.pm'

You can re-run configuration any time with 'o conf init' in the CPAN shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.9800)
Enter 'h' for help.

cpan[1]> install Geo::IPfree ← Geo::IPfreeモジュールインストール

cpan[2]> quit ← perl-CPAN終了
Terminal does not support GetHistory.
Lockfile removed.


[root@centos ~]# vi awstatsinit.sh ← AWStatsデータベース初期作成スクリプト作成

# データベース作成先ディレクトリ作成
mkdir -p `grep ^DirData /etc/awstats/awstats.$1.conf | awk -F= '{print $2}'|tr -d \"`

# AWStats設定ファイルよりApacheログファイル名取得
logfile=`grep ^LogFile /etc/awstats/awstats.$1.conf|sed -e 's/LogFile="\([^ ]*\)"/\1/p' -e d`

# 過去ログを古い順に処理
grep dateext /etc/logrotate.conf > /dev/null 2>&1
if [ $? -eq 0 ]; then
    ls $logfile-* > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        # 過去ログファイル名に日付が設定されている場合
        for log in `ls $logfile-*|sort`
            `rpm -ql awstats|grep "awstats\.pl"` \
            -config=$1 -update -logfile=$log
    ls $logfile.* > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        # 過去ログファイル名に通番が設定されている場合
        for log in `ls $logfile.*|sort -r`
            `rpm -ql awstats|grep "awstats\.pl"` \
            -config=$1 -update -logfile=$log

# 現在ログ処理
for log in `ls $logfile|sort`
    `rpm -ql awstats|grep "awstats\.pl"` \
    -config=$1 -update -logfile=$log

[root@centos ~]# sh awstatsinit.sh centossrv.jp ← AWStatsデータベース初期作成スクリプト実行

[root@centos ~]# rm -f awstatsinit.sh ← AWStatsデータベース初期作成スクリプト削除

[root@centos ~]# vi /etc/cron.daily/awstats ← AWStatsデータベース自動更新設定スクリプト作成
for conf in `ls /etc/awstats/|grep -v awstats.model.conf`
    site=`echo $conf|sed -e 's/awstats\.\([^ ]*\)\.conf/\1/p' -e d`
    `rpm -ql awstats|grep "awstats\.pl"` -config=$site -update > /dev/null

[root@centos ~]# chmod +x /etc/cron.daily/awstats ← AWStatsデータベース自動更新設定スクリプトへ実行権限付加

[root@centos ~]# vi /etc/logrotate.d/httpd ← Apacheログローテーション設定ファイル編集
/var/log/httpd/*log {
        `rpm -ql awstats|grep "awstats_updateall\.pl"` now -confdir="/etc/awstats" \
        -awstatsprog="`rpm -ql awstats|grep "awstats\.pl"`" >/dev/null
        /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true

[root@centos ~]# vi /etc/httpd/conf.d/awstats.conf ← Apache用AWStats設定ファイル編集
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
    Require all granted ← 追加(Order句、Allow句のApache2.4変更対応)
    #Order allow,deny ← 行頭に#を追加してコメントアウト
    #Allow from all ← 行頭に#を追加してコメントアウト

[root@centos ~]# systemctl reload httpd ← Apache設定反映





[root@centos ~]# mkdir /var/www/awstatsreport ← HTML版格納ディレクトリ作成

[root@centos ~]# vi /etc/httpd/conf.d/awstatsreport.conf ← HTML版格納ディレクトリアクセス設定ファイル作成
Alias /awstatsreport "/var/www/awstatsreport"
<Location "/awstatsreport">
    Require all denied
    Require ip
    Require ip ← 内部ネットワークアドレスを指定

[root@centos ~]# vi /etc/httpd/conf.d/awstats.conf ← Apache用AWStats設定ファイル編集
<Files "awstats.pl">
    Require all denied
    Require ip
    Require ip ← 内部ネットワークアドレスを指定

[root@centos ~]# systemctl reload httpd ← Apache設定反映

[root@centos ~]# vi awstatsreport.sh ← アクセス統計ページHTML版作成スクリプト作成


reportbuild() {
    # AWStatsデータベース更新中断時ロックファイル残存対処(ここから)
    if [ -f /tmp/awstats.$site.lock ]; then
        ps -p `cat /tmp/awstats.$site.lock |awk '{print $6}'`
        if [ $? -ne 0 ]; then
            echo /tmp/awstats.$site.lock removed >&2
            rm -f /tmp/awstats.$site.lock 
    # AWStatsデータベース更新中断時ロックファイル残存対処(ここまで)
    `rpm -ql awstats|grep "awstats_buildstaticpages\.pl"` \
    -awstatsprog="`rpm -ql awstats|grep "awstats\.pl"`"\
    -config=$site -update -lang=jp -dir=$dir \
    -year=$YEAR -month=$MONTH -builddate=$YEAR$MONTH
    # 個別ページリンク切れ対処(ここから)
    sed -i "s/href=\"${site}/href=\"awstats.${site}/g" \
    # 個別ページリンク切れ対処(ここまで)
    if [ "$YEAR$MONTH" = $(date +%Y%m) ]; then
        mv $dir/awstats.$site.$YEAR$MONTH.html $dir/index.html
        mv $dir/awstats.$site.$YEAR$MONTH.html $dir/$YEAR$MONTH.html

ls $dir/* > /dev/null 2>&1
if [ $? -eq 0 ]; then
    YEAR=`date --date '1 days ago' +%Y`
    MONTH=`date --date '1 days ago' +%m`
    DirData=`grep ^DirData /etc/awstats/awstats.model.conf|awk -F= '{print $2}'|tr -d \"`
    for log in `ls $DirData/awstats*.$site.txt`
        YEAR=`echo $log|cut -d / -f 5|cut -d . -f 1|sed -e 's/awstats..\([^ ]*\)/\1/p' -e d`
        MONTH=`echo $log|cut -d / -f 5|cut -d . -f 1|sed -e 's/awstats\([^ ]*\)..../\1/p' -e d`

[root@centos ~]# chmod 700 awstatsreport.sh ← アクセス統計ページHTML版作成スクリプトへ実行権限付加

[root@centos ~]# ./awstatsreport.sh centossrv.jp /var/www/awstatsreport ← アクセス統計ページHTML版作成スクリプト実行
※awstatsreport.shを実行して以下のようなエラーメッセージが出力される場合は、「908 awstatsreport.sh の実行エラー」の10の書き込みを参考にして対処する
/root/awstatsreport.sh: /usr/bin/awstats_buildstaticpages.pl: /usr/bin/perl^M: bad interpreter: No such file or directory mv: cannot stat `/var/www/awstatsreport/awstats.centossrv.jp.200807.html': No such file or directory


[root@centos ~]# echo "00 00 * * * root /root/awstatsreport.sh centossrv.jp /var/www/awstatsreport > /dev/null" > /etc/cron.d/awstatsreport
 ← cron登録



Copyright© 2005-2017 fallenangels, All rights reserved.