awstatインストール

## 目的

* Apacheのログをtxt形式で見るのにうんざり。いい加減サマライズしてくれるツールから見たいという事でawstatを利用してみた。

## 記載範囲

* centos7へのインストールまで。

### 環境

|項目|値|備考|
|---|---|---|
|ホストOS|Win10 Home|｜
|仮想化ソフトウェア|VirtualBox|以下でIPは192.168.56.60|
|ゲストOS         |cnetos7  |                      |

## 参考資料 

* http://yokensaka.com/centos/?p=307

## 構築手順

1, awstatsをyumからインストール

```bash
yum install -y awstats
```

2, 不要な設定ファイルを削除しておく

```bash
rm -rf /etc/awstats/awstats.localhost.localdomain.conf
rm -rf /etc/awstats/awstats.centos7.localdomain.conf
```

3, 設定ファイルのコピー

```bash
cp /etc/awstats/awstats.model.conf /etc/awstats/awstats.192.168.56.60.conf
```

4, 設定ファイルの編集

```bash
vi /etc/awstats/awstats.192.168.56.60.conf

------------------------
LogFile="/var/log/httpd/access_log"
LgFile="/root/log/ssl_access_log.%YYYY-0%MM-0%DD"

HostAliases="localhost 127.0.0.1"
HostAliases="localhost 127.0.0.1 REGEX[^10\.243\.\.]"

DNSLookup=2
DNSLookup=1

#LoadPlugin="tooltips"
LoadPlugin="tooltips"

#LoadPlugin="geoipfree"
LoadPlugin="geoipfree"
------------------------
```

5, AWStatsデータベース初期作成スクリプト作成

```bash
vi awstatsinit.sh
------------------------
#!/bin/sh
logfile=`grep ^LogFile /etc/awstats/awstats.$1.conf|sed -e 's/LogFile="\([^ ]*\)"/\1/p' -e d`
for log in `ls $logfile*|sort -r`
do
`rpm -ql awstats|grep "awstats\.pl"` \
-config=$1 -update -logfile=$log
done
------------------------
```

6, awstatsデータベース初期作成スクリプト実行
※エラー解消しなかったのでgeoipfreeは諦めた

```bash
Error: Plugin load for plugin 'geoipfree\ failed with return code: Error: Can't locate Geo/IPfree.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /usr/share/awstats/lib /usr/share/awstats/plugins /usr/share/awstats/wwwroot/cgi-bin/plugins) at (eval 4) line 1.

http://yasutam.blogspot.com/2015/12/webyumawstats.html
yum install perl-CPAN
perl -MCPAN -e shell

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

install Geo::IPfree

[local::lib] install Geo::IPfree


Warning: You do not have write permission for Perl library directories.

To install modules, you need to configure a local Perl library directory or
escalate your privileges.  CPAN can help you by bootstrapping the local::lib
module or by configuring itself to use 'sudo' (if available).  You may also
resolve this problem manually if you need to customize your setup.

What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
 [local::lib] sudo

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] yes
Trying to fetch a mirror list from the Internet
Fetching with LWP:
http://www.perl.org/CPAN/MIRRORED.BY
Fetching with LWP:
http://www.perl.org/CPAN/MIRRORED.BY.gz
Fetching with LWP:
ftp://ftp.perl.org/pub/CPAN/MIRRORED.BY
Fetching with LWP:
ftp://ftp.perl.org/pub/CPAN/MIRRORED.BY.gz
Fetching with Net::FTP:
ftp://ftp.perl.org/pub/CPAN/MIRRORED.BY

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

New urllist
  http://mirror.rise.ph/cpan/
  http://ftp.kr.freebsd.org/pub/CPAN/
  http://mirror.amberit.com.bd/CPAN/

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.

sh awstatsinit.sh 192.168.56.60
Create/Update database for config "/etc/awstats/
Create/Update database for config "/etc/awstats/awstats.web.conf" by AWStats version 7.7 (build 20180105)
From data in log file "/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 1228
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 8 corrupted records,
 Found 0 old records,
 Found 1220 new qualified records.
```

7, Apache用AWStats設定ファイル編集

```bash
cp -p /etc/httpd/conf.d/awstats.conf /etc/httpd/conf.d/awstats.conf.org
vi /etc/httpd/conf.d/awstats.conf

Require local
↓
Require all granted
```

8, 接続確認

```
# 以下にアクセス
http://192.168.56.60/awstats/awstats.pl
```