查看完整版本: Apache 2 頻寬限制模組 mod_cband


toyota 2009-2-6 17:22

Apache 2 頻寬限制模組 mod_cband

如果你是用Apache Web Server自己架站,而且對外頻寬又不大的話,是否常因為對外頻寬被你架設的網站使用完,而造成你整各網路都很慢呢?<BR>  這裡我為自己的伺服器安裝上了 mod_cband MODULE,這個MODULE相當好用,可以用來解決架設 Apache 頻寬問題,它可以讓 Apache 來控制管理你的頻寬,才不會導致對外(Up Bandwith)頻寬被用完,連帶影響對內(Down Bandwith)頻寬也變慢。<BR><BR>&nbsp; &nbsp; 以下說明我的安裝過程:<BR>我的安裝環境:<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; CentOS 5.0<BR>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Apache 2.2.3<BR>
<BLOCKQUOTE>先去下載該模組: <A href="http://cband.linux.pl/download/mod-cband-0.9.7.5.tgz" target=_blank><FONT color=#0066cc>mod_cband</FONT></A> 目前釋出到 0.9.7.5 版 <A href="http://cband.linux.pl/" target=_blank><FONT color=#0066cc>http://cband.linux.pl/</FONT></A><BR><BR>下載到 /tmp/ 資料夾裡面<BR># cd /tmp<BR># wget <A href="http://cband.linux.pl/download/mod-cband-0.9.7.5.tgz" target=_blank><FONT color=#0066cc>http://cband.linux.pl/download/mod-cband-0.9.7.5.tgz</FONT></A><BR><BR>解壓縮: tar -zxvf mod-cband-0.9.7.5.tgz <BR><BR>如果你有安裝 apsx 或 apsx2 的話 請用下面安裝 (我用此方式,因我有安裝 apsx )<BR># cd mod-cband-0.9.7.5<BR># ./configure<BR><FONT color=#0000ff>checking for gcc... gcc<BR>checking for C compiler default output file name... a.out<BR>checking whether the C compiler works... yes<BR>checking whether we are cross compiling... no<BR>checking for suffix of executables... <BR>checking for suffix of object files... o<BR>checking whether we are using the GNU C compiler... yes<BR>checking whether gcc accepts -g... yes<BR>checking for gcc option to accept ANSI C... none needed<BR>checking whether make sets $(MAKE)... yes<BR>checking for apr_palloc in -laprutil... no<BR>checking for an ANSI C-conforming const... yes<BR>checking for apxs... apxs<BR>checking how to run the C preprocessor... gcc -E<BR>checking for egrep... grep -E<BR>checking for ANSI C header files... yes<BR>checking for sys/types.h... yes<BR>checking for sys/stat.h... yes<BR>checking for stdlib.h... yes<BR>checking for string.h... yes<BR>checking for memory.h... yes<BR>checking for strings.h... yes<BR>checking for inttypes.h... yes<BR>checking for stdint.h... yes<BR>checking for unistd.h... yes<BR>checking stdio.h usability... yes<BR>checking stdio.h presence... yes<BR>checking for stdio.h... yes<BR>checking for string.h... (cached) yes<BR>checking assert.h usability... yes<BR>checking assert.h presence... yes<BR>checking for assert.h... yes<BR>checking ctype.h usability... yes<BR>checking ctype.h presence... yes<BR>checking for ctype.h... yes<BR>checking errno.h usability... yes<BR>checking errno.h presence... yes<BR>checking for errno.h... yes<BR>checking math.h usability... yes<BR>checking math.h presence... yes<BR>checking for math.h... yes<BR>checking netinet/in.h usability... yes<BR>checking netinet/in.h presence... yes<BR>checking for netinet/in.h... yes<BR>checking sys/socket.h usability... yes<BR>checking sys/socket.h presence... yes<BR>checking for sys/socket.h... yes<BR>checking arpa/inet.h usability... yes<BR>checking arpa/inet.h presence... yes<BR>checking for arpa/inet.h... yes<BR>configure: creating ./config.status<BR>config.status: creating Makefile</FONT><BR><BR># make<BR><FONT color=#0000ff>apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -c src/mod_cband.c<BR>/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic&nbsp;&nbsp;-DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd&nbsp;&nbsp;-I/usr/include/apr-1&nbsp; &nbsp;-I/usr/include/apr-1&nbsp;&nbsp;-Wall -DDST_CLASS=3&nbsp;&nbsp;-c -o src/mod_cband.lo src/mod_cband.c &amp;&amp; touch src/mod_cband.slo<BR>src/mod_cband.c:81: warning: type qualifiers ignored on function return type<BR>/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o src/mod_cband.la&nbsp;&nbsp;-rpath /usr/lib64/httpd/modules -module -avoid-version&nbsp; &nbsp; src/mod_cband.lo</FONT><BR><BR># make install<BR><FONT color=#0000ff>apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -i -a -n cband src/mod_cband.la<BR>/usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' src/mod_cband.la /usr/lib64/httpd/modules<BR>/usr/lib64/apr-1/build/libtool --mode=install cp src/mod_cband.la /usr/lib64/httpd/modules/<BR>cp src/.libs/mod_cband.so /usr/lib64/httpd/modules/mod_cband.so<BR>cp src/.libs/mod_cband.lai /usr/lib64/httpd/modules/mod_cband.la<BR>cp src/.libs/mod_cband.a /usr/lib64/httpd/modules/mod_cband.a<BR>chmod 644 /usr/lib64/httpd/modules/mod_cband.a<BR>ranlib /usr/lib64/httpd/modules/mod_cband.a<BR>PATH="$PATH:/sbin" ldconfig -n /usr/lib64/httpd/modules<BR>----------------------------------------------------------------------<BR>Libraries have been installed in:<BR>&nbsp; &nbsp;/usr/lib64/httpd/modules</FONT> <FONT color=#0000ff>If you ever happen to want to link against installed libraries<BR>in a given directory, LIBDIR, you must either use libtool, and<BR>specify the full pathname of the library, or use the `-LLIBDIR'<BR>flag during linking and do at least one of the following:<BR>&nbsp; &nbsp;- add LIBDIR to the `LD_LIBRARY_PATH' environment variable<BR>&nbsp; &nbsp;&nbsp;&nbsp;during execution<BR>&nbsp; &nbsp;- add LIBDIR to the `LD_RUN_PATH' environment variable<BR>&nbsp; &nbsp;&nbsp;&nbsp;during linking<BR>&nbsp; &nbsp;- use the `-Wl,--rpath -Wl,LIBDIR' linker flag<BR>&nbsp; &nbsp;- have your system administrator add LIBDIR to `/etc/ld.so.conf'</FONT><BR><FONT color=#0000ff>See any operating system documentation about shared libraries for<BR>more information, such as the ld(1) and ld.so(8) manual pages.<BR>----------------------------------------------------------------------<BR>chmod 755 /usr/lib64/httpd/modules/mod_cband.so<BR>[activating module `cband' in /etc/httpd/conf/httpd.conf]<BR><BR><FONT color=#ff0000>安裝一切順利沒有錯誤訊息,安裝過程中編譯好 mod_cband.so 且被放置到 Apache 的模組資料夾(/usr/lib64/httpd/modules/)內了<BR>及在 Apache 的設定檔(/etc/httpd/conf/httpd.conf)內加入了載入模組 <BR>LoadModule cband_module&nbsp; &nbsp;&nbsp; &nbsp; /usr/lib64/httpd/modules/mod_cband.so</FONT><BR></FONT><BR><FONT color=#ff0000><B>至此mod_cband裝設已經完成,</B></FONT><FONT color=#ff0000><B>所以後續再設定要管控的相關設定即可!</B><BR></FONT><BR>如果沒有安裝 apsx 或 apsx2 的話 請用下面的方式編譯<BR># cd mod-cband-0.9.7.5<BR># ./configure –add-module=../mod-cband/mod_cband.c –enable-shared=cband –enable-module=so<BR># make<BR># make install<BR></BLOCKQUOTE>使用該模組對 VirtualHost 設定可以使用的頻寬 (在 mos-cband 模組解壓縮後有一個 INSTALL 檔,裡面有詳述)<BR>以下我針對我的設定說明:
<BLOCKQUOTE>設定 /etc/httpd/conf/httpd.conf<BR>以下使用最簡單的方式配置,不作假為複雜的配置,如:CBandClass<BR><BR><FONT color=#993300>&lt;VirtualHost xxx.xxx.xxx.xxx&gt;&nbsp;&nbsp;<FONT color=#ff0000><B># 此處 xxx.xxx.xxx.xxx 請改成你的伺服器 對外 IP 位置</B></FONT><BR>ServerName </FONT><A href="http://www.xspace.idv.tw/" target=_blank><FONT color=#993300>www.xspace.idv.tw</FONT></A><BR><FONT color=#993300>ServerAdmin </FONT><A href="mailto:webmaster@xspace.idv.tw" target=_blank><FONT color=#993300>webmaster@xspace.idv.tw</FONT></A><BR><FONT color=#993300>DocumentRoot /var/www/www.xspace.idv.tw<BR><BR> #限制此虛擬主機最高訪問速度 1024kbps、每秒最高接受請求數 200 個 、最高並發連接 200 個<BR>CBandSpeed 1024 200 200<BR><BR>#限制來自遠端訪問速度512kB每秒,30個請求每秒,30個連接。<BR>CBandRemoteSpeed 512kb/s 30 30<BR> <BR>&nbsp;&nbsp;#設定多久對所記錄的全域訪問頻寬進行重設(歸零)&nbsp;&nbsp;4W=4 weeks 4 週 (一個月)<BR> CBandPeriod 4W<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;#開啟 mod_cband 的即時監看功能,可以透過 </FONT><A href="http://server_name/cband-status" target=_blank><FONT color=#993300>http://server_name/cband-status</FONT></A><FONT color=#993300> 進行觀查。(全域監看)<BR> SetHandler cband-status</FONT><BR><FONT color=#993300> #開啟 mod_cband 的即時監看功能,可以透過 </FONT><A href="http://server_name/cband-status-me" target=_blank><FONT color=#993300>http://server_name/cband-status-me</FONT></A><FONT color=#993300> 進行觀查。(單一監看)<BR>SetHandler cband-status-me<BR><BR>&lt;/VirtualHost&gt;<BR><BR></FONT><BR></BLOCKQUOTE><FONT color=#ff0000><B>以上設定好後 重啟 Apache 服務 後連上這一個所設定的 VirtualHost </B><B>就會受到頻寬限制了<BR>可參考官方的文件也壓縮安模組內的 INSTALL 或 doc 資料夾內的 documentation.txt&nbsp;&nbsp;或 faq.txt 檔案<BR><FONT color=#000000>或可以使用 VirtualHost Template Configurator for Apache2 工具進行配置,但須 XWindows<BR>VirtualHost Template Configurator for Apache2&nbsp;&nbsp;官方網站:<A href="http://www.jackal-net.at/tiki-read_article.php?articleId=25" target=_blank><FONT color=#0066cc>http://www.jackal-net.at/tiki-read_article.php?articleId=25</FONT></A><BR></FONT></B></FONT><BR>原文取自: <A href="http://www.xspace.idv.tw/bo_blog/read.php?7" target=_blank>http://www.xspace.idv.tw/bo_blog/read.php?7</A><BR>

wudas 2009-8-12 13:13

甘拎剌 謝謝哈..好東西

mmmnnnbbb 2010-8-11 13:33

可以請問apsx 或 apsx2 是指什麼  網路上找不到相關的說明  感謝
頁: [1]
查看完整版本: Apache 2 頻寬限制模組 mod_cband