Ubuntu 10.04에 AWstats 설치하기

아파치 웹로그를 분석하는 툴로 가장 많이 알려진 것이 webalizer입니다.

webalizer보다도 좀 더 강력한 분석 결과를 제공하는 것이 AWstats 인데, 이를 우분투에 설치하는 방법입니다. 다음의 문서를 참조하였습니다. : http://ubuntu-tutorials.com/2008/01/16/configuring-awstats-on-ubuntu-server/

1. 패키지 설치

다음 명령어로 먼저 awstats를 설치합니다.

sudo apt-get install awstats libgeoip1 libgeoip-dev libgeo-ip-perl

2. conf 파일 수정

각 virtual host 별로 conf 파일을 만들어주어야 합니다. host 명을 domain.tld 라고 하면, 다음과 같은 형식으로 새로 config 파일을 하나 생성해줍니다. 저의 경우에는 localhost로 명명했습니다.

sudo cp /etc/awstats/awstats.conf /etc/awstat/awstats.domain.tld.conf

그리고 생성된 파일을 수정합니다.

sudo vi /etc/awstats/awstats.domain.tld.conf

이 때 수정할 항목으로는

  • LogFile=”/var/log/apache2/access.log”
  • LogFormat=1
  • SiteDomain=”domain.tld”
  • HostAliases=”www.domain.tld localhost 127.0.0.1″

위와 같은 것들이 있습니다.

추가적으로 GeoCity 정보를 이용하기 위해서는 다음과 같이 데이터파일을 직접 다운받아 설치합니다.

wget
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz  (위의 줄까지 한 줄입니다)
gzip -d GeoLiteCity.dat.gz
sudo mv GeoLiteCity.dat /usr/share/GeoIP

또한 GeoIP를 활성화 시키기 위해서 다음 라인을 활성화 시켜고, GeoIP.dat 파일 경로를 적어줍니다.

  • DNSLookup=0
  • LoadPlugin=”geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat”

추가적으로 GeoCity 정보를 활성화하려면 아래 라인을 활성화시켜줍니다.

  • LoadPlugin=”geoip GEOIP_STANDARD /usr/share/GeoIP/GeoLiteCity.dat”

3. apache 설정

저의 경우에는 다음과 같이 awstats.conf 파일을 새로 하나 만들었습니다.

sudo vi /etc/apache2/conf.d/awstats.conf

파일 내용은 다음과 같습니다.

Alias /awstatsclasses “/usr/share/awstats/lib/”
Alias /awstats-icon/ “/usr/share/awstats/icon/”
Alias /awstatscss “/usr/share/doc/awstats/examples/css”
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

저장하고, apache를 재시작합니다.

sudo /etc/init.d/apache2 restart

4. 과거 로그 파일 처리하기

저의 경우에는 logrotate가 설치되어 있기에, 과거 gz로 압축된 로그들을 처리해야 했습니다. 다음과 같은 명령어를 통해 간단하게 과거의 로그들을 하나로 통합해서 분석할 수 있습니다.

이 때 주의할 점은, awstats는 가장 마지막으로 parse된 파일 이후의 것만 처리하기 때문에 과거 로그를 먼저 import 한 다음에 최신 로그를 처리해야 한다는 것입니다. 즉 4번 단계를 먼저 하고 5번 단계를 하시면 되며, 과거 쌓인 내역이 없거나 분석하기 원치 않으시는 경우에는 바로 5번 단계로 넘어가시면 됩니다.

cd /var/log/apache2
gzip -d access.log.*.gz
sudo /usr/share/doc/awstats/examples/logresolvemerge.pl access.log.* >> access_combined.log
sudo /usr/lib/cgi-bin/awstats.pl -config=localhost -LogFile=”/var/log/apache2/access_combined.log”

아마 초기 업데이트에는 많은 시간이 소요될 것입니다.

5. 업데이트

최근 로그(access.log)는 아래와 같은 명령어를 통해 업데이트 가능합니다.

sudo /usr/lib/cgi-bin/awstats.pl -config=domain.tld -update

이를 아래와 같이 crontab 에 등록시켜두면 매 시간마다 자동으로 로그를 바탕으로 업데이트하게 됩니다.

6. cron에 등록

sudo crontab -e

그리고 아래 내용을 등록합니다.

0 * * * * /usr/lib/cgi-bin/awstats.pl -config=domain.tld -update >/dev/null

7. 확인

위와 같이 모든 셋업 과정이 끝납니다. 웹브라우저에서 아래 주소로 접속하면 됩니다.

http://domain.tld/awstats/awstats.pl

저의 경우에는 도메인 이름을 localhost로 등록해서, 아래와 같이 접속해야 했습니다.

http://domain.tld/awstats/awstats.pl?config=localhost

대화에 참여

댓글 1개

댓글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다