'AWStats'에 해당되는 글 1건

  1. 2011.01.21 awstats 설치 하기 / apache log analysis

아파치 로그를 관리하는데 뭔가 특별한 도구가 필요한 시점이 다가왔습니다.
물론 기존에 사용하던 cat과  sort 등을 몇개의 파이프 명령어만으로 결과를 볼 수 있었지만
사람들이 어떠한 형태로 서비스를 이용하는지를 보고 싶어서 말이죠.

awstats은 프로그램을 설치하고 로그파일을 로드해서 자체DB형태로 분석해서 적재를 합니다.
적재가 완료되면 Apache를 통해 리포트를 볼 수 있도록 하고 있는 구조로써 각각의 단계를 따라서 확인해 보겠습니다.


1. 프로그램 다운로드 
   http://awstats.sourceforge.net/ 이곳에서 다운로드 받을 수 있습니다. 
   저는 awstats-7.0.tar.gz 버전을 다운로드 받았답니다.  (이후의 설명도 해당 버전 중심 설명)


2. 다운로드 받은 파일의 압축을 풉니다.
[neouserTest(neouser):/factory/work/neouser/work_awstats> tar xvfz awstats-7.0.tar.gz
awstats-7.0/
awstats-7.0/README.TXT
awstats-7.0/tools/
....... 700 정도 파일의 압축이 풀립니다..........
awstats-7.0/docs/index.html


3. 링크를 등록합니다.
[neouserTest(neouser):/usr/local> ln -s /factory/work/neouser/work_awstats/awstats-7.0 awstats

 이과정은 해도 그만 안해도 그만입니다.
 저의 경우 테스트 서버가 공용이라 /usr/local 을 더럽히고 싶지않아 위와 같이 설정 정보를 개인폴더로 추출해 놨습니다.  / 앞으로의 과정에서 폴더를 새롭게 지정하는 방식에 대해서도 함께 소개 될 예정입니다.


4. awstats 설치

[neouserTest(neouser):/usr/local/awstats/tools> ./awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 1.9) (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
Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/data2/factory/work/neouser/work_awstats/awstats-7.0
to standard directory:
/usr/local/awstats
And then, run configure.pl from this location.
Do you want to continue setup from this NON standard directory [yN] ? y

-----> Check for web server install
  Found Web server Apache config file '/usr/local/apache/conf/httpd.conf'

-----> 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
  Add 'Alias /awstatsclasses "/data2/factory/work/neouser/work_awstats/awstats-7.0/wwwroot/classes/"'
  Add 'Alias /awstatscss "/data2/factory/work/neouser/work_awstats/awstats-7.0/wwwroot/css/"'
  Add 'Alias /awstatsicons "/data2/factory/work/neouser/work_awstats/awstats-7.0/wwwroot/icon/"'
  Add 'ScriptAlias /awstats/ "/data2/factory/work/neouser/work_awstats/awstats-7.0/wwwroot/cgi-bin/"'
  Add '<Directory>' directive
  AWStats directives added to Apache config file.

-----> Update model config file '/data2/factory/work/neouser/work_awstats/awstats-7.0/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

-----> 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:
> neouserweb
  : 여기는 나중에 awstats 를 웹브라우져에서 볼때 parameter 가 됩니다.

-----> 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):
> /factory/work/neouser/work_awstats/awstats-7.0
  : 그냥 Enter 를 입력하면 /etc/awstats에 설치됩니다만 이렇게 경로를 지정하면
    해당 경로에 설치가 된답니다.


-----> Create config file '/factory/work/neouser/work_awstats/awstats-7.0/awstats.daumblog.conf'
 Config file /factory/work/neouser/work_awstats/awstats-7.0/awstats.daumblog.conf created.

-----> Restart Web server with '/sbin/service httpd restart'
httpd: unrecognized service

-----> 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:
/data2/factory/work/neouser/work_awstats/awstats-7.0/wwwroot/cgi-bin/awstats.pl -update -config=daumblog
Or if you have several config files and prefer having only one command:
/data2/factory/work/neouser/work_awstats/awstats-7.0/tools/awstats_updateall.pl now
Press ENTER to continue...


A SIMPLE config file has been created: /factory/work/neouser/work_awstats/awstats-7.0/awstats.daumblog.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'daumblog' with command:
> perl awstats.pl -update -config=daumblog
You can also read your statistics for 'daumblog' with URL:
> http://localhost/awstats/awstats.pl?config=daumblog

Press ENTER to finish...



설치과정에서 몇번의 질문을 입력받는데 위의과정을 참고 하시면 되겠습니다. 


5. 환경변수 설정하기 
환경변수는 매우 중요한 역할을 합니다. 나중에 DB만들때 어디서 어떤 로그파일을 찾아야 하는지와 언어에 대한 부분도 있습니다.


[neouserTest(neouser):/usr/local/awstats>vi awstats.neouserweb.conf

해당 위치는 링크를 걸어두었기 때문에 바로 찾아갈 수 있다는점? 알고 계시죠? (ln -s ...)

파일의 내용이 생각보다 많아서 변경이 필요한 부분만 언급드리도록 합니다. 


....
#LogFile="/var/log/httpd/mylog.log"  (기본 설정값)
LogFile="/data2/factory/work/neouser/work_awstats/log/110105.access_log"
....
#
LogFormat=1  # 로그포멧이 IIS가 아니라면 그냥 1번 이랍니다.
....
# Enter the log file type you want to analyze.
....
# Example: "ftp.domain.com"
# Example: "domain.com"
#
SiteDomain="neouserweb"   
       ## 이게 왜 이런 값을 가지는지 이해가죠? 설치에서 정한이름

....
#
#DirData="/var/lib/awstats"
DirData="/data2/factory/work/neouser/work_awstats/lib/awstats"
       ## 여기에 로그파일을 분석한 자체 DB가 쌓입니다.

....
# Default: "auto"
#
#Lang="auto"
Lang="ko"  ## 언어타입을 변경합니다.
....


사실 문서를 더욱 자세하게 봐야하는데 결과를 보고 싶은 욕심에 쉽게 눈에 띄는 부분만 옵션을 변경했습니다.   설정이 잘 안되는 경우 (http://awstats.sourceforge.net/) 에서 더 깊은 정보를 얻으시길 바랍니다. 


6. 로그도 잘 설정했으니 이제 DB를 만들어 볼까요!
로그가 잘 로드가 되었다면 이제 아파치 로그파일로 DB를 만들어야 합니다.
저는 앞서 경로를 awstats가 권장하는 루트를 이요하지 않았습니다. 그래서 DB만들때 추가적인 변경사항이 있습니다. 

[neouserTest(neouser):/factory/work/neouser/work_awstats/awstats-7.0/wwwroot/cgi-bin> vi awstats.pl

  my $configdir         = shift;
    my @PossibleConfigDir = (
            "$DIR",
            "/data2/factory/work/neouser/work_awstats/awstats-7.0", ## 추가
            "/etc/awstats",
            "/usr/local/etc/awstats", "/etc",
            "/etc/opt/awstats"
        );


원래는 3개의 경로만 찾습니다. 하지만 새롭게 만든 곳이 있는터라 위의 경로를 추가시켜 줍니다. 
저장을 한다음 DB를 만들어내는 실행을 해보겠습니다.

가장 시간이 많이 걸리는 부분이기 때문에 이작업을 하고 기다리셔야 합니다.
지루하다면 그 시간을 이용해서 저같이 블로그를 작성해서 정보들을 공유하는것은 어떨까요? ^^ 

[neouserTest(neouser):/factory/work/neouser/work_awstats/awstats-7.0/wwwroot/cgi-bin> ./awstats.pl -update -config=neouserweb
Error: AWStats database directory defined in config file by 'DirData' parameter (/data2/hanmail/work/neouser/work_awstats/lib/awstats) does not exist or is not writable.
Setup ('/data2/hanmail/work/neouser/work_awstats/awstats-7.0/awstats.daumblog.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).
[blogtest(hanadmin):/hanmail/work/neouser/work_awstats/awstats-7.0/wwwroot/cgi-bin> ./awstats.pl -update -config=daumblog
Create/Update database for config "/data2/hanmail/work/neouser/work_awstats/awstats-7.0/awstats.daumblog.conf" by AWStats version 7.0 (build 1.971)
From data in log file "/data2/hanmail/work/neouser/work_awstats/log/110105.web2n.blog.activity_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)...
Flush history file on disk (unique url reach flush limit of 5000)
......
......
Flush history file on disk (unique url reach flush limit of 5000)
Jumped lines in file: 0
Parsed lines in file: 2044734
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 4933 corrupted records,
 Found 0 old records,
 Found 2039801 new qualified records.



7. 리포트를 보기 위한 Apache 설정하기
이제 얼마 남지 않았습니다. DB까지 생성된 awstats는 이제 리포트를 볼 수 있도록 하는 apache 설정 과정을 눈앞에 두고 있습니다.  열씨미!! 열씨미!!

<VirtualHost 127.0.0.1>
        ServerAdmIn neouser@neouser.net
        DocumentRoot "/usr/local/awstats/wwwroot/"
        ServerName awstats

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

        <Directory "/usr/local/awstats/wwwroot">
            Options None
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
</VirtualHost>


이렇게 설정하는 것은 이미  apache도 공용으로 사용하고 있을테고 그래서 IP라도 급하게 사용하려는 의도랍니다. 애써 이런것이 필요없다면 좋겠지만 다양한 사례가 존재하니까요.
root 계정으로 apache를  restart 하시면 이제 awstat를 볼 수 있을 준비가 된것입니다.


8. 리포트를 봅시다!!
주소표시줄에  URL 을 입력합니다. 

http://127.0.0.1/awstats/awstats.pl?config=neouserweb

















 

1 

글 보관함

카운터

Total : / Today : / Yesterday :
get rsstistory!