Apache에서 트래픽 제한 모듈 mod_cband를 설정하려면 어떻게 하나요?
💡 요약 정리
- mod_cband는 Apache 웹 서버의 트래픽(전송량, 속도)을 제어하기 위한 모듈입니다.
- 설치는 소스 다운로드 후 컴파일 및 httpd.conf 파일 수정 방식으로 진행됩니다.
- 가상호스트별로 세부 제한 설정이 가능하며, 사용량은 별도 페이지에서 확인할 수 있습니다.
- 설정 도중 환 경에 맞게 apxs 경로나 IP주소 등을 정확히 입력해야 합니다.
1. 소스 파일 다운로드
sourceforge.net 이나 Apache 관련 사이트를 통해 mod-cband 소스 파일을 다운로드합니다.
2. 압축 해제 및 설치
[root@localhost src]# ls
mod-cband-0.9.7.5.gz
[root@localhost src]# tar xvzfp mod-cband-0.9.7.5.gz
mod-cband-0.9.7.5/
mod-cband-0.9.7.5/Changes
mod-cband-0.9.7.5/doc/
mod-cband-0.9.7.5/doc/faq.txt
mod-cband-0.9.7.5/doc/documentation.txt
mod-cband-0.9.7.5/configure
mod-cband-0.9.7.5/LICENSE
mod-cband-0.9.7.5/libpatricia.copyright
mod-cband-0.9.7.5/Makefile.in
mod-cband-0.9.7.5/INSTALL
mod-cband-0.9.7.5/conf/
mod-cband-0.9.7.5/conf/vhosts3.conf.example
mod-cband-0.9.7.5/conf/vhosts.conf.example
mod-cband-0.9.7.5/conf/vhosts2.conf.example
mod-cband-0.9.7.5/AUTHORS
mod-cband-0.9.7.5/src/
mod-cband-0.9.7.5/src/mod_cband.c
mod-cband-0.9.7.5/src/libpatricia.c
mod-cband-0.9.7.5/src/mod_cband.h
[root@localhost src]# cd mod-cband-0.9.7.5
[root@localhost mod-cband-0.9.7.5]# ls
AUTHORS Changes conf configure doc INSTALL libpatricia.copyright LICENSE Makefile.in src
[root@localhost mod-cband-0.9.7.5]# ./configure --with-apxs=/home/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 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
/home/apache/bin/apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -c src/mod_cband.c
/home/apache/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/home/apache/include -I/home/apache/include -I/home/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
/home/apache/build/libtool --silent --mode=link gcc -o src/mod_cband.la -rpath /home/apache/modules -module -avoid-version src/mod_cband.lo
설치 명령을 입력합니다.
[root@localhost mod-cband-0.9.7.5]# make install
/home/apache/bin/apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -i -a -n cband src/mod_cband.la
/home/apache/build/instdso.sh SH_LIBTOOL='/home/apache/build/libtool' src/mod_cband.la /home/apache/modules
/home/apache/build/libtool --mode=install cp src/mod_cband.la /home/apache/modules/
libtool: install: cp src/.libs/mod_cband.so /home/apache/modules/mod_cband.so
libtool: install: cp src/.libs/mod_cband.lai /home/apache/modules/mod_cband.la
libtool: install: cp src/.libs/mod_cband.a /home/apache/modules/mod_cband.a
libtool: install: chmod 644 /home/apache/modules/mod_cband.a
libtool: install: ranlib /home/apache/modules/mod_cband.a
libtool: finish: PATH="/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/home/mysql/bin:/home/apache/bin:/sbin" ldconfig -n /home/apache/modules
----------------------------------------------------------------------
Libraries have been installed in:
/home/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 /home/apache/modules/mod_cband.so
[activating module `cband' in /home/apache/conf/httpd.conf]
[root@localhost mod-cband-0.9.7.5]# cd /home/apache/modules/
[root@localhost modules]# ls
[... 다양한 모듈 목록 중 ...]
mod_cband.so
[root@localhost modules]# ls -al mod_cband.so
-rwxr-xr-x 1 root root 199271 Jan 3 10:26 mod_cband.so
httpd.conf 파일에 모듈이 등록되었는지 확인합니다.
[root@localhost modules]# cat /home/apache/conf/httpd.conf | grep mod_cband
LoadModule cband_module modules/mod_cband.so
3. httpd.conf 파일에 Location 설정 추가
<Location /cband-status>
SetHandler cband-status
Order deny,allow
Deny from all
Allow from 허용 아이피(예: 192.168.100.10)
</Location>
<Location /cband-status-me>
SetHandler cband-status-me
</Location>
4. 가상호스트 설정에 트래픽(전송량) 제한 추가
<VirtualHost *>
ServerName mydomain.co.kr
Document /home/mydomain/public_html
CBandLimit 100Mi <-- 트래픽 100M로 제한
CBandPeriod 1D <-- 트래픽 측정 주기(해당 주기가 지나면 reset됨)
CBandExceededURL http://mydomain.co.kr/traffic-over.html <-- 트래픽 초과시 보여줄 페이지 설정
</VirtualHost>
traffic-over.html 파일은 안내 메시지 작성 후 위 경로에 업로드해야 합니다.
추가 설정 예시는 아래와 같습니다.
<VirtualHost *>
ServerName ftp.mydomain.co.kr
Document /home/mydomain/ftp
CBandSpeed 1024 10 30 <-- 전송속도(대역폭)을 1024kb/s, 초당 10개의 요청처리, 동시접속 30으로 제한
CBandRemoteSpeed 20kb/s 3 10 <-- 접속자당 20kb/s, 초당 5개의 요청처리, 동시접속 10으로 제한
</VirtualHost>
5. 사용량 확인
- 사용량 확인 페이지는 Location 항목에서 허용한 IP 주소만 접속이 가능하며,
- 가능하다면 Apache 인증 기능을 활용하여 인증을 거친 후 접근되도록 설정합니다.
http://도메인/cband-status
http://도메인/cband-status-me
6. 주요 옵션
-
CBandLimit
- 제한할 전송량을 설정합니다.
- 사용 단위: K (kilo), M (mega), G (giga), Ki (kibi), Mi (mebi), Gi (gibi)
- 예시:
CBandLimit 10M→ 전송양 10M (1010001000 bytes)CBandLimit 10Mi→ 전송양 10Mi (1010241024 bytes)
-
CBandPeriod
- 용량제한 기간을 설정하며, 해당 기간 경과 후 다시 리셋됩니다.
- 사용 단위: S (초), M (분), H (시간), D (일), W (주)
- 예시:
CBandPeriod 1W(1주일)CBandPeriod 14D(14일)CBandPeriod 60M(60분)
-
CBandSpeed
- 가상호스트 전체의 속도, 요청 수, 접속 수를 제한합니다.
- 형식:
CBandSpeed kbps rps max_conn- kbps : 초당 최대 전송속도
- rps : 초당 최대 요청 수
- max_conn : 최대 동시 접속 수
- 예시:
CBandSpeed 1024 20 20
-
CBandRemoteSpeed
- 접속자(IP) 개별 기준의 속도, 요청 수, 접속 수 제한
- 형식:
CBandRemoteSpeed kbps rps max_conn - 예시:
CBandRemoteSpeed 30kb/s 5 2