본문 바로가기

개발질/CentOS(리눅스)

[리눅스] 웹로그 분석 프로그램 AWStats 설치하기

Webalizer도 많이 쓰이지만 AWStats는 Webalizer보다 깔끔한 인터페이스와 다양한 정보를 표시에 요즘엔 더 인기가 많은 웹로그 분석 프로그램입니다.
프로필파일 작성으로 분석할 로그파일을 나눌수 있어 편리하게 구성이 가능한 장점도 있습니다.
또한 한글화도 잘되어있습니다.

설치법 설명은 AWStats 6.9 버전 기준입니다.

프로그램 파일 다운로드 / 압축풀기

일단 가장 먼저 할것은 프로그램 다운로드입니다.
웹사이트 주소는 http://awstats.sourceforge.net 으로 이곳에서 최신파일을 받을 수 있습니다.

[root@sjworks src]# wget http://prdownloads.sourceforge.net/awstats/awstats-6.9.tar.gz
--00:10:35--  http://prdownloads.sourceforge.net/awstats/awstats-6.9.tar.gz
Resolving prdownloads.sourceforge.net... 216.34.181.59
Connecting to prdownloads.sourceforge.net|216.34.181.59|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://jaist.dl.sourceforge.net/project/awstats/AWStats/6.9/awstats-6.9.tar.gz [following]
--00:10:35--  http://jaist.dl.sourceforge.net/project/awstats/AWStats/6.9/awstats-6.9.tar.gz
Resolving jaist.dl.sourceforge.net... 150.65.7.130
Connecting to jaist.dl.sourceforge.net|150.65.7.130|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1125906 (1.1M) [application/x-gzip]
Saving to: `awstats-6.9.tar.gz'
100%[===========================================>] 1,125,906    726K/s   in 1.5s
00:10:37 (726 KB/s) - `awstats-6.9.tar.gz' saved [1125906/1125906]
[root@sjworks src]# tar zxvf awstats-6.9.tar.gz
...(생략)...
awstats-6.9/wwwroot/cgi-bin/lang/awstats-be.txt
awstats-6.9/wwwroot/cgi-bin/lang/awstats-pl.txt
awstats-6.9/wwwroot/cgi-bin/lang/awstats-he.txt
awstats-6.9/wwwroot/cgi-bin/lang/awstats-nl.txt
awstats-6.9/wwwroot/cgi-bin/lang/awstats-sk.txt
awstats-6.9/wwwroot/cgi-bin/awstats.pl
awstats-6.9/wwwroot/cgi-bin/awredir.pl
awstats-6.9/wwwroot/cgi-bin/awstats.model.conf
[root@sjworks src]#
※ 흰색으로 써져있는 글자가 입력한 글자입니다.

wget를 이용해서 프로그램을 다운받고 tar명령어로 압축을 풀었습니다.

프로그램 파일 위치 / 디렉토리(폴더) 생성

두번째로 프로그램 파일을 위치시키고, 필요한 디렉토리(폴더)를 생성합니다.

[root@sjworks src]# mv awstats-6.9/ /usr/local/awstats
[root@sjworks src]# chmod 755 /usr/local/awstats

프로그램 파일을 /usr/local/awstats 로 이동시켰습니다.
awstats에서 권장하는 프로그램 경로는 /usr/local/awstats 이지만 꼭 이곳으로 하지 않아도 무관합니다만, 프로그램 소스 일부를 수정해주어야 동작합니다.

[root@sjworks src]# mkdir /etc/awstats
[root@sjworks src]# mkdir /var/lib/awstats

프로그램 사용에 필요한 디렉토리도 생성해 줍니다.
/etc/awstats 는 프로필 파일이 위치하는 곳이고,
/var/lib/awstats 는 수집한 통계 데이터가 저장되는 곳입니다.
다른 경로 지정할려면 프로그램 소스 수정이 필요합니다.

프로그램 설정

프로그램 설정은 프로그램 파일중 tools 디렉토리 안에있는 awstats_configure.pl 파일로 진행합니다.

[root@sjworks src]# cd /usr/local/awstats/tools
[root@sjworks tools]# ./awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 1.8) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix

-----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
> /usr/local/apache/conf/httpd.conf

위 메세지는 아파치의 설정 파일의 경로를 적으라는 메세지입니다.
위와같이 적어주면 됩니다.

-----> Check and complete web server config file '/usr/local/server/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

아파치 설정파일의 로그설정이 common방식으로 되어있다는 경고메세지입니다.
AWStats는 combined 방식으로 설정이 되어있어야 제대로 작동합니다.
y를 누르면 설정 프로그램이 아파치 설정을 수정합니다.
n를 눌러 직접 해줘도 됩니다.
가상 호스트를 이용하여 구성하고 호스트별로 로그파일을 달리했을시에는 직접 설정파일을 수정해주셔야 합니다.(common -> combined)
로그 설정에 대해서 자세한 정보는 http://httpd.apache.org/docs/2.2/logs.html 를 참고하세요.

이어서 아파치 설정 파일에 AWStats 설정값이 추가됩니다.

  Add 'alias /awstatsclasses "usr/local/awstats/wwwroot/classes/"'
  Add 'alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
  Add 'alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
  Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
  Add '<Directory>' directive
  AWStats directives added to Apache config file.

-----> Update model config file '/usr/local/server/awstats/wwwroot/cgi-bin/awstats.model.conf'
  File awstats.model.conf updated.

-----> 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

새로운 프로필 파일을 생성할지에 대한 물음입니다.
AWStats는 프로필 파일당 분석할 로그파일을 달리하여 동시에 여러 로그를 분석할 수 있습니다.
y를 입력하면 아래와 같이 뜨게 됩니다.

-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> sjworks

프로필 파일 이름을 적습니다.
이 이름은으로 프로필 파일 이름이 생성되는데 프로필 파일 이름 형식은
awstats.(프로필이름).conf 입니다.

-----> 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

-----> Create config file '/etc/awstats/awstats.sjworks.conf'
 Config file /etc/awstats/awstats.sjworks.conf created.

-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/server/awstats/wwwroot/cgi-bin/awstats.pl -update -config=sjworks
Or if you have several config files and prefer having only one command:
/usr/local/server/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...(ENTER)

A SIMPLE config file has been created: /etc/awstats/awstats.sjworks.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'sjworks' with command:
> perl awstats.pl -update -config=sjworks
You can also read your statistics for 'sjworks' with URL:
> http://localhost/awstats/awstats.pl?config=sjworks
Press ENTER to finish...(ENTER)
You have new mail in /var/spool/mail/root
[root@sjworks tools]#

프로필 파일이 저장될 경로(/etc/awstats)를 입력하면
프로그램 설정이 완료됩니다.

프로필 파일 수정

이제 사용을 위한 프로필 설정을 위해 프로필 파일을 수정합니다.

[root@sjworks tools]# cd /etc/awstats
[root@sjworks awstats]# ls
awstats.sjworks.conf
[root@sjworks awstats]# vi awstats.sjworks.conf
[root@sjworks awstats]#

/etc/awstats 경로의 생성된 프로필 파일을 수정합니다.
자동생성된 파일에는 주석과 설정가능한 수많은 설정값이 존재하나 여기서 중요한것은 LogFile 값입니다.
초기에는 LogFile="/var/log/httpd/mylog.log"
로 입력되어있는것을 분석할 로그 파일 경로 수정해 줍니다.
예) LogFile="/usr/local/apache/logs/access_log"

언어설정은 Lang값을 통해서 이루어집니다.
Lang="auto"로 되어있는것을 Lang="ko"로 수정에 한글로 설정합니다.

로그 업데이트 실행 / Cron 등록

분석된 로그 자료를 웹에서 보려면 로그파일을 분석하는 업데이트가 실행이 되어야 합니다.
각 프로필별로 업데이트 실행법은 다음과 같습니다.
/usr/local/server/awstats/wwwroot/cgi-bin/awstats.pl -update -config=sjworks(프로필이름)

여러개의 프로필을 운영할때 한꺼번에 모든 프로필을 한번에 업데이트 할 수도 있습니다.
/usr/local/server/awstats/tools/awstats_updateall.pl now

매번 업데이트를 직접 실행해줄수는 없으니 cron을 이용하여 자동실행되게 합니다.

[root@sjworks awstats]# crontab -e

cron에 등록하기 위해 crontab을 실행합니다.

*/5 * * * * '/usr/local/awstats/tools/awstats_updateall.pl now'

보통 5분에 한번씩 실행하게 설정하는데 다음과 같이 추가적으로 입력해 줍니다.
※ crontab의 입력법은 vi에디터와 같습니다. 

crontab: installing new crontab
[root@sjworks awstats]#

적용이 완료되었습니다.

웹 접속

웹에서 AWStats 페이지로 접속하는 URL은 다음과 같습니다.
http://www.UserDomain.net/awstats/awstats.pl?config=(프로필명)