如果你是用Apache Web Server自己架站,而且對外頻寬又不大的話,是否常因為對外頻寬被你架設的網站使用完,而造成你整各網路都很慢呢?
  這裡我為自己的伺服器安裝上了 mod_cband MODULE,這個MODULE相當好用,可以用來解決架設 Apache 頻寬問題,它可以讓 Apache 來控制管理你的頻寬,才不會導致對外(Up Bandwith)頻寬被用完,連帶影響對內(Down Bandwith)頻寬也變慢。

    以下說明我的安裝過程:



 我的安裝環境:
                   CentOS 5.0
                   Apache 2.2.3
先去下載該模組: mod_cband 目前釋出到 0.9.7.5 版 http://cband.linux.pl/

下載到 /tmp/ 資料夾裡面
# cd /tmp
# wget http://cband.linux.pl/download/mod-cband-0.9.7.5.tgz

解壓縮: tar -zxvf mod-cband-0.9.7.5.tgz

如果你有安裝 apsx 或 apsx2 的話 請用下面安裝 (我用此方式,因我有安裝 apsx )
# cd mod-cband-0.9.7.5
# ./configure
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 for apxs... apxs
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


# make
apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -c src/mod_cband.c
/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  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd  -I/usr/include/apr-1   -I/usr/include/apr-1  -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/lib64/apr-1/build/libtool --silent --mode=link gcc -o src/mod_cband.la  -rpath /usr/lib64/httpd/modules -module -avoid-version    src/mod_cband.lo


# make install
apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -i -a -n cband src/mod_cband.la
/usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' src/mod_cband.la /usr/lib64/httpd/modules
/usr/lib64/apr-1/build/libtool --mode=install cp src/mod_cband.la /usr/lib64/httpd/modules/
cp src/.libs/mod_cband.so /usr/lib64/httpd/modules/mod_cband.so
cp src/.libs/mod_cband.lai /usr/lib64/httpd/modules/mod_cband.la
cp src/.libs/mod_cband.a /usr/lib64/httpd/modules/mod_cband.a
chmod 644 /usr/lib64/httpd/modules/mod_cband.a
ranlib /usr/lib64/httpd/modules/mod_cband.a
PATH="$PATH:/sbin" ldconfig -n /usr/lib64/httpd/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/lib64/httpd/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/lib64/httpd/modules/mod_cband.so
[activating module `cband' in /etc/httpd/conf/httpd.conf]

安裝一切順利沒有錯誤訊息,安裝過程中編譯好 mod_cband.so 且被放置到 Apache 的模組資料夾(/usr/lib64/httpd/modules/)內了
及在 Apache 的設定檔(/etc/httpd/conf/httpd.conf)內加入了載入模組 
LoadModule cband_module       /usr/lib64/httpd/modules/mod_cband.so


至此mod_cband裝設已經完成,所以後續再設定要管控的相關設定即可!

如果沒有安裝 apsx 或 apsx2 的話 請用下面的方式編譯
# cd mod-cband-0.9.7.5
# ./configure –add-module=../mod-cband/mod_cband.c –enable-shared=cband –enable-module=so
# make
# make install

使用該模組對 VirtualHost 設定可以使用的頻寬 (在 mos-cband 模組解壓縮後有一個 INSTALL 檔,裡面有詳述)
以下我針對我的設定說明:

設定 /etc/httpd/conf/httpd.conf
以下使用最簡單的方式配置,不作假為複雜的配置,如:CBandClass

<VirtualHost xxx.xxx.xxx.xxx>  # 此處 xxx.xxx.xxx.xxx 請改成你的伺服器 對外 IP 位置
 ServerName
www.xspace.idv.tw
 ServerAdmin webmaster@xspace.idv.tw
 DocumentRoot /var/www/www.xspace.idv.tw
 
 #限制此虛擬主機最高訪問速度 1024kbps、每秒最高接受請求數 200 個 、最高並發連接 200 個
 CBandSpeed 1024 200 200
 
 #限制來自遠端訪問速度512kB每秒,30個請求每秒,30個連接。
 CBandRemoteSpeed 512kb/s 30 30
 
  #設定多久對所記錄的全域訪問頻寬進行重設(歸零)  4W=4 weeks 4 週 (一個月)
 CBandPeriod 4W
 
  #開啟 mod_cband 的即時監看功能,可以透過
http://server_name/cband-status 進行觀查。(全域監看)
 SetHandler cband-status

 #開啟 mod_cband 的即時監看功能,可以透過 http://server_name/cband-status-me 進行觀查。(單一監看)
 SetHandler cband-status-me
 
</VirtualHost>

以上設定好後 重啟 Apache 服務 後連上這一個所設定的 VirtualHost 就會受到頻寬限制了
可參考官方的文件也壓縮安模組內的 INSTALL 或 doc 資料夾內的 documentation.txt  或 faq.txt 檔案
或可以使用 VirtualHost Template Configurator for Apache2 工具進行配置,但須 XWindows
VirtualHost Template Configurator for Apache2  官方網站:http://www.jackal-net.at/tiki-read_article.php?articleId=25
創作者介紹

新‧夢想

kevin0523 發表在 痞客邦 PIXNET 留言(0) 人氣()