Computer/Network

[Linux] throttle 설치 및 설정

알찬돌삐 2005. 5. 24. 08:32
아파치 웹서버의 모듈 중, throttle 모듈은 트래픽 사용량을 제한하는 역할을 한다.

순간트래픽의 제한보다는 보통 1일트래픽 제한을 하는데 사용된다.

cafe24의 500원짜리 웹호스팅을 '일일 트래픽은 400메가입니다' 라고 말하는데...

그때 사용되는 모듈이다.



웹호스팅 계정의 트래픽을 제한하는 것은 매우 중요하다.

필자의 경험으로는, 해킹을 당했거나, 옥션에 이미지파일을 링크시키는 사이트가 트래픽이 많이 나왔다.



옥션에 장사하는 분들이, 이미지파일을 링크하는 것을 우습게 보면 안된다.

보통 20~30메가 정도 순간트래픽이 꾸준이 발생한다.

IDC에선, 100M 회선이 월 200만원 정도 하니... 한달에 500원짜리 웹호스팅에서 트래픽이 발생하면 문제가 많다.. ㅡㅡ;



물론, 이미지파일이나 스트리밍 파일의 외부링크를 막는 방법도 간단하지만.....

아파치에서는 throttle 모듈이라는 좋은 플러그인을 제공한다.



설치는 이미 되어 있을 것이다. 살펴보자.


[CODE] # rpm -qa | grep throttle apache-throttle-3.1.2-1 # rpm -qi apache-throttle Name : apache-throttle Relocations: (not relocateable) Version : 3.1.2 Vendor: AnNyung Packaging Team Release : 1 Epoch: 1 Group : System Environment/Daemons Source RPM: apache-throttle-3.1.2-1.src.rpm Size : 44260 License: Freely distributable and usable Build Host : work.oops.org Build Date : 2004년 11월 22일 (월) 오후 10시 29분 40초 Install date: 2005년 03월 04일 (금) 오후 05시 59분 52초 Packager : JoungKyun Kim <http://www.oops.org> Summary : 아파치의 대역폭 또는 서버 로드를 조절하는 모듈 Description : 가상호스트, 디렉토리 위치 또는 유저가 설정한 규칙에 의하여 서버 로드와 대역 폭 사용량을 제한한다. 또한, 클라이언트 IP 와 원격 유저 이름으로 쓰로틀링이 가능하다. # [/CODE]


설정 과정은 2단계이다.

첫 번째, 아파치 환경설정파일인 httpd.conf 파일에서 throttle 모듈을 사용하도록 설정하고..

두 번째, 버추얼호스트 설정항목에서 throttle 모듈을 지정하여 주면 된다.



우선 첫 번째, /etc/httpd/conf/httpd.conf 파일에서 throttle 모듈에 관한 내용을 살펴보니,

1069 라인에 /etc/httpd/conf/module.d/*.conf 파일로 별도 지정한 것을 볼 수 있다.



1069라인 : Include /etc/httpd/conf/module.d/*.conf



이중에서 throttle 모듈에 대한 설정은 /etc/httpd/conf/module.d/throttle.conf 파일이다.

우선, 8라인의 주석 표시를 지워준다.



8라인 : LoadModule throttle_module modules/mod_throttle.so



나머지 부분도 별로 수정할 사항이 없다. 필자는 다음과 같이 수정하였다.



[CODE] <IfModule mod_throttle.c> ThrottlePolicy none <Location /throttle-status> SetHandler throttle-status Order deny,allow # Deny from all Allow from all </Location> <Location /throttle-me> SetHandler throttle-me </Location> <Location /~*/throttle-me> SetHandler throttle-me </Location> </IfModule>[/CODE]


20라인을 주석처리하였고, 21라인의 localhost 대신에 all 을 넣었다.

만약, 사용자는 제외하고, 관리자만 트래픽 현황을 보고싶다면 다음과 같이 한다.



Deny from all

Allow from 127.0.0.1 192.168.7.0/255.255.255.0



이제, /etc/httpd/conf/conf.d/virtual.conf 파일에 throttle 모듈 관련 내용을 설정하면 된다.

앞의 '[안녕] APM - 버추얼호스트로 공동서버 운영' 강좌에서 /etc/httpd/conf/conf.d/virtual.conf 파일에 다음과 같이 설정을 하였다.



[CODE]<VirtualHost 192.168.7.3> ServerAdmin webmaster@naver.com DocumentRoot /home/naver/html ServerName naver.com ServerAlias www.naver.com ErrorLog /var/log/httpd/naver-error_log CustomLog /var/log/httpd/naver-access_log common env=!img-nosave,!CodeRedNimda </VirtualHost>[/CODE]


다음과 같이 추가하여 보자.



[CODE] <VirtualHost 192.168.7.3> ServerAdmin webmaster@naver.com DocumentRoot /home/naver/html ServerName naver.com ServerAlias www.naver.com ThrottlePolicy Volume 400M 1d ErrorLog /var/log/httpd/naver-error_log CustomLog /var/log/httpd/naver-access_log common env=!img-nosave,!CodeRedNimda </VirtualHost>[/CODE]



하루(1d) 트래픽을 400메가(400M) 로 제한한다는 의미이다.



이제 아파치 웹서버를 재시작하자.



# /etc/rc.d/init.d/httpd restart
Shutting down http: [ 확인 ]
Starting httpd: [ 확인 ]
#



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



서버관리자 : http://도메인이름/throttle-status

계정사용자 : http://도메인이름/throttle-me



cafe24 웹호스팅에서와 같은 화면을 볼 수 있을 것이다.

물론, 제한한 하루 트래픽을 초과한다면, 사이트의 접속이 안된다.

또한 1d를 1초 단위(1s)나, 1시간 단위(1h) 등으로 변경할 수도 있다.

1초 단위로 변경한다면, throttle 모듈로, 순간트래픽을 재한하는 traffic 모듈과 같은 역할을 한다.

출처 : http://www.linuxc.net.

'Computer > Network' 카테고리의 다른 글

[Linux] 계정별로 트래픽 제한하기  (0) 2005.05.24
[Linux] throttle-status 및 암호설정  (0) 2005.05.24
[Linux] Route 명령어로 IP 차단  (0) 2005.05.24
암호화  (0) 2005.05.15
Ip address와 subnetting  (0) 2005.05.15