[펌]Apache 트래픽 제한

출처: http://oskorean.com/bbs/board.php?bo_table=B01&wr_id=5

다운로드 : mod-cband-0.9.7.5.tgz

설치 시작 (소스파일 다운로드 후 소스파일 디렉토리로 이동합니다.)


[root@localhost mod-cband-0.9.7.5]# ./configure –with-apxs=/usr/local/apache/bin/apxs (아파치경로는 알맞게설정)
checking for gcc… gcc
checking for C compiler default output file name… a.out
checking whether the C compiler works… yes
checking whether we are cross compiling… no
checking for suffix of executables…
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ANSI C… none needed
checking whether make sets $(MAKE)… yes
checking for apr_palloc in -laprutil… no
checking for an ANSI C-conforming const… yes
checking apxs –with-apxs=/usr/local/apache/bin/apxs… found
checking how to run the C preprocessor… gcc -E
checking for egrep… grep -E
checking for ANSI C header files… yes
checking for sys/types.h… yes
checking for sys/stat.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for stdint.h… yes
checking for unistd.h… yes
checking stdio.h usability… yes
checking stdio.h presence… yes
checking for stdio.h… yes
checking for string.h… (cached) yes
checking assert.h usability… yes
checking assert.h presence… yes
checking for assert.h… yes
checking ctype.h usability… yes
checking ctype.h presence… yes
checking for ctype.h… yes
checking errno.h usability… yes
checking errno.h presence… yes
checking for errno.h… yes
checking math.h usability… yes
checking math.h presence… yes
checking for math.h… yes
checking netinet/in.h usability… yes
checking netinet/in.h presence… yes
checking for netinet/in.h… yes
checking sys/socket.h usability… yes
checking sys/socket.h presence… yes
checking for sys/socket.h… yes
checking arpa/inet.h usability… yes
checking arpa/inet.h presence… yes
checking for arpa/inet.h… yes
configure: creating ./config.status
config.status: creating Makefile




[root@localhost mod-cband-0.9.7.5]# make


/usr/local/apache/bin/apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -c src/mod_cband.c
/usr/local/apache/build/libtool –silent –mode=compile gcc -prefer-pic -I/usr/kerberos/include -L/usr/kerberos/lib  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -pthread -I/usr/local/apache/include  -I/usr/local/apache/include  -I/usr/local/apache/include  -Wall -DDST_CLASS=3  -c -o src/mod_cband.lo src/mod_cband.c && touch src/mod_cband.slo
src/mod_cband.c:81: warning: type qualifiers ignored on function return type
/usr/local/apache/build/libtool –silent –mode=link gcc -o src/mod_cband.la  -rpath /usr/local/apache/modules -module -avoid-version    src/mod_cband.lo


write “make install” to install module




[root@localhost mod-cband-0.9.7.5]# make install
/usr/local/apache/bin/apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -i -a -n cband src/mod_cband.la
/usr/local/apache/build/instdso.sh SH_LIBTOOL=’/usr/local/apache/build/libtool’ src/mod_cband.la /usr/local/apache/modules
/usr/local/apache/build/libtool –mode=install cp src/mod_cband.la /usr/local/apache/modules/
cp src/.libs/mod_cband.so /usr/local/apache/modules/mod_cband.so
cp src/.libs/mod_cband.lai /usr/local/apache/modules/mod_cband.la
cp src/.libs/mod_cband.a /usr/local/apache/modules/mod_cband.a
chmod 644 /usr/local/apache/modules/mod_cband.a
ranlib /usr/local/apache/modules/mod_cband.a
PATH=”$PATH:/sbin” ldconfig -n /usr/local/apache/modules
———————————————————————-
Libraries have been installed in:
  /usr/local/apache/modules


If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR’
flag during linking and do at least one of the following:
  – add LIBDIR to the `LD_LIBRARY_PATH’ environment variable
    during execution
  – add LIBDIR to the `LD_RUN_PATH’ environment variable
    during linking
  – use the `-Wl,–rpath -Wl,LIBDIR’ linker flag
  – have your system administrator add LIBDIR to `/etc/ld.so.conf’


See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
———————————————————————-
chmod 755 /usr/local/apache/modules/mod_cband.so
[activating module `cband’ in /usr/local/apache/conf/httpd.conf]



vi /usr/local/apache/conf/httpd.conf 파일안에 cband 추가된 모듈확인
LoadModule cband_module      modules/mod_cband.so



vi /usr/local/apache/conf/httpd.conf 파일 수정
….
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml
</IfModule>


# 아래사항 추가
<IfModule mod_cband.c>
        <Location /cband-status>
                SetHandler cband-status
        </Location>
        <Location /cband-status-me>
                SetHandler cband-status-me
        </Location>
        <Location /~*/cband-status-me>
                SetHandler cband-status-me
        </Location>
        <Location /cband-status>
                SetHandler cband-status
                Order deny,allow
                Deny from all
                Allow from all
        </Location>
</IfModule>
# 여기까지



#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type.  The MIMEMagicFile
# directive tells the module where the hint definitions are located.
….



트래픽 자동리셋 설정
설치 및 설정이 완료된 후
http://도메인/cband-status 로 접속하면 virtual host name 옆부분에 reset all 버튼이 있습니다.
마우스 우클릭 > 속성 > 주소(URL) 복사 후 아래내용에 써주시면 됩니다.
파일 생성 후 crontab 등록
wget “http://oskorean.com/cband-status?reset=all&refresh=15&unit=” > /dev/null 2>&1
rm -rf /usr/local/src/kimhaksun/cband-status?refresh=15&unit=


[root@localhost kimhaksun]# crontab -l
00 00 * * *    /bin/sh /usr/local/src/kimhaksun/cband_reset.sh > /dev/null 2>&1




virtualhost 설정
….
    CbandLimit 500Mi
    CBandPeriod 1D
    CBandExceededURL http://oskorean.com/traffic_over.html
버츄얼 호스트밑에 위 사항을 추가해줍니다. (필요기능 추가가능합니다.)
oskorean.com 의 홈폴더 밑에 traffic_over.html 파일을 생성하여 트래픽 초과시 나타낼 페이지를 생성해줍니다.



지시자 및 단위 설명 (필요시 찾아보세요!!)
  1) 단위.
    * 전송속도 단위
          o kbps, Mbps, Gbps – bits per second: 1024, 1024*1024 , 1024*1024*1024 bps
          o kb/s, Mb/s, Gb/s – bytes per second:  1024, 1024*1024, 1024*1024*1024 b/s
          o 기본 : kbps


    * 트래픽 쿼터 단위
          o K, M, G – bytes: 1000, 1000*1000 ,1000*1000*1000 bytes
          o Ki, Mi, Gi – bytes: 1024, 1024*1024, 1024*1024*1024 bytes
          o 기본 : K


    * 시간(기간) 단위
          o S, M, H, D, W – 초, 분, 시간, 일, 주
          o 기본 : S


  2) 지시자들
    (1) 이름 : CBandDefaultExceededURL
          설명 : 제한을 초과했을때 보여줄 URL  (지정하지 않으면, 503 에러 페이지)
            문맥 : Server config
          문법 : CBandDefaultExceededURL URL


    (2)이름 : CBandDefaultExceededCode
        설명 : 제한을 초과했을시 보여줄 에러 코드
        문맥 : Server config
        문법 : CBandDefaultExceededCode HTTP_CODE
        예제 : CBandDefaultExceededCode 509 



    (3)이름 : CBandScoreFlushPeriod
        설명 : scoreboard 파일에 기록할 요청수, mod_cband 의 성능에 영향을 준다.
        기본값 : 1
        문맥 : Server config
        문법 : CBandScoreFlushPeriod 요청수
        예제 : CBandScoreFlushPeriod 100  ( 매 100번의 요청에 한번씩 scoreboard 파일에 기록)


    (4)이름 : CBandSpeed
        설명 : 가상호스트 도메인의 최대 속도, 요청수, 접속수  설정
        문맥 : <Virtualhost>
        문법 : CBandSpeed kbps rps max_conn
                kbps – 초당 최대 전송속도
                rps – 초당 최대 요청수
                max_conn – 최대 동시 접속수
        예제 : CBandSpeed 1024 10 30
                최대 1024kbps전송속도로 제한, 초당 10개의 요청 처리, 동시 접속을 30개로 제한.


    (5)이름 : CBandRemoteSpeed
        설명 : 접속자(IP)의 최대속도, 요청수, 접속수 제한 (CBandSpeed와 비슷하지만, 접속자당 설정)
        문맥 : <Virtualhost>
        문법 : CBandRemoteSpeed kbps rps max_conn
                  kbps – 초당 최대 전송속도
                  rps – 초당최대 요청수
                  max_conn – 최대 동시 접속수
        예제 : CBandRemoteSpeed 20kb/s 3 3
                  접속자(ip)에대해 최대 20kb/s , 초당 3개의 요청, 동시 접속 3개로 제한.


    (6)이름 : CBandClassRemoteSpeed
        설명 : 정의한 class(ip 범위)에 대해 최대속도, 요청수, 접속수 제한
        문맥 : <Virtualhost>
        문법 : CBandClassRemoteSpeed class_name kbps rps
                  class_name – 이미 정의한 클래스 이름 (IP범위)
                  kbps – 초당 최대 전송속도
                  rps – 초당 최대 요청수
                  max_conn – 최대 동시 접속수
        예제 : <CBandClass googlebot_class>
                    CBandClassDst 66.249.64/24
                    CBandClassDst 66.249.65/24
                    CBandClassDst 66.249.79/24
                  </CBandClass>
                        CBandClassRemoteSpeed googlebot_class 20kb/s 2 3
                        위에서 정의한 클래스(googlebot_class)의 요청에는 20kb/s 의 전송속도,
                      초당 3개의 요청, 동시 접속 3개로 제한.


    (7)이름 : CBandRandomPulse
        설명 : 속도 제한을 위해서 임의의 파형을 생성한 다음 처리하는 mod_cband의 처리 방법이다.
                  부하가 많을때는 자동 Off된다.
        문맥 : Global
        문법 : CBandRandomPulse On/Off


    (8)이름 : CBandLimit
        설명 : 제한할 전송량을 설정한다. (기간은 CBandPeriod 에서 설정)
        문맥 : <Virtualhost>
        문법 : CBandLimit limit
                  limit – 전송량, 사용단위: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)
        예제 : CBandLimit 10M
                    전송양을 10M(10*1000*1000bytes)로 제한한다.
                  CBandLimit 10Mi
                    전송양을 10M(10*1024*1024bytes)로 제한한다.


    (9)이름 : CBandClassLimit
        설명 : 정의한 class(ip범위)에 대해 제한할 전송량 설정.
        문맥 : <Virtualhost>
        문법 : CBandClassLimit class_name limit
                  class_name – 이미 정의한 클래스 이름(ip범위)
                  limit – 전송량, 사용단위: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)


  (10)이름 : CBandExceededURL
        설명 : 제한을 초과했을시 보여줄 URL, 지정하지 않으면 503 에러 발생 ( 가상호스트에서 )
        문맥 : <Virtualhost>
        문법 : CBandExceededURL URL


  (11)이름 : CBandExceededSpeed
        설명 : 전송양을 초과했을시 , 전송속도 제한 설정.
        문맥 : <Virtualhost>
        문법 : CBandExceededSpeed kbps rps max_conn
                  kbps – 초당 최대 전송속도
                  rps – 초당 최대 요청수
                  max_conn – 최대 동시 접속수


    (12)이름 : CBandScoreboard
        설명 : 가상호스트의 scoreboard 파일 지정. (성능향상을 위해 필요)
        문맥 : <Virtualhost>
        문법 : CBandScoreboard path
                  (path는 아파치(nobody또는 apache)권한으로 쓰기가능해야 함)


    (13)이름 : CBandPeriod
        설명 : 용량제한기간(이 기간이 지나면, 측정되었던 용량은 지워진다.)
        문맥 : <Virtualhost>
        문법 : CBandPeriod period
                  period – 사용단위: S (초), M (분), H (시간), D (일), W (주)
        예제 : CBandPeriod 1W  (1주일)
                  CBandPeriod 14D  (14일)
                  CBandPeriod 60M  (60분)


  (14)이름 : CBandPeriodSlice
        설명 : 기간이 길때는 나눌 기간을 명시한다.
        기본값 : slice_len = limit
        문맥 : <Virtualhost>
        문법 : CBandPeriodSlice slice_length
        예제 : CBandLimit 100G
                  CBandPeriod 4W
                  CBandPeriodSlice 1W
                  4주는 1주일 단위로 나뉜다(4W/1W = 4). 용량은 100G/4=25G
                  1주에 25G, 2주째 50G 이렇게 나눠 처리 된다.


  (15)이름 : <CBandUser>
        설명 : 새로운 cband 가상 사용자 설정
        문맥 : Server config
        문법 : <CBandUser user_name>


  (16)이름 : CBandUserSpeed
        설명 : cband 가상 사용자의 속도, 요청수, 동시 접속수 제한
        문맥 : <CBandUser>
        문법 : CBandUserSpeed kbps rps max_conn
                  kbps – 초당 최대 전송속도
                  rps – 초당 최대 요청수
                  max_conn – 최대 동시 접속수
        예제 : CBandUserSpeed 100kb/s 10 5



  (17)이름 : CBandUserLimit
        설명 : cband 가상 사용자의 저송 용량 제한.
        문맥 : <CBandUser>
        문법 : CBandUserLimit limit
                  limit – 사용용량, 사용단위: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)
        예제 : CBandUserLimit 10M
                  CBandUserLimit 10Mi


  (18)이름 : CBandUserClassLimit
        설명 : cband 가상 사용자의 정의한 class(ip범위)에 대해 제한할 전송량 설정
        문맥 : <CBandUser>
        문법 : CBandUserClassLimit class_name limit
                  class_name – 지정한 class(IP범위)이름
                  limit -사용용량, 사용단위: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)


  (19)이름 : CBandUserExceededURL
        설명 : cband 가상 사용자의, 제한을 초과했을시 보여줄 URL,
                  지정하지 않으면 503 에러 발생 ( 가상호스트에서 )
        문맥 : <CBandUser>
        문법 : CBandUserExceededURL URL


  (20)이름 : CBandUserExceededSpeed
        설명 : cband 가상 사용자의, 전송양을 초과했을시 , 전송속도 제한 설정.
        문맥 : <CBandUser>
        문법 : CBandUserExceededSpeed kbps rps max_conn
                  kbps – 초당 최대 전송속도
                  rps – 초당 최대 요청수
                  max_conn – 최대 동시 접속수


  (21)이름 : CBandUserScoreboard
        설명 : cband 가상 사용자의, scoreboard 파일 지정.
        문맥 : <CBandUser>
        문법 : CBandUserScoreboard path
                  (path는 아파치(nobody또는 apache)권한으로 쓰기가능해야 함)


  (22) 이름 : CBandUserPeriod
        설명 : cband 가상 사용자의, 용량제한기간(이 기간이 지나면, 측정되었던 용량은 지워진다.)
        문맥 : <CBandUser>
        문법 : CBandUserPeriod period
                  period – 사용단위: S (초), M (분), H (시간), D (일), W (주)
        예제 : CBandUserPeriod 1W
                  CBandUserPeriod 14D
                  CBandUserPeriod 60M


  (23)이름 : CBandUserPeriodSlice
        설명 : cband 가상 사용자의, 기간을 나눌 기간 명시
        기본값 : slice_len = limit
        문맥 : <CBandUser>
        문법 : CBandUserPeriodSlice slice_length
        예제 : CBandUserLimit 100G
                  CBandUserPeriod 4W
                  CBandUserPeriodSlice 1W
                  4주는 1주일 단위로 나뉜다(4W/1W = 4). 용량은 100G/4=25G
                  1주에 25G, 2주째 50G 이렇게 나눠 처리 된다.




CBand 웹페이지 확인
전체 : http://도메인/cband-status
개별 : http://도메인/cband-status-me

4716432672.tgz

댓글 남기기