LoginSignup
0
0

More than 3 years have passed since last update.

AWSでAwstatsのインストール

Posted at

AWSでAwstatsのインストールをしたので、メモ代わりに投稿します。
Awstatsって、まだ需要あるのかな?

Awstatsのインストールと設定方法

apacheのログの形式を変更
Awstatsをインストールする前に、先にapacheのログの形式を変更。

$ vi /etc/httpd/conf/httpd.conf

以下の様に、変更。

CustomLog logs/access_log common
↓
CustomLog logs/access_log combined

次はAWstatsのダウンロード。
最新版は7.8。

$ wget http://prdownloads.sourceforge.net/awstats/awstats-7.8.tar.gz

ダウンロードしたファイルを解凍。

$ tar zxvf awstats-7.8.tar.gz

解凍したディレクトリのcgi-binディレクトリに移動。

$ cd awstats-7.8/wwwroot/cgi-bin

このディレクトリ内のファイルを全てapacheのcgiが動作するディレクトリにコピー。AWSだと場所は/var/www/cgi-bin/

$ cp -r * /var/www/cgi-bin/

一つ上のディレクトリに移動して、iconディレクトリを/var/www/html/にコピー。

$ cd ../

$ cp -r icon/ /var/www/html/

cgi-binディレクトリに移動。

$ cd /var/www/cgi-bin/

awstats.model.confをawstats.ドメイン.confという名前でコピー。
たとえば、ドメイン名がnewstweet.jpの場合は、awstats.newstweet.jp.confという名前でコピー。

$ cp awstats.model.conf awstats.newstweet.jp.conf

次は、今作成した設定ファイルの編集。

$ vi awstats.newstweet.jp.conf

次はLogFileを自分のログファイルの位置に変更。

# 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/mylog.log"
↓
LogFile="/var/log/httpd/access_log"(自分のアクセスログを指定)

LogTypeの値を確認。 今回はwebのログを取得するのでWのままでOK。

# Enter the log file type you want to analyze.
# Possible values:
# W - For a web log file
# S - For a streaming log file
# M - For a mail log file
# F - For a ftp log file
# Example: W
# Default: W
#
LogType=W

次に、LogTypeの値を確認。 最初にログの形式をcombinedに変更しているので、1であるかを確認。

# Examples for Apache combined logs (following two examples are equivalent):
# LogFormat = 1
# LogFormat = "%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
#
# Example for IIS:
# LogFormat = 2
#
LogFormat=1

Sitedomainには自分のドメインを入れる。

# If analyzing mail log, enter here the domain name of mail server.
# Example: "myintranetserver"
# Example: "www.domain.com"
# Example: "ftp.domain.com"
# Example: "domain.com"
#
SiteDomain=""
↓
SiteDomain="newstweet.jp"(自分のドメイン名を入れる)

DNSLookupの値を1に変更。

# 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=2
↓
DNSLookup=1

apacheのログのパーミッションを変更

$ sudo chmod 755 /var/log/httpd
$ sudo chmod 644 /var/log/httpd/access_log

その他の項目はそのままでOK。 解析後データはawstats.plと同じディレクトリに置かれる。(今回の場合は /var/www/cgi-bin/)
基本的な設定はここまで。
次に統計の作成を行う。

$ perl awstats.pl -config=newstweet.jp -update

newstweet.jpの部分を自分のドメイン名に変更して実行することで統計が作成。

Create/Update database for config "./awstats.newstweet.jp.conf" by AWStats version 7.8 (build 20200416)
From data in log file "/var/log/httpd/access_log"...
(省略)

上記の様なメッセージが表示されれば成功。
統計が作成できたらブラウザから

http://newstweet.jp/cgi-bin/awstats.pl

にアクセスし、統計情報が見られるか確認。
統計情報が見られればAWstatsの導入は完了。

cronに定期的(1分毎)に解析を行うように設定

最後に1分毎に自動更新の設定
cronを行います。

crontab -e

以下を追加「-config=」には/etc/awstats/にある設定ファイル名ではなく、awstats設定ファイル内の「SiteDomain」に定義されたドメイン名を設定。

*/01 * * * * perl /var/www/cgi-bin/awstats.pl -config=newstweet.jp -update > /dev/null 2>&1

これで1分ごとに解析が行われているはず。

最後に・・・

今回、インストールしたAwstatsのアクセス解析を公開しているので、参考にどうぞ!
newstweet.jpのアクセス解析

アクセス解析を見て、アクセスの少なさに同情した方は、こちらをお願いします。
NewsTweet|Twitterで注目されているニュースが分かる

参考にしたサイト
Awstatsのインストールと設定方法 - Denet Tech Lib.
Apacheログ解析ツールAwstatsの導入
AWStats:/var/log/apache2/access.logにアクセスできません

0
0
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
0
0