ハマログ

株式会社イーツー・インフォの社員ブログ

AWStatsのyumインストールと移転

はじめに

AWStatsが入っているサーバの引っ越しをしています。

AWStatsはログを解析してグラフィカルに表示してくれるソフトウェアです。


(AWStatsロゴ)

詳しくはAWStatsの公式サイトを参照
https://awstats.sourceforge.io/

説明を公式サイトより引用
AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically.

インストール

CentOS7&Apache Httpd Server2.4環境です

yumでインストール
yum install awstats
成功すると、conf.d配下にawstats.confが自動的に生成されます。

[root@/]# cd /etc/httpd/conf.d/
[root@conf.d]# ll
-rw-r--r-- 1 root root  366  6月 27 22:49 README
-rw-r--r-- 1 root root 2926  6月 27 22:48 autoindex.conf
-rw-r--r-- 1 root root 1184  1月  8  2018 awstats.conf
-rw-r--r-- 1 root root  691  4月 13 04:04 php.conf
-rw-r--r-- 1 root root 9443  6月 27 03:07 ssl.conf
-rw-r--r-- 1 root root 1252  6月 27 03:07 userdir.conf
-rw-r--r-- 1 root root  824  6月 27 03:07 welcome.conf

標準の間だとローカルアクセスのみ許可されているため、IPを追加します
vim /etc/httpd/conf.d/awstats.conf
IP許可設定を追加

Require local
# ↓add
Require ip 999.999.999.999

ブラウザでアクセスしてみると、以下のようなエラーが表示されました
Error: Couldn't open config file "awstats.hostname.conf" nor "awstats.conf". Please read the documentation for directories where the configuration file should be located. 

- Did you use the correct URL ?
Example: http://localhost/awstats/awstats.pl?config=mysite
Example: http://127.0.0.1/cgi-bin/awstats.pl?config=mysite
- Did you create your config file 'awstats.hostname.conf' ?
If not, you can run "awstats_configure.pl" from command line, or create it manually.

Check config file, permissions and AWStats documentation (in 'docs' directory).

/etc/awstats/ 配下のコンフィグファイルは、 /etc/awstats/awstats.【hostname】.conf とする必要があるようです。
mv awstats.hostname.conf awstats.www.example.com.conf
この時点で画面をブラウザで確認できるようになりました(データがないのでまだ0)
続いて、導入する環境にあわせた設定をおこないます。 設定ファイルは上記でファイル名を変更した、/etc/awstats/awstats.【hostname】.conf です。
vim /etc/awstats/awstats.hostname.conf
変更箇所はおそらくこのあたり
# ローテーションしているので、標準で付属しているマージツールを利用する
LogFile="/usr/share/awstats/tools/logresolvemerge.pl /var/log/httpd/www*example-access_log | "

# ウェブサイトのドメインとエイリアス
SiteDomain="www.example.com"
HostAliases="example.com www.example.com 127.0.0.1 localhost"

# 集計対象外のIPアドレス
SkipHosts="127.0.0.1 999.999.999.999"
集計は自動でおこなわれないので、何らかの方法でコマンドを定期実行する必要があります。今回は crontab.

crontabに登録する前に動作確認します。
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=www.example.com -update
フォルダに存在する Apache ログ分のアクセス情報が表示されました
グラフが更新されたら、crontabに登録します。
# 1日1回集計(1分単位とかでも問題なし)
00 2 * * * /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.example.com
ここまでで導入は完了です。続いてデータ移行作業をおこないます。

設定ファイルで集計情報の保存ディレクトリを調べます。
[root@etc awstats]# cat awstats.hostname.conf | grep DirData=
DirData="/var/lib/awstats"
# dynamic value for DirData (for example DirData="/home/__REMOTE_USER__") and
[root@etc awstats]#
データ格納ディレクトリがわかったので、移行元サーバのデータをコピーします。
表示できました!
Analyticsawstatshttpdlogyum

  kaneko tomo   2018年9月30日


関連記事

Dockerについてあれこれ

最近Dockerでローカル環境を構築したりしてるので、ここまでに調べた事・気づい…

Amazon Linux2でLocaleを変更してみた

  はじめに どうも!T-utsuです。 最近なにかとAWSをいじるこ…

Lambdaとは?何語?意味?

はい、どーも! 社内でJava8のラムダ式の話が出た際に、 「ラムダについてブロ…


← 前の投稿

次の投稿 →