[리눅스] webalizer를 통한 apache log(웹서버 접속 통계) 분석하기
OS : CentOS 5.4
UTIL : Webalizer Version 2.21
1. 설치하기
yum -y install GeoIP-data GeoIP-devel GeoIP # 국가별 로그 남기기 (GeoIP 설치)
yum -y install webalizer (주의 : 영문으로 컴파일되어 있음)
- http://www.mrunix.net/webalizer/download.html 에서 소스를 다운로드 받는다.
wget ftp://ftp.mrunix.net/pub/webalizer/webalizer-2.21-02-src.tar.bz2
bzcat webalizer-2.21-02-src.tar.bz2 | tar xvf -
cd webalizer-2.21-02
./configure --prefix=/usr/local/webalizer \
--with-language=korean \
--with-pnglib=/usr/lib \
--with-gdlib=/usr/lib \
--with-gd=/usr/include \
--enable-geoip \
--with-geoip=/usr/include \
--with-geoiplib=/usr/lib \
--enable-flags
make
mv /usr/bin/webalizer /usr/bin/webalizer.org
cp webalizer /usr/bin/webalizer (한글판으로 대체하기)
2. 가상호스트 서버에 대한 설정하기
- 먼저 /etc/httpd/conf/httpd.conf 에서 VirtualHost설정 내역과 일치하여야 한다.
mkdir -p /etc/webalizer/conf
cd /etc/webalizer/conf
vi exam.conf (exam 은 자신의 가상호스트명을 사용하면 된다)
---------------------------------------------------------
LogFile /var/log/httpd/exam.domain.net-access_log
OutputDir /var/www/usage/exam
HistoryName /var/www/usage/exam/webalizer.hist
ReportTitle 사용량 통계 :
HostName exam.domain.net
Incremental yes
IncrementalName /var/www/usage/exam/webalizer.current
GeoIP yes
GeoIPDatabase /var/lib/GeoIP/GeoIP.dat
CountryFlags yes
FlagDir flags
---------------------------------------------------------
3. 분석결과 저장 디렉토리 만들기
mkdir -p /var/www/usage/exam # OutputDir 만들기
4. 하루에 한번씩 수행되게 하기 (crond)
- 파일명이 왜 00webalizer냐면, logrotate 보다 먼저 실행시키기 위함이다
vi /etc/cron.daily/00webalizer
----------------------------------------
# VirtualHost들에 대한 접속통계
for f in `ls /etc/webalizer/conf/*.conf`
do
/usr/bin/webalizer -c $f
done
----------------------------------------
5. Apache에 mod_geoip 설치하기 (DSO 방식)
wget http://geolite.maxmind.com/download/geoip/api/mod_geoip2/mod_geoip2_1.2.5.tar.gz
zcat mod_geoip2_1.2.5.tar.gz | tar xvf -
cd mod_geoip2_1.2.5
/usr/sbin/apxs -a -i -L/var/lib -I/usr/include -lGeoIP -c mod_geoip.c
6. 아파치 GeoIP 설정하기
/etc/httpd/conf/httpd.conf 설정
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{Host}i %{GEOIP_COUNTRY_CODE}e" common
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /var/lib/GeoIP/GeoIP.dat
< /IfModule>
7. 아파치 재시동
/sbin/service httpd restart
8. 국가별 국기(아이콘) 설치하기
mkdir /var/www/usage/flags
cd /var/www/usage/flags
wget http://flags.blogpotato.de/zip/small/world.zip
unzip world.zip
cd /var/www/usage/exam
ln -s ../flags ./
9. 분석 결과 만들기
for f in `ls /etc/webalizer/conf/*.conf` ; do /usr/bin/webalizer -c $f ; done
10. 수행결과 (예제)
http://usage.inmu.net/ezsimple/