Linux: February 2011 Archives

Apache mod_limitipconn

user-pic
Vote 0 Votes

mod_limitipconn 是 Apache 限制 IP 連線數的 Module,
Client 端使用多線的下載會對 Server 造成較高的 Loading, 其實速度也不見得會比較快

把 mod_limitipconn 編入 httpd
tar xzvf httpd-2.2.17.tar.gz
tar xjvf mod_limitipconn-0.23.tar.bz2
cd httpd-2.2.17
./configure --with-module=aaa:../mod_limitipconn-0.23/mod_limitipconn.c \
--prefix=/usr/local/apache --sysconfdir=/usr/local/apache/conf \
--enable-ssl --enable-rewrite --enable-proxy --enable-expires --enable-headers
make
make install

加到 httpd.conf, 本例是每個 IP 限制 4 個連線, 圖檔不限制
MaxConnPerIP 4
NoIPLimit image/*

重啟 Apache 後, 查看 phpinfo() 若 Loaded Modules 有看到 mod_limitipconn 表示已經有載入
使用多線下載軟體如 Flashget 測試, 線程開超過限制的量, 觀察 access log,
若看到到 Apache status code 503 (Service Temporarily Unavailable)
即表示運作正常, 超出的線程被限制住了.

此工具特點是有支援 IPv6, 大部份的 Distro 應該都沒這個套件,
需至 sipcalc 網站 下載 Source 來編譯
以目前 TWNIC 配發的 IPv6 最小區段為例 2001:07FA:0001::/48
就有 2001:07fa:0001:0000:0000:0000:0000:0000 - 2001:07fa:0001:ffff:ffff:ffff:ffff:ffff
共 1208925819614629174706176 個 IP, 已經多到不曉得要用什麼單位來稱呼了

# sipcalc 2001:07FA:0001::/48
-[ipv6 : 2001:07FA:0001::/48] - 0

[IPV6 INFO]
Expanded Address - 2001:07fa:0001:0000:0000:0000:0000:0000
Compressed address - 2001:7fa:1::
Subnet prefix (masked) - 2001:7fa:1:0:0:0:0:0/48
Address ID (masked) - 0:0:0:0:0:0:0:0/48
Prefix address - ffff:ffff:ffff:0:0:0:0:0
Prefix length - 48
Address type - Aggregatable Global Unicast Addresses
Network range - 2001:07fa:0001:0000:0000:0000:0000:0000 -
2001:07fa:0001:ffff:ffff:ffff:ffff:ffff

當然也可計算 IPv4
# sipcalc 192.168.22.1/23
-[ipv4 : 192.168.22.1/23] - 0

[CIDR]
Host address - 192.168.22.1
Host address (decimal) - 3232241153
Host address (hex) - C0A81601
Network address - 192.168.22.0
Network mask - 255.255.254.0
Network mask (bits) - 23
Network mask (hex) - FFFFFE00
Broadcast address - 192.168.23.255
Cisco wildcard - 0.0.1.255
Addresses in network - 512
Network range - 192.168.22.0 - 192.168.23.255
Usable range - 192.168.22.1 - 192.168.23.254

ref. Linux上好用的IP計算工具-sipcalc

About this Archive

This page is an archive of entries in the Linux category from February 2011.

Linux: December 2010 is the previous archive.

Linux: March 2011 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Linux: Monthly Archives

Monthly Archives