6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Apacheアクセスログの解析ツール(AWStats)を使用する

Posted at

WEBページの閲覧状況確認のため、Apacheアクセスログ解析ツール(AWStats)を使用してみた。

Ubuntu 14.04

パッケージをインストールする。

$ sudo aptitude install awstats

awstats設定を変更する。
※仮想ホスト設定を使用しているため、解析対象のログファイル指定を変える必要があった。

$ sudo vi /etc/awstats/awstats.conf
--- a/awstats/awstats.conf
+++ b/awstats/awstats.conf
@@ -48,7 +48,7 @@
 # If there are several log files from load balancing servers :
 # Example: "/pathtotools/logresolvemerge.pl *.log |"
 #
-LogFile="/var/log/apache2/access.log"
+LogFile="/var/log/apache2/other_vhosts_access.log"


 # Enter the log file type you want to analyze.
@@ -120,7 +120,7 @@ LogType=W
 # Example for IIS:
 # LogFormat = 2
 #
-LogFormat=4
+LogFormat = "%virtualname:%other %host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"


 # If your log field's separator is not a space, you can change this parameter.
@@ -151,7 +151,7 @@ LogSeparator=" "
 # Example: "ftp.domain.com"
 # Example: "domain.com"
 #
-SiteDomain=""
+SiteDomain="home.local"


 # Enter here all other possible domain names, addresses or virtual host
@@ -210,7 +210,7 @@ DirData="/var/lib/awstats"
 # Example: "/awstats"
 # Default: "/cgi-bin"   (means awstats.pl is in "/yourwwwroot/cgi-bin")
 #
-DirCgi="/cgi-bin"
+DirCgi="/awstats"


 # Relative or absolute web URL of your awstats icon directory.

ログ解析実行スケジュールの設定ファイルを修正する。
※デフォルトのままではスクリプトがログファイルにアクセスできないため、ログファイルのパーミッションかcron実行アカウントのどちらかを修正する必要あり。

$ sudo vi /etc/cron.d/awstats
--- a/cron.d/awstats
+++ b/cron.d/awstats
@@ -1,6 +1,6 @@
 MAILTO=root

-*/10 * * * * www-data [ -x /usr/share/awstats/tools/update.sh ] && /usr/share/awstats/tools/update.sh
+*/10 * * * * root [ -x /usr/share/awstats/tools/update.sh ] && /usr/share/awstats/tools/update.sh

 # Generate static reports:
-10 03 * * * www-data [ -x /usr/share/awstats/tools/buildstatic.sh ] && /usr/share/awstats/tools/buildstatic.sh
+10 03 * * * root [ -x /usr/share/awstats/tools/buildstatic.sh ] && /usr/share/awstats/tools/buildstatic.sh

apache設定フィアルを作成する。
※デフォルトでは存在しないので作成する必要あり。

$ cat <<EOS | sudo tee /etc/apache2/sites-available/awstats.conf
Alias /awstats-icon/ /usr/share/awstats/icon/
Alias /awstats/ /usr/lib/cgi-bin/
<Location /awstats>
    Options FollowSymLinks MultiViews ExecCGI
    Require ip 192.168.0
</Location>
<FilesMatch "\.pl$">
    AddHandler cgi-script .pl
</FilesMatch>
EOS
$ sudo a2enmod cgi
$ sudo a2ensite awstats
$ sudo service apache2 restart

アクセス確認

CentOS 7

パッケージをインストールする。

$ sudo yum install awstats

apache設定フィアルを変更する。
※アクセス許可変更

$ sudo vi /etc/httpd/conf.d/awstats.conf
--- awstats.conf.org    2015-11-23 17:33:57.513830080 +0900
+++ awstats.conf        2015-11-23 17:34:07.343830053 +0900
@@ -26,7 +26,7 @@
     AllowOverride None
     <IfModule mod_authz_core.c>
         # Apache 2.4
-        Require local
+        Require ip 192.168.0
     </IfModule>
     <IfModule !mod_authz_core.c>
         # Apache 2.2

httpdサービスを再起動する。

$ sudo systemctl restart httpd.service
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?