<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OurApache &#187; 并发数</title>
	<atom:link href="http://ourapache.com/archives/tag/%e5%b9%b6%e5%8f%91%e6%95%b0/feed" rel="self" type="application/rss+xml" />
	<link>http://ourapache.com</link>
	<description>我们致力于一个Apache知识的分享网站</description>
	<lastBuildDate>Tue, 13 Apr 2010 05:18:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>apache限制并发数,IP,带宽设置</title>
		<link>http://ourapache.com/archives/128</link>
		<comments>http://ourapache.com/archives/128#comments</comments>
		<pubDate>Tue, 10 Feb 2009 07:53:17 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[宽带]]></category>
		<category><![CDATA[并发数]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=128</guid>
		<description><![CDATA[apache限制并发数,IP,带宽设置]]></description>
			<content:encoded><![CDATA[<div id="read_tpc" class="tpc_content">apache限制并发数,<a href="http://ourapache.com/archives/tag/ip" class="st_tag internal_tag" rel="tag" title="标签 ip 下的日志">IP</a>,带宽设置<br />
限制并发数<br />
下载模块： </p>
<p>到官方网址： http://www.nowhere-land.org/programs/mod_vhost_limit/下载模块</p>
<p>http://www.nowhere-land.org/programs/mod_vhost_limit/mod_vhost_limit-0.4.tar.gz</p>
<p>安装：<br />
apxs -c mod_vhost_limit.c -o /path/to/libexec/mod_vhost_limit.so</p>
<p>在 httpd.conf 加入：</p>
<p>LoadModule vhost_limit_module libexec/mod_vhost_limit.so<br />
AddModule mod_vhost_limit.c</p>
<p>配置：</p>
<p>MaxClients 150<br />
ExtendedStatus On</p>
<p>NameVirtualHost *<br />
ServerName server1<br />
DocumentRoot /some/where/1<br />
MaxVhostClients 100<br />
ServerName server2<br />
DocumentRoot /some/where/2<br />
MaxVhostClients 30<br />
ServerName server3<br />
DocumentRoot /some/where/3</p>
<p>其中： server1 被限制为 100 个并发线程数。 server2 被限制为 30 个并发线程数。 server3 没有被限制。</p>
<p>注：需 mod_status 的 ExtendedStatus On 支持！！</p>
<p>如超出限制的并发数在客户端就会出现503错误</p>
<p>———————————————————————————————-</p>
<p>限制IP连接数</p>
<p>到这里下载模块 http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz</p>
<p>安装:<br />
tar zxvf mod_limitipconn-0.04.tar.gz<br />
cd mod_limitipconn-0.04<br />
make APXS=/usr/local/apache/bin/apxs ß—–这里要按你自己的路径设置<br />
make install APXS=/usr/local/apache/bin/apxs ß—–这里要按你自己的路径设置</p>
<p>编辑httpd.conf<br />
添加<br />
全局变量:<br />
&lt; IfModule mod_limitipconn.c &gt;<br />
&lt; Location / &gt; # 所有虚拟主机的/目录<br />
MaxConnPerIP 3 # 每IP只允许3个并发连接<br />
NoIPLimit image/* # 对图片不做IP限制<br />
&lt; /Location &gt;</p>
<p>&lt; Location /mp3 &gt; # 所有主机的/mp3目录<br />
MaxConnPerIP 1 # 每IP只允许一个连接请求<br />
OnlyIPLimit audio/mpeg video # 该限制只对视频和音频格式的文件<br />
&lt; /Location &gt;<br />
&lt; /IfModule &gt;</p>
<p>或者虚拟主机的:<br />
&lt; VirtualHost xx.xxx.xx.xx &gt; ##ip 地址<br />
ServerAdmin easy@phpv.net<br />
DocumentRoot /home/easy<br />
ServerName www.phpv.net<br />
&lt; IfModule mod_limitipconn.c &gt;<br />
&lt; Location / &gt;<br />
MaxConnPerIP 5<br />
NoIPLimit image/*<br />
&lt; /Location &gt;<br />
&lt; Location /mp3 &gt; # 所有主机的/mp3目录<br />
MaxConnPerIP 2 # 每IP只允许一个连接请求<br />
OnlyIPLimit audio/mpeg video # 该限制只对视频和音频格式的文件<br />
&lt; /Location &gt;<br />
&lt; /IfModule &gt;<br />
&lt; /VirtualHost &gt;</p>
<p>———————————————————————————————-</p>
<p>限制带宽：</p>
<p>下载模块 ftp://ftp.cohprog.com/pub/apache/module/1.3.0/mod_bandwidth.c<br />
安装:<br />
/usr/local/apache/bin/apxs -c ./mod_bandwidth.c -o /usr/local/apache/libexec/mod_bandwidth.so</p>
<p>&lt;——-以上/usr/local/apache请设置为你的路径</p>
<p>编辑httpd.conf<br />
添加：<br />
LoadModule bandwidth_module libexec/mod_bandwidth.so<br />
AddModule mod_bandwidth.c</p>
<p>重启你的apache</p>
<p>相关文档：</p>
<p>Global configuration directives :</p>
<p>BandWidthDataDir<br />
Syntax : BandWidthDataDir<br />
Default : “/tmp/apachebw”<br />
Context : server config<br />
Sets the name of the root directory used by mod_bandwidth to store its internal temporary information. Don’t forget to create the needed directories : /master and /link</p>
<p>BandWidthModule<br />
Syntax : BandWidthModule</p></div>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年02月7号 -- <a href="http://ourapache.com/archives/92" title="在Apache下限制每个虚拟主机的并发数">在Apache下限制每个虚拟主机的并发数</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/9" title="apache禁止使用IP访问的实现方法">apache禁止使用IP访问的实现方法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/ip" title="ip" rel="tag">ip</a>, <a href="http://ourapache.com/archives/tag/%e5%ae%bd%e5%b8%a6" title="宽带" rel="tag">宽带</a>, <a href="http://ourapache.com/archives/tag/%e5%b9%b6%e5%8f%91%e6%95%b0" title="并发数" rel="tag">并发数</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/128/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在Apache下限制每个虚拟主机的并发数</title>
		<link>http://ourapache.com/archives/92</link>
		<comments>http://ourapache.com/archives/92#comments</comments>
		<pubDate>Sat, 07 Feb 2009 12:32:45 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache初级应用]]></category>
		<category><![CDATA[并发数]]></category>
		<category><![CDATA[虚拟主机]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=92</guid>
		<description><![CDATA[在Apache下限制每个虚拟主机的并发数]]></description>
			<content:encoded><![CDATA[<p>下载模块：<a href="http://www.nowhere-land.org/programs/mod_vhost_limit/"><span style="color: #218dd1;">http://www.nowhere-land.org/programs/mod_vhost_limit/</span></a></p>
<p>安装：</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="function anonymous() { function anonymous() { linenumber(this) } }">
<li class="hl-firstline">apxs -c mod_vhost_limit.c -o /path/to/libexec/mod_vhost_limit.so</li>
</ol>
</div>
<p>在 httpd.conf 加入：</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="function anonymous() { function anonymous() { linenumber(this) } }">
<li class="hl-firstline">LoadModule vhost_limit_module libexec/mod_vhost_limit.so</li>
<li>AddModule mod_vhost_limit.c</li>
</ol>
</div>
<p>配置：</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="function anonymous() { function anonymous() { linenumber(this) } }">
<li class="hl-firstline">MaxClients 150</li>
<li>ExtendedStatus On</li>
<li> </li>
<li>NameVirtualHost *</li>
<li>&lt;VirtualHost *&gt;</li>
<li>    ServerName server1</li>
<li>    DocumentRoot /some/where/1</li>
<li>    MaxVhostClients 100</li>
<li>&lt;/VirtualHost&gt;</li>
<li> </li>
<li>&lt;VirtualHost *&gt;</li>
<li>    ServerName server2</li>
<li>    DocumentRoot /some/where/2</li>
<li>    MaxVhostClients 30</li>
<li>&lt;/VirtualHost&gt;</li>
<li> </li>
<li>&lt;VirtualHost *&gt;</li>
<li>    ServerName server3</li>
<li>    DocumentRoot /some/where/3</li>
<li>&lt;/VirtualHost&gt;</li>
</ol>
</div>
<p>其中：server1 被限制为 100 个并发线程数。server2 被限制为 30 个并发线程数。server3 没有被限制。<br />
注：需 mod_status 的 ExtendedStatus On 支持！！</p>
<p>如超出限制的并发数在客户端就会出现503错误：<br />
Service Temporarily Unavailable<br />
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.<br />
——————————————————————————–</p>
<p>Apache/1.3.27 Server at server1 Port 80</p>
<p>在 error_log 中将会有类似以下的错误提示：<br />
[Mon Jun 23 15:22:24 2003] [error] client access to server1 deferred, MaxVhostClients 100 exceeded<br />
——————————————————————————–</p>
<p>下载 mod_limitipconn.c<br />
<a href="http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz"><span style="color: #218dd1;">http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz</span></a><br />
<a href="http://dominia.org/djao/limit/mod_limitipconn-0.04-1.i386.rpm"><span style="color: #218dd1;">http://dominia.org/djao/limit/mod_limitipconn-0.04-1.i386.rpm</span></a><br />
(proxy client detection feature not enabled)<br />
<a href="http://dominia.org/djao/limit/mod_limitipconn-0.04-1.src.rpm"><span style="color: #218dd1;">http://dominia.org/djao/limit/mod_limitipconn-0.04-1.src.rpm</span></a><br />
我用的是tar包下载的是mod_limitipconn-0.04.tar.gz,(该模块已经可以支持apache2)在服务器上执行# wget <a href="http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz"><span style="color: #218dd1;">http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz</span></a> 下载到本地，然后执行下面的命令编译安装。我的apache位于/usr/local/apache目录</p>
<p>解压缩：</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="function anonymous() { function anonymous() { linenumber(this) } }">
<li class="hl-firstline">[root@ns chenlf]# tar zxvf mod_limitipconn-0.04.tar.gz</li>
<li>mod_limitipconn-0.04/</li>
<li>mod_limitipconn-0.04/Makefile</li>
<li>mod_limitipconn-0.04/README</li>
<li>mod_limitipconn-0.04/apachesrc.diff</li>
<li>mod_limitipconn-0.04/mod_limitipconn.c</li>
<li>mod_limitipconn-0.04/ChangeLog</li>
</ol>
</div>
<p>编译安装：</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="function anonymous() { function anonymous() { linenumber(this) } }">
<li class="hl-firstline">[root@ns chenlf]# cd mod_limitipconn-0.04</li>
<li>[root@ns mod_limitipconn-0.04]# ls</li>
<li>apachesrc.diff     ChangeLog     Makefile</li>
<li>mod_limitipconn.c  README</li>
<li>[root@ns mod_limitipconn-0.04]</li>
<li># /usr/local/apache/bin/apxs -c -i -a mod_limitipconn.c</li>
<li>gcc -DLINUX=22 -I/usr/include/db1 -fpic -DSHARED_MODULE -I</li>
<li>/usr/local/apache/include -c mod_limitipconn.c</li>
<li>gcc -shared -o mod_limitipconn.so mod_limitipconn.o</li>
<li>[activating module `limitipconn' in /usr/local/apache/conf/httpd.conf]</li>
<li>cp mod_limitipconn.so </li>
<li>/usr/local/apache/libexec/mod_limitipconn.so</li>
<li>chmod 755 /usr/local/apache/libexec/mod_limitipconn.so</li>
<li>cp /usr/local/apache/conf/httpd.conf</li>
<li>    /usr/local/apache/conf/httpd.conf.bak</li>
<li>cp /usr/local/apache/conf/httpd.conf.new</li>
<li>    /usr/local/apache/conf/httpd.conf</li>
<li>rm /usr/local/apache/conf/httpd.conf.new</li>
</ol>
</div>
<p>修改配置文件：</p>
<ol>
<li>全局控制，在httpd.conf加上以下几行：
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="function anonymous() { function anonymous() { linenumber(this) } }">
<li class="hl-firstline">&lt;IfModule mod_limitipconn.c&gt;</li>
<li>    &lt;Location /&gt; # 所有虚拟主机的/目录</li>
<li>        MaxConnPerIP 3 # 每IP只允许3个并发连接</li>
<li>        NoIPLimit image/* # 对图片不做IP限制</li>
<li>    &lt;/Location&gt;</li>
<li>    &lt;Location /mp3&gt; # 所有主机的/mp3目录</li>
<li>        MaxConnPerIP 1 # 每IP只允许一个连接请求</li>
<li>        OnlyIPLimit audio/mpeg video # 该限制只对视频和音频格式的文件</li>
<li>    &lt;/Location&gt;</li>
<li>&lt;/IfModule&gt;</li>
</ol>
</div>
</li>
<li>局部限制，你也可以在虚拟主机的配置文件里设置IP限制，方法是完全一样：
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="function anonymous() { function anonymous() { linenumber(this) } }">
<li class="hl-firstline">&lt;VirtualHost xx.xxx.xx.xx&gt;</li>
<li>    ServerAdmin chenlf@chinalinuxpub.com</li>
<li>    DocumentRoot /home/my</li>
<li>    ServerName www.my.com</li>
<li>    &lt;IfModule mod_limitipconn.c&gt;</li>
<li>        &lt;Location /&gt; # 所有虚拟主机的/目录</li>
<li>            MaxConnPerIP 5 # 每IP只允许3个并发连接</li>
<li>            NoIPLimit image/* # 对图片不做IP限制</li>
<li>        &lt;/Location&gt;</li>
<li>        &lt;Location /mp3&gt; # 所有主机的/mp3目录</li>
<li>            MaxConnPerIP 2 # 每IP只允许一个连接请求</li>
<li>            OnlyIPLimit audio/mpeg video # 该限制只对视频和音频格式的文件</li>
<li>        &lt;/Location&gt;</li>
<li>    &lt;/IfModule&gt;</li>
<li>    ErrorLog /home/my/logs/error_log</li>
<li>    CustomLog /home/my/logs/access_log common</li>
<li>&lt;/VirtualHost&gt;</li>
</ol>
</div>
</li>
<li>此外必须将 apache 的 ExtendedStatus 设置为ON。<br />
在httpd.conf找到 # ExtendedStatus On 去掉前面的注释即可。</li>
</ol>
<p>好了，全部配置结束，重起apache就可以生效了。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年02月25号 -- <a href="http://ourapache.com/archives/170" title="Apache 两种虚拟主机方式的区别">Apache 两种虚拟主机方式的区别</a></li><li>2009年02月22号 -- <a href="http://ourapache.com/archives/161" title="在Windows上手动配置Apache下面的虚拟主机站点">在Windows上手动配置Apache下面的虚拟主机站点</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/128" title="apache限制并发数,IP,带宽设置">apache限制并发数,IP,带宽设置</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/9" title="apache禁止使用IP访问的实现方法">apache禁止使用IP访问的实现方法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/primary" title="Apache初级应用" rel="tag">Apache初级应用</a>, <a href="http://ourapache.com/archives/tag/%e5%b9%b6%e5%8f%91%e6%95%b0" title="并发数" rel="tag">并发数</a>, <a href="http://ourapache.com/archives/tag/%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba" title="虚拟主机" rel="tag">虚拟主机</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/92/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

