トップ > Fedora Core4によるサーバーの構築 >

ログ解析(Awstats)

Awstatsのインストール

 Awstatsを利用することにより,Apache,Squid及びPostfixのアクセスログを解析することができます。

  1. rootでログインする。
  2. 以下のコマンドを実行して,Awstatをインストールする。
    # yum install awstats
  3. 以下のようなAwstatsに関するファイルタイプの設定内容を,/etc/selinux/targeted/src/policy/file_contexts/program/mypolicy.fcに追加する。
    /usr/share/awstats/wwwroot/cgi-bin(/.*)? system_u:object_r:httpd_sys_script_exec_t
    /var/lib/awstats(/.*)? system_u:object_r:httpd_sys_content_t
  4. 以下のコマンドを実行して,設定をシステムに反映させる。
    # cd /etc/selinux/targeted/src/policy
    # make clean
    # make reload
    # fixfiles relabel

Apacheのアクセスログ解析

  1. rootでログインする。
  2. /etc/awstats/awstats.apache.confを以下のように作成する。
    LogFile="/var/log/httpd/access_log"
    LogType=W
    LogFormat=1
    # 当サイトのドメイン名
    SiteDomain="www.shitomi.jp"
    # 上記以外の当サイトのドメイン名(正規表現)
    HostAliases="REGEX[^.*\.shitomi\.(net|com)$]"
    DNSLookup=1
    DirData="/var/lib/awstats"
    DirCgi="/awstats"
    DirIcons="/awstatsicons"
    EnableLockForUpdate=1
    # DNSの逆引きを行わないIPアドレス(正規表現)
    SkipDNSLookupFor="REGEX[^192\.168\.0\.]"
    # 閲覧を許可するIPアドレスの範囲
    AllowAccessFromWebToFollowingIPAddresses="192.168.0.1-192.168.0.254"
    SkipHosts="127.0.0.1 REGEX[^192\.168\.0\.]"
    Lang="jp"
  3. SELinuxのPermissiveモードで以下のコマンドを実行することにより,アクセスログ分析結果のHTMLファイルが作成される。
    # /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=apache
  4. http://192.168.0.1/awstats/awstats.pl?config=apacheにアクセスして,Awstatsの動作を確認する。

Squidのログ解析

  1. rootでログインする。
  2. /etc/awstats/awstats.squid.confを以下のように作成する。
    LogFile="/var/log/squid/access.log"
    LogType=W
    LogFormat=4
    # 当サイトのドメイン名
    SiteDomain="ns.shitomi.jp"
    DNSLookup=2
    DirData="/var/lib/awstats"
    DirCgi="/awstats"
    DirIcons="/awstatsicons"
    EnableLockForUpdate=1
    # 閲覧を許可するIPアドレスの範囲
    AllowAccessFromWebToFollowingIPAddresses="192.168.0.1-192.168.0.254"
    Lang="jp"

    LevelForBrowsersDetection=0
    LevelForOSDetection=0
    LevelForRefererAnalyze=0
    LevelForRobotsDetection=0
    LevelForSearchEnginesDetection=0
    LevelForKeywordsDetection=0
    LevelForWormsDetection=0

    ShowDomainsStats=0
    ShowRobotsStats=0
    ShowFileSizesStats=0
    ShowOSStats=0
    ShowBrowsersStats=0
    ShowOriginStats=0
    ShowKeyphrasesStats=0
    ShowKeywordsStats=0
  3. SELinuxのPermissiveモードで以下のコマンドを実行することにより,アクセスログ分析結果のHTMLファイルが作成される。
    # /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=squid
  4. http://192.168.0.1/awstats/awstats.pl?config=squidにアクセスして,Awstatsの動作を確認する。

Postfixのログ解析

  1. rootでログインする。
  2. /etc/awstats/awstats.postfix.confを以下のように作成する。
    LogFile="perl /usr/share/awstats/tools/maillogconvert.pl standard < /var/log/maillog |"
    LogType=M
    LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"
    # 当サイトのドメイン名
    SiteDomain="mail.shitomi.jp"
    DNSLookup=2
    DirData="/var/lib/awstats"
    DirCgi="/awstats"
    DirIcons="/awstatsicons"
    EnableLockForUpdate=1
    # 閲覧を許可するIPアドレスの範囲
    AllowAccessFromWebToFollowingIPAddresses="192.168.0.1-192.168.0.254"
    Lang="jp"

    LevelForBrowsersDetection=0
    LevelForOSDetection=0
    LevelForRefererAnalyze=0
    LevelForRobotsDetection=0
    LevelForSearchEnginesDetection=0
    LevelForKeywordsDetection=0
    LevelForFileTypesDetection=0
    LevelForWormsDetection=0

    ShowMonthStats=UHB
    ShowDaysOfMonthStats=HB
    ShowDaysOfWeekStats=HB
    ShowHoursStats=HB
    ShowDomainsStats=0
    ShowHostsStats=HBL
    ShowRobotsStats=0
    ShowEMailSenders=HBML
    ShowEMailReceivers=HBML
    ShowSessionsStats=0
    ShowPagesStats=0
    ShowFileTypesStats=0
    ShowFileSizesStats=0
    ShowOSStats=0
    ShowBrowsersStats=0
    ShowOriginStats=0
    ShowKeyphrasesStats=0
    ShowKeywordsStats=0
    ShowMiscStats=0
    ShowHTTPErrorsStats=0
    ShowSMTPErrorsStats=1
  3. SELinuxのPermissiveモードで以下のコマンドを実行することにより,アクセスログ分析結果のHTMLファイルが作成される。
    # /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=postfix
  4. http://192.168.0.1/awstats/awstats.pl?config=postfixにアクセスして,Awstatsの動作を確認する。

 このサイトに書かれていることが原因でトラブルが発生しても,私は責任を取ることができません。したがいまして,ここで述べられていることに関する実行は,自己責任でお願いいたします。なお,このサイトはリンクフリーで,リンク時の連絡も不要です。

サイト内関連リンク:Apache, Squid, Postfix