Tag Archives: apach2

限制apache2的连接数

在debian下安装:
#apt-get install libapache-mod-limitipconn
 
不知道安装到什么地方了
 find / -name mod_limitipconn.so
/usr/lib/apache/1.3/mod_limitipconn.so
居然在1.3的目录下,复制到apache2的目录中
cp /usr/lib/apache/1.3/mod_limitipconn.so /usr/lib/apache2/modules/
 
修改apache2配置文件
nano /etc/apache2/httpd.conf
在最下面添加

ExtendedStatus On
LoadModule limitipconn_module modules/mod_limitipconn.so

重新启动/etc/init.d/apache2 restart
失败。。。
屏蔽LoadModule limitipconn_module modules/mod_limitipconn.so
正常
看来这个mod不直接支持apache2。。。。。。。
 
不过在官方的确写了安装方法,但是需要重新编译:(
 
Installation
The instructions below are written for Apache 2.0.39 since that’s what I had when I wrote the module, but they will also work with any later version of Apache 2.0.
Instructions for statically compiling mod_limitipconn into httpd:
 
tar xzvf httpd-2.0.39.tar.gz
tar xzvf mod_limitipconn-0.22.tar.gz
cd httpd-2.0.39
./configure –with-module=aaa:../mod_limitipconn-0.22/mod_limitipconn.c
make
make install
Instructions for building as a Dynamic Shared Object (DSO):
 
tar xzvf mod_limitipconn-0.22.tar.gz
cd mod_limitipconn-0.22
make install
Instructions for building static httpd with proxy tracking:
 
tar xzvf httpd-2.0.39.tar.gz
tar xzvf mod_limitipconn-0.22.tar.gz
cd httpd-2.0.39
patch -p1 < ../mod_limitipconn-0.22/apachesrc.diff
./buildconf
./configure –enable-forward –with-module=aaa:../mod_limitipconn-0.22/mod_limitipconn.c
make
make install
Instructions for building DSO with proxy tracking:
 
tar xzvf httpd-2.0.39.tar.gz
tar xzvf mod_limitipconn-0.22.tar.gz
cd httpd-2.0.39
patch -p1 < ../mod_limitipconn-0.22/apachesrc.diff
./buildconf
./configure –enable-forward
make
make install
cd ../mod_limitipconn-0.22
PATH=/usr/local/apache2/bin:$PATH make install

修改apache最大连接数

# prefork MPM
# StartServers ……… number of server processes to start
# MinSpareServers …… minimum number of server processes which are kept spare
# MaxSpareServers …… maximum number of server processes which are kept spare
# MaxClients ……….. maximum number of server processes allowed to start
# MaxRequestsPerChild .. maximum number of requests a server process serves
<IfModule prefork.c>
StartServers         5
MinSpareServers      5
MaxSpareServers     10
MaxClients          20
MaxRequestsPerChild  0
</IfModule>
 
# pthread MPM
# StartServers ……… initial  number of server processes to start
# MaxClients ……….. maximum  number of server processes allowed to start
# MinSpareThreads …… minimum  number of worker threads which are kept spare
# MaxSpareThreads …… maximum  number of worker threads which are kept spare
# ThreadsPerChild …… constant number of worker threads in each server process
# MaxRequestsPerChild .. maximum  number of requests a server process serves
<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>
 
 
注意,如果不知道自己的apache2使用哪种工作模式,最简单的方法,先restart一下apache2,然后netstat -t 看看有几个apache2的进程,然后对比一下就可以了
ps:
apache2默认最大256连接,如果需要更大,自己手动编译