블로그 이미지
좋은느낌/원철
이것저것 필요한 것을 모아보렵니다.. 방문해 주셔서 감사합니다..

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Notice

    2009. 7. 16. 16:44 개발/Linux 계열

    일반적으로 웹로그 분석은 Webalizer를 많이 사용하나, 여기서는 보다 괜찮은 인터페이스 및 한글화된 awstats를 설치하는 방법을 알아보도록 한다.





    우선, 필자가 테스트한 배포판은 김정균씨의 안녕리눅스를 devel로 설치하였고, Apache 1.3.29 버전이다. RedHat 7.3 및 9 버전에서도 설치하는데 문제는 없었다.





        관련사이트 : http://awstats.sourceforge.net


        데모사이트 : http://awstats.sourceforge.net/cgi-bin/awstats.pl





    1. 다운로드





      다음 주소에서 awstats 6.2 버전을 다운받아 설치하려는 서버로 옮겨 놓는다.





        http://lec.pe.kr/files/awstats-6.2.tgz








    2. 압축 풀기, 기본 디렉토리 생성





        # tar xvfz awstats-6.2.tgz


        # mv awstats-6.2 /usr/local/awstats


        # chmod 755 /usr/local/awstats/


        # chown -R root.root /usr/local/awstats/


        # mkdir /etc/awstats


        # mkdir /var/lib/awstats








    3. 설치 스크립트 실행





        # cd /usr/local/awstats/tools


        # ./awstats_configure.pl





      설치 중에 3번 정도 물어보는데, 아파치 환경설정파일의 절대경로 위치와, 처음 설치시 설정파일 생성 여부('y'로 답하면 된다), 그리고 임의의 이름을 정하면 된다. 필자는 nfo.pe.kr 사이트에 로그분석기를 설치하므로 세 번째의 이름을 nfo.pe.kr로 적었다.








    4. 설정파일의 수정





      이제 /etc/awstats/ 디렉토리 밑에 awstats.[자신이 정한 이름].conf 파일이 생성된 것을 볼 수 있다. 필자의 경우 파일명은 다음과 같다.





        /etc/awstats/awstats.nfo.conf





      이 파일을 열어서 51번째 라인의 LogFile의 지정 값을 로그 분석하고자 하는 파일명으로 수정한다. 일반적으로 아파치 로그파일은 /var/log/httpd/ 디렉토리에 위치할 것이다. 다음은 필자의 경우 수정한 예제이다.





        # cat /etc/awstats/awstats.nfo.conf | grep ^LogFile


        LogFile="/var/log/httpd/nfo.pe.kr-access_log"








    5. httpd.conf 파일의 수정





      필자의 경우 안녕 배포판에 rpm으로 Apache를 설치하였으므로 Apache 환경설정파일의 위치는 /etc/httpd/conf/httpd.conf 파일이다. 


      위에서 /usr/local/awstats/tools 디렉토리에 있는 awstats_configure.pl 파일을 실행하여 제대로 설치하였다면 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>





      혹시 httpd.conf 파일에 위의 내용이 추가되어 있지 않다면 /usr/local/awstats/tools/httpd_conf 파일의 내용을 그대로 복사하여 httpd.conf 파일에 넣어주면 된다.





      또한 httpd.conf 파일에서 로그 파일의 포맷을 combined 로 변경해 주어야 한다. 일반적으로 로그파일의 포맷은 common으로 되어 있는 경우가 대부분이다. 필자 역시 다음과 같이 common 포맷으로 되어 있었다.





        CustomLog /var/log/httpd/nfo.pe.kr-access_log common env=!img-nosave,!CodeRedNimda





      이것을 다음과 같이 combined로 수정하여 준다.





        CustomLog /var/log/httpd/nfo.pe.kr-access_log combined env=!img-nosave,!CodeRedNimda








    6. 기존 로그파일의 내용 삭제, Apache 재시작





      기존의 로그파일인 /var/log/httpd/nfo.pe.kr-access_log 파일의 포맷이 common에서 combined로 변경되었으므로 로그파일에 쌓인 로그를 모두 지운 후에 Apache를 재실행한다.








    7. 로그분석 실행 밑 웹페이지에서 확인





      여기까지 마친 후, awstats 로그분석기를 실행하려면 다음과 같이 한다( -config 옵션의 값은 [자신이 정한 이름]을 적으면 된다).





        # /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=nfo.pe.kr





      웹브라우저에서 다음 주소로 확인할 수 있다.





        http://도메인주소/awstats/awstats.pl?config=[자신이 정한 이름]





      필자의 경우, 도메인 주소는 nfo.pe.kr 이고 [자신이 정한 이름]은 nfo.pe.kr 이므로, 다음과 같이 브라우저에서 찾아가면 웹로그분석 사이트가 보일 것이다.





        http://nfo.pe.kr/awstats/awstats.pl?config=nfo.pe.kr








    8. Cron 등록





      awstats 로그분석기를 일정 간격으로 자동 실행하기 위하여 /etc/crontab 파일에 다음을 추가한다.





        30 1-24/12 * * root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=nfo.pe.kr





      하루 두 번씩 cron 데몬이 정기적으로 업데이트를 하고 있다. 업데이트 주기는, 사이트의 방문자가 많을 수록 짧게 하면 된다.



    posted by 좋은느낌/원철