제목 : Apache Redirectmatch 사용 예
작성자 : 이선규 (neosky)  (neosky(at)smileserv.com, admin(at)nple.com,
http://seroot.com)
작성일 : 2010년 6월 22일




주소창에서 http://nple.kr/2010 와 같이 입력했을 경우

그 다음에 나온 룰에 따라 http://nple.kr/main/bbs/board.php?bo_table=2010 으로 매치하게 된다.





    RedirectMatch ^/([a-zA-Z0-9_-]+)$  http://nple.kr/main/bbs/board.php?bo_table=$1

2010/06/22 17:51 2010/06/22 17:51








마음튼튼 이 작성.

당신의 의견을 작성해 주세요.

[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다


1) 일일 Access log size 500M 이하 ( 기본설정 )
MaxKeepAliveRequests 1024
< IfModule mpm_worker_module >
   StartServers      8
   ServerLimit       16
   MaxClients      1024
   MinSpareThreads    64
   MaxSpareThreads   512
   ThreadsPerChild    64
   MaxRequestsPerChild  0
< /IfModule >


2) 일일 Access log size 500M ~ 1G
MaxKeepAliveRequests 2048
< IfModule mpm_worker_module >
   StartServers     16
   ServerLimit      32
   MaxClients      2048
   MinSpareThreads   256
   MaxSpareThreads   1024
   ThreadsPerChild    64
   MaxRequestsPerChild  0
< /IfModule >


3) 일일 Access log size 1G ~ 2G
MaxKeepAliveRequests 4096
< IfModule mpm_worker_module >
   StartServers     8
   ServerLimit      32
   MaxClients      4096
   MinSpareThreads   1024
   MaxSpareThreads   2048
   ThreadsPerChild    128
   MaxRequestsPerChild  0
< /IfModule >
2010/06/10 18:20 2010/06/10 18:20








마음튼튼 이 작성.

당신의 의견을 작성해 주세요.

[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다


Apache 에서 최대 접속자 수 늘리기
작성자 : neosky (seroot.com, nple.com)
작성일 : 2010. 05. 11


1) Apache 1.3

Apache 1.3 에서는 기본적으로 Max Clients 값은 256까지만 설정할 수 있다.
이 Parameter 값을 증가시키려면 Apache 의 source 를 수정하여 다시 컴파일 해야 가능하다.

Apache source 디렉토리로 이동해서 src/include/httpd.h 파일을 열고
HARD_SERVER_LIMIT 256 으로 설정되어 있는 값을 512 또는 1024 로 변경하여 저장 후 컴파일 해준다.


2) Apache 2.2

Apache 2.2 는 Apache 1.3 과 매우 다른데, httpd.h 파일에는 Max Client 와 관련한 옵션이 없다.
따라서, Apache 2.2 에서는 2개의 파일에서 설정을 바꾸어 주어야 한다.

Apache source 디렉토리로 이동해서 server/mpm/prefork/prefork.c 파일을 열고
#define DEFAULT_SERVER_LIMIT 256 으로 설정되어 있는 값을 2048 으로 변경하여 저장한다.

여기서, 2048 / 256 을 계산하면 8 이라는 배수가 나온다. 

다시 Apache source 디렉토리로 이동해서 server/mpm/work/worker.c 파일을 열고
#define DEFAULT_SERVER_LIMIT 16 으로 설정되어 있는 값을 16 으로 변경하여 저장한다.

./configure -prefix=/usr/local/apache --enable-rewrite 명령으로 재컴파일

vi /usr/local/apache/conf/extra/httpd-mpm.conf 파일을 열고

<IfModule worker.c> 지시자내 설정 중
MaxClients 2048 저장하고 Apache 를 재시작해준다.

work 는 스레드 방식으로 아파치가 작동하도록 하기 위한 설정
prefork 는 전통적인 아파치 실행방식은 prefork 방식의 설정


 

2010/05/11 15:42 2010/05/11 15:42








마음튼튼 이 작성.

당신의 의견을 작성해 주세요.

[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다


웹 로그 분석기 awstats 설치 + GeoIP, GeoCity Plugin 설치
작성자 : neosky (seroot.com, nple.com)
작성일자 : 2010. 05. 04.



※ 퍼가실때는 반드시 댓글과 출처를 남겨주세요. ^^


오늘은 아파치 웹 로그를 분석해서 다양한 정보를 그래프로 보여주는
awstats 설치에 대해 알아보겠습니다. 

(과거에는 webalizer 로그 분석기를 많이 선호하였으나, 깔끔한 인터페이스와 다양한 정보 분석을
해준다는 점에서 awstats 를 쓰는 추세입니다. ^^)


공식 홈페이지 : http://awstats.sourceforge.net/

사용자 삽입 이미지


라이센스 : GNU GPL
배포버전 : 7.0 beta (2010-05-02), 6.95 (2009-10-25)
               2000-05-02 1.0 버전을 시작으로 현재 6.95 버전이 최신 버전입니다.
               여기서는 6.95 버전을 기준으로 설명합니다.

다운로드 URL : http://awstats.sourceforge.net/#DOWNLOAD
파일 URL : http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz




1. 파일 다운로드, 압축 해제, 디렉토리 이동

# wget http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz

--2010-05-04 09:28:44--  http://prdownloads.sourceforge.net/awstats/awstats-6.95.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://cdnetworks-kr-2.dl.sourceforge.net/project/awstats/AWStats/6.95/awstats-6.95.tar.gz [following]
--2010-05-04 09:28:45-- 
http://cdnetworks-kr-2.dl.sourceforge.net/project/awstats/AWStats/6.95/awstats-6.95.tar.gz
Resolving cdnetworks-kr-2.dl.sourceforge.net... 211.39.135.163
Connecting to cdnetworks-kr-2.dl.sourceforge.net|211.39.135.163|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1138306 (1.1M) [application/x-gzip]
Saving to: `awstats-6.95.tar.gz'
100%[=====================================================================================================================================================================>] 1,138,306   --.-K/s   in 0.03s
2010-05-04 09:28:45 (33.6 MB/s) - `awstats-6.95.tar.gz' saved [1138306/1138306]

# tar xvfz awstats-6.95.tar.gz

awstats-6.95/
awstats-6.95/README.TXT
awstats-6.95/docs/
awstats-6.95/docs/COPYING.TXT
awstats-6.95/docs/LICENSE.TXT
awstats-6.95/docs/awstats.pdf
awstats-6.95/docs/awstats_benchmark.html
awstats-6.95/docs/awstats_changelog.txt
awstats-6.95/docs/awstats_compare.html
awstats-6.95/docs/awstats_config.html
awstats-6.95/docs/awstats_contrib.html
awstats-6.95/docs/awstats_extra.html
awstats-6.95/docs/awstats_faq.html
... 이하 생략

# mv awstats-6.95 /usr/local/awstats
`awstats-6.95' -> `/usr/local/awstats'


2. 사용자 권한 부여, 작업 디렉토리 생성

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

changed ownership of `/usr/local/awstats/README.TXT' to root:root
changed ownership of `/usr/local/awstats/tools/awstats_exportlib.pl' to root:root
changed ownership of `/usr/local/awstats/tools/awstats_updateall.pl' to root:root
changed ownership of `/usr/local/awstats/tools/maillogconvert.pl' to root:root
changed ownership of `/usr/local/awstats/tools/awstats_buildstaticpages.pl' to root:root
changed ownership of `/usr/local/awstats/tools/urlaliasbuilder.pl' to root:root
changed ownership of `/usr/local/awstats/tools/httpd_conf' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.datademo2.xml' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.datademo1.xslt' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.datademo2.xslt' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.xsd' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/awstats.datademo1.xml' to root:root
changed ownership of `/usr/local/awstats/tools/xslt/README.txt' to root:root
... 이하 생략

# chmod 755 /usr/local/awstats
`/usr/local/awstats'의 모드를 0755(rwxr-xr-x)으로 유지하였습니다

# mkdir /etc/awstats
# mkdir /var/lib/awstats



3. awstats 설치

# cd /usr/local/awstats/tools
# perl ./awstats_configure.pl


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

-----> 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: 
> nple.com <--- 자신의 도메인 명을 넣는다.


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

엔터
엔터



4. awstats 도메인 환경설정 파일 생성, 아파치 로그 형식 설정

# cd /etc/awstats
# vi ./awstats.nple.com.conf   <== 파일 이름 형식은 항상 awstats.도메인명.conf 입니다.

*** 51번째 줄에서 사이트에 맞는 로그 파일경로로 수정합니다.
LogFile="/var/log/httpd/mylog.log" ==> LogFile="/usr/local/apache/logs/nple.com-access_log"

*** 905번째 줄에서 한글로 웹 로그 분석을 보기 위해 Lang 값을 수정합니다.
Lang="auto" ==> Lang="ko"

# cat /usr/local/awstats/tools/httpd_conf 에 내용이
# vi /usr/local/apache/conf/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>

# vi /usr/local/apache/conf/httpd.conf  파일이나 버추얼호스트 설정 파일을 열어 로그 형식을 바꿔줍니다.

CustomLog /usr/local/apache/logs/nple.com-access_log
==>

SetEnvIfNoCase Request_URI (gif|png|jpg|css|js|bmp|jpeg|swf)$ IMAGE=1
CustomLog /usr/local/apache/logs/nple.com-access_log combined env=!img-nosave,!CodeRedNimda


그리고, 아파치 재시작
# /etc/init.d/apachectl restart




5. 웹 로그 분석기 수동 실행, 웹에서 확인

# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=nple.com

Create/Update database for config "/etc/awstats/awstats.nple.com.conf" by AWStats version 6.95 (build 1.943)
From data in log file "/usr/local/apache/logs/nple.com-access_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)...
Jumped lines in file: 0
Parsed lines in file: 1
 Found 0 dropped records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 1 new qualified records.


http://nple.com/awstats/awstats.pl?config=nple.com


< Lang="auto" 로 했을때 영문 출력화면 >

사용자 삽입 이미지

< Lang="ko" 로 했을때 한글 출력화면 >

사용자 삽입 이미지


6. cron 으로 스케쥴링 설정

매번 서버에서 명령을 실행하는 작업은 번거로울 수 있습니다.
주기적으로 로그 분석을 실행하기 위해 cron 에서 설정해주도록 합니다.

# vi /etc/crontab

*/30 * * * * root /etc/cron.weblog/awstats.sh > /dev/null 2>&1


*** 필자는 30분 단위로 /etc/cron.weblog/awstats.sh 스크립트를 실행합니다.


awstats.sh 스크립트는 다시 아래와 같이 구성합니다.
여러 사이트를 분석해야할 경우 편리하게 추가하여 사용할 수 있습니다.

# mkdir /etc/cron.weblog
# vi /etc/cron.weblog/awstats.sh


----------------------------------------------------------------------------------------
#/bin/sh

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=nple.com
----------------------------------------------------------------------------------------

# chmod 700 /etc/cron.weblog/awstats.sh




7. 국가 Flag, City 표시 Plugin 설치

아래와 같이 유입 IP의 국가별 FLAG를 출력하기 위해서는 서버에 GeoIP 가 설치되어 있어야 합니다.

사용자 삽입 이미지
사용자 삽입 이미지


GeoIP URL : http://www.maxmind.com/


7-1. GeoIP C API 설치

다운로드 URL : http://www.maxmind.com/app/c
파일 URL : http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz


*** GCC 가 서버에 설치되어 있어야 합니다.

# wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz

# tar xvfz GeoIP-1.4.6.tar.gz
# cd GeoIP-1.4.6

# ./configure
# make
# make check
# make install



7-2. Perl 모듈 설치

awstats 아파치 분석툴에 적용하기 위해 Perl 모듈을 다운로드 받아 설치합니다.

다운로드 URL : http://www.maxmind.com/app/perl?rid=awstat

Download Geo::IP Perl Module
Download Geo::IP::PurePerl Module

# wget http://geolite.maxmind.com/download/geoip/api/perl/Geo-IP-1.38.tar.gz
# wget http://geolite.maxmind.com/download/geoip/api/pureperl/Geo-IP-PurePerl-1.25.tar.gz

# tar xvfz Geo-IP-1.38.tar.gz
# tar xvfz Geo-IP-PurePerl-1.25.tar.gz

# cd Geo-IP-1.38
# perl Makefile.PL
# make
# make test
# make install

# cd Geo-IP-PurePerl-1.25
# perl Makefile.PL
# make
# make test
# make install



7-3. 데이터베이스 다운로드 및 설치



7-4. awstats 환경설정 파일에 GeoIP, GeoIPCity 데이터베이스 파일 연결

# vi /etc/awstats/awstats.nple.com.conf

1312번째줄 주석처리된 다음 줄에 아래와 같이 적어줍니다.
LoadPlugin="geoip GEOIP_STANDARD /usr/local/lib/GeoIP.dat"

1353번째줄 주석처리된 다음 줄에 아래와 같이 적어줍니다.
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/lib/GeoIPCity.dat"



웹에서 로그 분석기를 열어보면 왼쪽에 국가 아래에 Cities 메뉴가 생긴 것을 볼 수 있고,

예와 같이 Flag, City가 표시 되는 것을 확인할 수 있습니다.





2010/05/04 11:20 2010/05/04 11:20








마음튼튼 이 작성.

당신의 의견을 작성해 주세요.

[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다



    # .gif, .jpg, .png 확장자를 가진 이미지 로그는 쌓이지 않도록 필터링하는 옵션들
    SetEnvIf Request_URI \.gif image-request
    SetEnvIf Request_URI \.jpg image-request
    SetEnvIf Request_URI \.png image-request

    CustomLog logs/access.log common env=!image-request
    ErrorLog logs/error.log


2009/07/10 21:37 2009/07/10 21:37








마음튼튼 이 작성.

당신의 의견을 작성해 주세요.

[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다


제   목 : 아파치 SSL 모드 시작시 자동으로 비밀번호 입력
구   분 : 운영팁
작성자 : 이선규 (neosky)  (neosky(at)smileserv.com, admin(at)nple.com,
http://seroot.com)
작성일 : 2008년 12월 28일




SSL 인증서 설치 후 아파치 구동할때 비밀번호를 자동으로 입력하게 하려면 다음과 같이 한다.


1. 비밀번호를 출력하는 쉘을 만든다.

# cd /usr/local/apache/bin
# vi startssl_pw.sh
#!/bin/sh
echo "password"  <-- 자동으로 입력할 패스워드


2. httpd.conf 파일중 SSL 설정 부분인 <IfModule mod_ssl.c> 아래에 내용을 추가한다.

SSLPassPhraseDialog  exec:/usr/local/apache/bin/startssl_pw.sh

2008/12/26 20:44 2008/12/26 20:44








마음튼튼 이 작성.

당신의 의견을 작성해 주세요.

[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다