리눅스/기타

awstats 설치

Rohin 2018. 11. 22. 16:36
반응형

웹로그 분석으로 awstats 설치해서 분석하는 경우가 많다.

 

Centos 6.6 64bit // apache 2.4.3 // mysql 5.6.10 //  php 5.5.x

 

에서 awstats 를 설치진행하려고 한다.

 

awstats 압축파일을 받는다

 

http://awstats.sourceforge.net에서 최신버전을 다운로드 받을 수 있다.

해당 사이트를 접속해서 최신버전을 다운받는다.

 

해당서버를 서버에 올린뒤 압축을 푼다.

 

# tar zxvf awstats-7.5.tar.gz

 

# cp -arp awstats-7.5 /usr/local/awstats

 

# chmod -R 705 /usr/local/awstats

 

# cd /usr/local/awstats/tools

 

# perl awstats_configure.pl

 

 

-----> Check and complete web server config file '/usr/local/apache/conf/httpd.conf'
Warning: You Apache config file contains directives to write 'common' log files
This means that some features can't work (os, browsers and keywords detection).
Do you want me to setup Apache to write 'combined' log files [y/N] ? y

 

 apache 로그형식을 combined로 했는지를 확인하고 있다. 아직 combined로 안했더라도 나중에 설정하면 되므로 “y”

 

Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y
– 시스템에 awstats를 처음 설정 하는 것인지를 확인하고 있다. 처음이면 “y”를 아니면 “n”

Your web site, virtual server or profile name:
harulife.co.kr<– 설정파일 이름을 정한다.


Directory path to store config file(s) (Enter for default): (엔터) 
– 설정 디렉토리를 정한다. 보통 디폴트(/etc/awstats)로 설정한다.

 

아파치 conf 끝부분에 아래와같은 내용이 있는지 확인한다.

 

# vi /usr/local/apache/conf/httpd.conf

 

# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"

#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats/wwwroot">
    Options None
#    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

 

# vi /etc/awstats/awstats.harulife.co.kr.conf

                                        (처음 셋팅시 만들었던 명창)

해당 파일에 들어가서 몇가지 수정을 해준다.

 

#LogFile="/var/log/httpd/mylog.log"

LogFile="/usr/local/apache/logs/harulife.co.kr-access_log"

실제로 적용할 사이트 로그

 

#DirData="/var/lib/awstats"
DirData="/usr/local/awstats"

awstats 설치 경로

 

Lang="ko"
#Lang="auto"

적용시킬 언어

 

윗부분 적용시킨뒤 저장후 나오고 apache log 설정을 해줘야한다.

 

/usr/local/apache/conf/httpd.conf 내용

 

CustomLog "logs/access_log" common

CustomLog "logs/access_log" combined 으로 변경

 

/usr/local/apache/conf/extra/httpd-vhosts.conf 내용

 

CustomLog "logs/phpmyadmin.harulife.co.kr-access_log" common

CustomLog "logs/phpmyadmin.harulife.co.kr-access_log" combined 로 변경

 

 

변경하였다면 apache 재시작

 

 

/usr/local/awstats/tools/awstats_updateall.pl now

 

위 명령어로 정상적으로 등록되어었는지 확인한다.

 

만약 아래와같은 오류가나온다면.

 

Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=harulife.co.kr -configdir="/etc/awstats"' to update config harulife.co.kr
Create/Update database for config "/etc/awstats/awstats.harulife.co.kr.conf" by AWStats version 7.5 (build 20160301)
From data in log file "/usr/local/apache/logs/harulife.co.kr-access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
AWStats did not find any valid log lines that match your LogFormat parameter, in the 50th first non commented lines read of your log.
Your log file /usr/local/apache/logs/harulife.co.kr-access_log must have a bad format or LogFormat parameter setup does not match this format.
Your AWStats LogFormat parameter is:
1
This means each line in your web server log file need to have "combined log format" like this:
111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] "GET / HTTP/1.1" 200 1234 "http://www.fromserver.com/from.htm""Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
And this is an example of records AWStats found in your log file (the record number 50 in your log):
115.68.87.2 - - [23/May/2016:16:51:54 +0900] "POST / HTTP/1.1" 302 -
Setup ('/etc/awstats/awstats.harulife.co.kr.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).

 

위와같은 오류는 로그파일 형식이 다르기때문이다.

 

# vi /etc/awstats/awstats.harulife.co.kr.conf

 

해당파일을 열어서

 

#LogFormat=1
LogFormat=4

 

로 변경시켜준다.

 

# /usr/local/awstats/tools/awstats_updateall.pl now
Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=harulife.co.kr -configdir="/etc/awstats"' to update config harulife.co.kr
Create/Update database for config "/etc/awstats/awstats.harulife.co.kr.conf" by AWStats version 7.5 (build 20160301)
From data in log file "/usr/local/apache/logs/harulife.co.kr-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: 7994
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 7994 new qualified records.

 

변경한뒤 적용할시 위와같은 로그를 뿌려준다.

 

이제 웹에서 해당 awstats 를 확인한다.

 

http://harulife.co.kr/awstats/awstats.pl?config=harulife.co.kr

 

해당 웹주소로 가면 정상적으로 구동되는 부분이 확인된다.

 

이제 /usr/local/awstats/tools/awstats_updateall.pl now 해당명령어를 주기적으로 실행하기위해

crontab 설정을 해준다.

 

적용을 하다보면 forbidden 에러가 발생될수도있다.

 

그러할시엔 /usr/local/apache/conf/httpd.conf 파일을 통해 수정해준다.

 

<Directory />
    AllowOverride none
#    Require all denied
    Require all granted
</Directory>

 

위부분의 denied 부분을 granted 로 변경해준다.

 

이렇게 구동을 하였을시 소스코드가 그대로 출력된다면!!!

 

LoadModule cgid_module modules/mod_cgid.so

 

AddHandler cgi-script .cgi .pl

 

위 두가지 설정을 해주면된다.