웹 로그 분석기 awstats 설치 + GeoIP, GeoCity Plugin 설치
작성자 : neosky (seroot.com, nple.com)
작성일자 : 2010. 05. 04.
※ 퍼가실때는 반드시 댓글과 출처를 남겨주세요. ^^
오늘은 아파치 웹 로그를 분석해서 다양한 정보를 그래프로 보여주는
awstats 설치에 대해 알아보겠습니다.
(과거에는 webalizer 로그 분석기를 많이 선호하였으나, 깔끔한 인터페이스와 다양한 정보 분석을
해준다는 점에서 awstats 를 쓰는 추세입니다. ^^)
공식 홈페이지 : http://awstats.sourceforge.net/
라이센스 : GNU GPL
배포버전 : 7.0 beta (2010-05-02), 6.95 (2009-10-25)
2000-05-02 1.0 버전을 시작으로 현재 6.95 버전이 최신 버전입니다.
여기서는 6.95 버전을 기준으로 설명합니다.
다운로드 URL : http://awstats.sourceforge.net/#DOWNLOAD
파일 URL : http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz
1. 파일 다운로드, 압축 해제, 디렉토리 이동
2010-05-04 09:28:45 (33.6 MB/s) - `awstats-6.95.tar.gz' saved [1138306/1138306]
# tar xvfz awstats-6.95.tar.gz
awstats-6.95/
awstats-6.95/README.TXT
awstats-6.95/docs/
awstats-6.95/docs/COPYING.TXT
awstats-6.95/docs/LICENSE.TXT
awstats-6.95/docs/awstats.pdf
awstats-6.95/docs/awstats_benchmark.html
awstats-6.95/docs/awstats_changelog.txt
awstats-6.95/docs/awstats_compare.html
awstats-6.95/docs/awstats_config.html
awstats-6.95/docs/awstats_contrib.html
awstats-6.95/docs/awstats_extra.html
awstats-6.95/docs/awstats_faq.html
... 이하 생략
# mv awstats-6.95 /usr/local/awstats
`awstats-6.95' -> `/usr/local/awstats'
2. 사용자 권한 부여, 작업 디렉토리 생성
# chown -R root.root /usr/local/awstats
changed ownership of `/usr/local/awstats/README.TXT' to root:root
changed ownership of `/usr/local/awstats/tools/awstats_exportlib.pl' to root:root
changed ownership of `/usr/local/awstats/tools/awstats_updateall.pl' to root:root
changed ownership of `/usr/local/awstats/tools/maillogconvert.pl' to root:root
changed ownership of `/usr/local/awstats/tools/awstats_buildstaticpages.pl' to root:root
changed ownership of `/usr/local/awstats/tools/urlaliasbuilder.pl' to root:root
changed ownership of `/usr/local/awstats/tools/httpd_conf' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.datademo2.xml' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.datademo1.xslt' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.datademo2.xslt' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.xsd' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.datademo1.xml' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/README.txt' to root:root
... 이하 생략
# chmod 755 /usr/local/awstats
`/usr/local/awstats'의 모드를 0755(rwxr-xr-x)으로 유지하였습니다
# mkdir /etc/awstats
# mkdir /var/lib/awstats
3. 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
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.comExample: demo
Your web site, virtual server or profile name:
> nple.com <--- 자신의 도메인 명을 넣는다.-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
> /etc/awstats엔터
엔터
4. awstats 도메인 환경설정 파일 생성, 아파치 로그 형식 설정
# cd /etc/awstats
# vi ./awstats.nple.com.conf <== 파일 이름 형식은 항상 awstats.도메인명.conf 입니다.
*** 51번째 줄에서 사이트에 맞는 로그 파일경로로 수정합니다.
LogFile="/var/log/httpd/mylog.log" ==> LogFile="/usr/local/apache/logs/nple.com-access_log"
*** 905번째 줄에서 한글로 웹 로그 분석을 보기 위해 Lang 값을 수정합니다.
Lang="auto" ==> Lang="ko"
# cat /usr/local/awstats/tools/httpd_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 /usr/local/apache/conf/httpd.conf 파일이나 버추얼호스트 설정 파일을 열어 로그 형식을 바꿔줍니다.
CustomLog /usr/local/apache/logs/nple.com-access_log
==>
SetEnvIfNoCase Request_URI (gif|png|jpg|css|js|bmp|jpeg|swf)$ IMAGE=1
CustomLog /usr/local/apache/logs/nple.com-access_log combined env=!img-nosave,!CodeRedNimda
그리고, 아파치 재시작
# /etc/init.d/apachectl restart
5. 웹 로그 분석기 수동 실행, 웹에서 확인
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=nple.com
Create/Update database for config "/etc/awstats/awstats.nple.com.conf" by AWStats version 6.95 (build 1.943)
From data in log file "/usr/local/apache/logs/nple.com-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: 1
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 1 new qualified records.
http://nple.com/awstats/awstats.pl?config=nple.com
< Lang="auto" 로 했을때 영문 출력화면 >
< Lang="ko" 로 했을때 한글 출력화면 >
6. cron 으로 스케쥴링 설정
매번 서버에서 명령을 실행하는 작업은 번거로울 수 있습니다.
주기적으로 로그 분석을 실행하기 위해 cron 에서 설정해주도록 합니다.
# vi /etc/crontab
*/30 * * * * root /etc/cron.weblog/awstats.sh > /dev/null 2>&1
*** 필자는 30분 단위로 /etc/cron.weblog/awstats.sh 스크립트를 실행합니다.
awstats.sh 스크립트는 다시 아래와 같이 구성합니다.
여러 사이트를 분석해야할 경우 편리하게 추가하여 사용할 수 있습니다.
# mkdir /etc/cron.weblog
# vi /etc/cron.weblog/awstats.sh
----------------------------------------------------------------------------------------
#/bin/sh
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=nple.com
----------------------------------------------------------------------------------------
# chmod 700 /etc/cron.weblog/awstats.sh
7. 국가 Flag, City 표시 Plugin 설치
아래와 같이 유입 IP의 국가별 FLAG를 출력하기 위해서는 서버에 GeoIP 가 설치되어 있어야 합니다.
GeoIP URL : http://www.maxmind.com/
7-1. GeoIP C API 설치
다운로드 URL :
http://www.maxmind.com/app/c파일 URL :
http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz*** GCC 가 서버에 설치되어 있어야 합니다.
7-2. Perl 모듈 설치
awstats 아파치 분석툴에 적용하기 위해 Perl 모듈을 다운로드 받아 설치합니다.
다운로드 URL :
http://www.maxmind.com/app/perl?rid=awstatDownload Geo::IP Perl Module
Download Geo::IP::PurePerl Module
7-3. 데이터베이스 다운로드 및 설치
7-4. awstats 환경설정 파일에 GeoIP, GeoIPCity 데이터베이스 파일 연결
# vi /etc/awstats/awstats.nple.com.conf
1312번째줄 주석처리된 다음 줄에 아래와 같이 적어줍니다.
LoadPlugin="geoip GEOIP_STANDARD /usr/local/lib/GeoIP.dat"
1353번째줄 주석처리된 다음 줄에 아래와 같이 적어줍니다.
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/lib/GeoIPCity.dat"
웹에서 로그 분석기를 열어보면 왼쪽에 국가 아래에 Cities 메뉴가 생긴 것을 볼 수 있고,
예와 같이 Flag, City가 표시 되는 것을 확인할 수 있습니다.
당신의 의견을 작성해 주세요.