<?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; Apache高级应用</title>
	<atom:link href="http://ourapache.com/archives/category/advanced/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>Apache2中俩种设置PHP的异同</title>
		<link>http://ourapache.com/archives/318</link>
		<comments>http://ourapache.com/archives/318#comments</comments>
		<pubDate>Tue, 09 Mar 2010 01:38:09 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[apache2handler]]></category>
		<category><![CDATA[Hook]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=318</guid>
		<description><![CDATA[Apache2开始引入了Hook方式, 对应的在PHP中也提供了apache2handler这种sapi. 

和我之前介绍过的PHP lifecycle不同, 这种情况下的PHP, 通过注册handler钩子, 从而可以在handler hook阶段有机会处理请求, 通过判断请求的handler, 来确定是否需要处理, 如果需要就会调用自身的处理器.
]]></description>
			<content:encoded><![CDATA[<p>Apache2开始引入了Hook方式, 对应的在PHP中也提供了apache2handler这种sapi.</p>
<p>和我之前介绍过的PHP lifecycle不同, 这种情况下的PHP, 通过注册handler钩子, 从而可以在handler hook阶段有机会处理请求, 通过判断请求的handler, 来确定是否需要处理, 如果需要就会调用自身的处理器.</p>
<p>那么, 这种情况下也就有了多种配置方法, 主要考虑如下俩种方式(第二种可以有多种变种):</p>
<blockquote><p>
第一种: AddType application/x-httpd-php .php<br />
第二种:<br />
      &lt;FilesMatch \.php$&gt;<br />
          SetHandler application/x-httpd-php</p></blockquote>
<p>首先来说, 这俩中方式的起作用的时刻不同, 对于第一种方式来说, 他是在type_check钩子阶段起作用的, 也就是在apache2src/modules/http/mod_mime.c中, 通过注册type_checker钩子, 加入find_ct(content_type), 在find_ct中, 通过配置文件中的mime映射, 或者是通过addType指令增加的映射, 根据文件的扩展来填充请求中的handler字段:</p>
<p>而对于第二种方式, 是在fixup钩子阶段, 通过注册fixups钩子阶段加入core_override_type(apache2src/server/core.c)函数, 来将目录级的配置指令生效.</p>
<p>而fixups钩子是晚于type_checker钩子的, 也是handler钩子之前最后的一个可以利用的钩子. 所以如果同时采用1,2俩种方式, 那么第二种方式会覆盖第一种方式设置的handler.</p>
<p>其次, 俩种方式依赖的数据结构不同, 第一种方式依赖的是一个全局的mime对照表extension_mappings, 这个表由mime配置文件和AddType指令而来.</p>
<p>而对于第二种方式, 它是根据配置文件构造的dir_config而来:</p>
<blockquote><p>
&#8230;.<br />
  core_dir_config *conf =<br />
        (core_dir_config *)ap_get_module_config(r-&gt;per_dir_config,<br />
                                                &amp;core_module);<br />
 <br />
    /* Check for overrides with ForceType / SetHandler<br />
*/<br />
    if (conf-&gt;mime_type &amp;&amp; strcmp(conf-&gt;mime_type, “none”))<br />
        ap_set_content_type(r, (char*) conf-&gt;mime_type);<br />
 <br />
    if (conf-&gt;handler &amp;&amp; strcmp(conf-&gt;handler, “none”))<br />
        r-&gt;handler = conf-&gt;handler;</p></blockquote>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年02月26号 -- <a href="http://ourapache.com/archives/184" title="Apache日志文件（配置和管理）">Apache日志文件（配置和管理）</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/123" title="Apache高级配置中文详解">Apache高级配置中文详解</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/66" title="Apache配置文件(httpd.conf)中文说明">Apache配置文件(httpd.conf)中文说明</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/9" title="apache禁止使用IP访问的实现方法">apache禁止使用IP访问的实现方法</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/3" title="apache的配置优化">apache的配置优化</a></li><li>2008年12月25号 -- <a href="http://ourapache.com/archives/1" title="使用gzip将你的Apache速度提高十倍">使用gzip将你的Apache速度提高十倍</a></li></ul>
	标签：<a href="http://ourapache.com/archives/tag/apache2handler" title="apache2handler" rel="tag">apache2handler</a>, <a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/hook" title="Hook" rel="tag">Hook</a>, <a href="http://ourapache.com/archives/tag/%e9%85%8d%e7%bd%ae" title="配置" rel="tag">配置</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/318/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用Apache做负载均衡</title>
		<link>http://ourapache.com/archives/314</link>
		<comments>http://ourapache.com/archives/314#comments</comments>
		<pubDate>Sat, 12 Dec 2009 15:38:45 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[负载均衡]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=314</guid>
		<description><![CDATA[第一次看到这个标题时我也很惊讶，Apache居然还能做负载均衡？真是太强大了。经过一番调查后发现的确可以，而且功能一点都不差。这都归功于 mod_proxy 这个模块。不愧是强大的Apache啊。]]></description>
			<content:encoded><![CDATA[<p>    第一次看到这个标题时我也很惊讶，Apache居然还能做负载均衡？真是太强大了。经过一番调查后发现的确可以，而且功能一点都不差。这都归功于 <a href="http://ourapache.com/archives/tag/mod_proxy" class="st_tag internal_tag" rel="tag" title="标签 mod_proxy 下的日志">mod_proxy</a> 这个模块。不愧是强大的Apache啊。</p>
<p>    废话少说，下面就来解释一下负载均衡的设置方法。</p>
<p>    一般来说，负载均衡就是将客户端的请求分流给后端的各个真实服务器，达到负载均衡的目的。还有一种方式是用两台服务器，一台作为主服务器(Master)，另一台作为热备份(Hot Standby)，请求全部分给主服务器，在主服务器当机时，立即切换到备份服务器，以提高系统的整体可靠性。</p>
<p>    <strong>负载均衡的设置</strong></p>
<p>    Apache可以应对上面这两种需求。先来讨论一下如何做负载均衡。首先需要启用Apache的几个模块：</p>
<pre>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#f3f3f3"><span style="font-weight: bold;">以下是引用片段：</span>
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so</td>
</tr>
</tbody>
</table>
</pre>
<p>    mod_proxy提供代理服务器功能，mod_proxy_balancer提供负载均衡功能， mod_proxy_http让代理服务器能支持HTTP协议。如果把mod_proxy_http换成其他协议模块（如mod_proxy_ftp），或许能支持其他协议的负载均衡，有兴趣的朋友可以自己尝试一下。</p>
<pre>  然后要添加以下配置：</pre>
<pre>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#f3f3f3"><span style="font-weight: bold;">以下是引用片段：</span>
ProxyRequests Off
&lt;Proxy balancer://mycluster&gt;
    BalancerMember http://node-a.myserver.com:8080
    BalancerMember http://node-b.myserver.com:8080
&lt;/Proxy&gt;
ProxyPass / balancer://mycluster 

# 警告：以下这段配置仅用于调试，绝不要添加到生产环境中！！！
&lt;Location /balancer-manager&gt;
    SetHandler balancer-manager
    Order Deny,Allow
    Deny from all
    Allow from localhost
&lt;/Location&gt; </td>
</tr>
</tbody>
</table>
</pre>
<p>    从上面的 ProxyRequests Off 这条可以看出，实际上负载均衡器就是一个反向代理，只不过它的代理转发地址不是某台具体的服务器，而是一个 balancer:// 协议：</p>
<pre>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#f3f3f3"><span style="font-weight: bold;">以下是引用片段：</span>
ProxyPass / balancer://mycluster</td>
</tr>
</tbody>
</table>
</pre>
<p>    协议地址可以随便定义。然后，在段中设置该balancer协议的内容即可。BalancerMember指令可以添加负载均衡组中的真实服务器地址。</p>
<p>    下面那段是用来监视负载均衡的工作情况的，调试时可以加上（生产环境中禁止使用！），然后访问 <a href="http://localhost/balancer-manager/">http://localhost/balancer-manager/</a> 即可看到负载均衡的工作状况。</p>
<p>    OK，改完之后重启服务器，访问你的Apache所在服务器的地址，即可看到负载均衡的效果了。打开 balancer-manager 的界面，可以看到请求是平均分配的。</p>
<p>    如果不想平均分配怎么办？给 BalancerMember 加上 loadfactor 参数即可，取值范围为1-100。比如你有三台服务器，负载分配比例为 7:2:1，只需这样设置：</p>
<pre>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#f3f3f3"><span style="font-weight: bold;">以下是引用片段：</span>
ProxyRequests Off
&lt;Proxy balancer://mycluster&gt;
    BalancerMember http://node-a.myserver.com:8080 loadfactor=7
    BalancerMember http://node-b.myserver.com:8080 loadfactor=2
    BalancerMember http://node-c.myserver.com:8080 loadfactor=1
&lt;/Proxy&gt;
ProxyPass / balancer://mycluster</td>
</tr>
</tbody>
</table>
</pre>
<pre>    默认情况下，负载均衡会尽量让各个服务器接受的请求次数满足预设的比例。如果要改变算法，可以使用 lbmethod 属性。如：</pre>
<pre>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#f3f3f3"><span style="font-weight: bold;">以下是引用片段：</span>
ProxyRequests Off
&lt;Proxy balancer://mycluster&gt;
    BalancerMember http://node-a.myserver.com:8080 loadfactor=7
    BalancerMember http://node-b.myserver.com:8080 loadfactor=2
    BalancerMember http://node-c.myserver.com:8080 loadfactor=1
&lt;/Proxy&gt;
ProxyPass / balancer://mycluster
ProxySet lbmethod=bytraffic</td>
</tr>
</tbody>
</table>
</pre>
<p>    lbmethod可能的取值有：</p>
<div class="ie5">
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#f3f3f3"><span style="font-weight: bold;">以下是引用片段：</span><br />
lbmethod=byrequests按照请求次数均衡(默认)<br />
lbmethod=bytraffic按照流量均衡<br />
lbmethod=bybusyness按照繁忙程度均衡(总是分配给活跃请求数最少的服务器)</td>
</tr>
</tbody>
</table>
</div>
<p>    各种算法的原理请参见<a href="http://httpd.apache.org/docs/2.2/en/mod/mod_proxy_balancer.html">Apache的文档</a>。</p>
<p>    <strong>热备份(Hot Standby)</strong></p>
<p>    热备份的实现很简单，只需添加 status=+H 属性，就可以把某台服务器指定为备份服务器：</p>
<pre>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#f3f3f3"><span style="font-weight: bold;">以下是引用片段：</span>
ProxyRequests Off
&lt;Proxy balancer://mycluster&gt;
    BalancerMember http://node-a.myserver.com:8080
    BalancerMember http://node-b.myserver.com:8080 status=+H
&lt;/Proxy&gt;
ProxyPass / balancer://mycluster</td>
</tr>
</tbody>
</table>
</pre>
<p>    从 balancer-manager 界面中可以看到，请求总是流向 node-a ，一旦node-a挂掉，Apache会检测到错误并把请求分流给 node-b。Apache会每隔几分钟检测一下 node-a 的状况，如果node-a恢复，就继续使用node-a。</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年02月10号 -- <a href="http://ourapache.com/archives/126" title="meta标签的一些解释">meta标签的一些解释</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/286" title="linux下查看nginx，apache，mysql，php的编译参数">linux下查看nginx，apache，mysql，php的编译参数</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/310" title=".htaccess的301跳转">.htaccess的301跳转</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/117" title="让Apache按日期保存日志数据">让Apache按日期保存日志数据</a></li><li>2009年05月8号 -- <a href="http://ourapache.com/archives/245" title="用apache实现禁止IP段或者主机对某个目录的访问">用apache实现禁止IP段或者主机对某个目录的访问</a></li><li>2009年09月6号 -- <a href="http://ourapache.com/archives/306" title="网络流量尽在掌控">网络流量尽在掌控</a></li><li>2009年04月8号 -- <a href="http://ourapache.com/archives/238" title="apache软件体系结构  ">apache软件体系结构  </a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/270" title="Apache配置之URL重写">Apache配置之URL重写</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/29" title="Apache 中KeepAlive 配置的合理使用(优化) ">Apache 中KeepAlive 配置的合理使用(优化) </a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/128" 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/%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1" title="负载均衡" rel="tag">负载均衡</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/314/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apache负载均衡设置方法: mod_proxy</title>
		<link>http://ourapache.com/archives/284</link>
		<comments>http://ourapache.com/archives/284#comments</comments>
		<pubDate>Thu, 13 Aug 2009 15:50:59 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[mod_proxy]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=284</guid>
		<description><![CDATA[　　第一次看到这个标题时我也很惊讶，Apache居然还能做负载均衡?真是太强大了。经过一番调查后发现的确可以，而且功能一点都不差。这都归功于 mod_proxy 这个模块。不愧是强大的Apache啊。]]></description>
			<content:encoded><![CDATA[<p>　　第一次看到这个标题时我也很惊讶，Apache居然还能做负载均衡?真是太强大了。经过一番调查后发现的确可以，而且功能一点都不差。这都归功于 <a href="http://ourapache.com/archives/tag/mod_proxy" class="st_tag internal_tag" rel="tag" title="标签 mod_proxy 下的日志">mod_proxy</a> 这个模块。不愧是强大的Apache啊。</p>
<p>　　废话少说，下面就来解释一下负载均衡的设置方法。</p>
<p>　　一般来说，负载均衡就是将客户端的请求分流给后端的各个真实服务器，达到负载均衡的目的。还有一种方式是用两台服务器，一台作为主服务器(Master)，另一台作为热备份(Hot Standby)，请求全部分给主服务器，在主服务器当机时，立即切换到备份服务器，以提高系统的整体可靠性。</p>
<p>　　负载均衡的设置</p>
<p>　　Apache可以应对上面这两种需求。先来讨论一下如何做负载均衡。首先需要启用Apache的几个模块：</p>
<p>　　程序代码</p>
<blockquote><p>　 LoadModule proxy_module modules/mod_proxy.so<br />
　　LoadModule proxy_balancer_module modules/mod_proxy_balancer.so<br />
　　LoadModule proxy_http_module modules/mod_proxy_http.so</p></blockquote>
<p>　　mod_proxy提供代理服务器功能，mod_proxy_balancer提供负载均衡功能， mod_proxy_http让代理服务器能支持HTTP协议。如果把mod_proxy_http换成其他协议模块(如mod_proxy_ftp)，或许能支持其他协议的负载均衡，有兴趣的朋友可以自己尝试一下。</p>
<p>　　然后要添加以下配置：</p>
<p>　　程序代码</p>
<blockquote><p>ProxyRequests Off<br />
　　<br />
　　BalancerMember http://node-a.myserver.com:8080<br />
　　BalancerMember http://node-b.myserver.com:8080<br />
　　 　　ProxyPass / balancer://mycluster<br />
　　# 警告：以下这段配置仅用于调试，绝不要添加到生产环境中!!!<br />
　　<br />
　　SetHandler balancer-manager<br />
　　order Deny,Allow<br />
　　Deny from all<br />
　　Allow from localhost<br />
　　</p></blockquote>
<p>　　从上面的 ProxyRequests Off 这条可以看出，实际上负载均衡器就是一个反向代理，只不过它的代理转发地址不是某台具体的服务器，而是一个 balancer:// 协议：</p>
<p>　　ProxyPass / balancer://mycluster协议地址可以随便定义。然后，在段中设置该balancer协议的内容即可。 BalancerMember指令可以添加负载均衡组中的真实服务器地址。</p>
<p>　　下面那段是用来监视负载均衡的工作情况的，调试时可以加上(生产环境中禁止使用!)，然后访问 http://localhost/balancer-manager/ 即可看到负载均衡的工作状况。</p>
<p>　　OK，改完之后重启服务器，访问你的Apache所在服务器的地址，即可看到负载均衡的效果了。打开 balancer-manager 的界面，可以看到请求是平均分配的。</p>
<p>　　如果不想平均分配怎么办?给 BalancerMember 加上 loadfactor 参数即可，取值范围为1-100。比如你有三台服务器，负载分配比例为 7:2:1，只需这样设置：</p>
<p>　　程序代码</p>
<blockquote><p>　 ProxyRequests Off<br />
　　<br />
　　BalancerMember http://node-a.myserver.com:8080 loadfactor=7<br />
　　BalancerMember http://node-b.myserver.com:8080 loadfactor=2<br />
　　BalancerMember http://node-c.myserver.com:8080 loadfactor=1<br />
　　 　　ProxyPass / balancer://mycluster</p></blockquote>
<p>　　默认情况下，负载均衡会尽量让各个服务器接受的请求次数满足预设的比例。如果要改变算法，可以使用 lbmethod 属性。如：</p>
<p>　　程序代码</p>
<blockquote><p>　ProxyRequests Off<br />
　　<br />
　　BalancerMember http://node-a.myserver.com:8080 loadfactor=7<br />
　　BalancerMember http://node-b.myserver.com:8080 loadfactor=2<br />
　　BalancerMember http://node-c.myserver.com:8080 loadfactor=1<br />
　　 　　ProxyPass / balancer://mycluster<br />
　　ProxySet lbmethod=bytraffic</p></blockquote>
<p>　　lbmethod可能的取值有：</p>
<p>　　lbmethod=byrequests 按照请求次数均衡(默认)</p>
<p>　　lbmethod=bytraffic 按照流量均衡</p>
<p>　　lbmethod=bybusyness 按照繁忙程度均衡(总是分配给活跃请求数最少的服务器)</p>
<p>　　各种算法的原理请参见[url=http://httpd.apache.org/docs/2.2/en/mod/mod_proxy_balancer.html]Apache的文档[/url]。</p>
<p>　　热备份(Hot Standby)</p>
<p>　　热备份的实现很简单，只需添加 status=+H 属性，就可以把某台服务器指定为备份服务器：</p>
<p>　　程序代码</p>
<blockquote><p>　ProxyRequests Off<br />
　　<br />
　　BalancerMember http://node-a.myserver.com:8080<br />
　　BalancerMember http://node-b.myserver.com:8080 status=+H<br />
　　 　　ProxyPass / balancer://mycluster</p></blockquote>
<p>　　从 balancer-manager 界面中可以看到，请求总是流向 node-a ，一旦node-a挂掉， Apache会检测到错误并把请求分流给 node-b。Apache会每隔几分钟检测一下 node-a 的状况，如果node-a恢复，就继续使用node-a。</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2008年12月25号 -- <a href="http://ourapache.com/archives/1" title="使用gzip将你的Apache速度提高十倍">使用gzip将你的Apache速度提高十倍</a></li><li>2009年02月22号 -- <a href="http://ourapache.com/archives/161" title="在Windows上手动配置Apache下面的虚拟主机站点">在Windows上手动配置Apache下面的虚拟主机站点</a></li><li>2009年07月14号 -- <a href="http://ourapache.com/archives/263" title="初识HTTP中的Referer">初识HTTP中的Referer</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/314" title="使用Apache做负载均衡">使用Apache做负载均衡</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/66" title="Apache配置文件(httpd.conf)中文说明">Apache配置文件(httpd.conf)中文说明</a></li><li>2009年06月14号 -- <a href="http://ourapache.com/archives/253" title="Apache自动添加地址末尾的斜线">Apache自动添加地址末尾的斜线</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/172" title="查询并禁止apache中异常访问量的用户">查询并禁止apache中异常访问量的用户</a></li><li>2010年03月9号 -- <a href="http://ourapache.com/archives/318" title="Apache2中俩种设置PHP的异同">Apache2中俩种设置PHP的异同</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/209" title="面向站长和网站管理员的Web缓存加速指南">面向站长和网站管理员的Web缓存加速指南</a></li><li>2009年01月15号 -- <a href="http://ourapache.com/archives/38" title="Apache服务器安全防范">Apache服务器安全防范</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/mod_proxy" title="mod_proxy" rel="tag">mod_proxy</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/284/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下Apache并发连接数和带宽控制</title>
		<link>http://ourapache.com/archives/281</link>
		<comments>http://ourapache.com/archives/281#comments</comments>
		<pubDate>Thu, 13 Aug 2009 10:13:57 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[mod_bandwidth]]></category>
		<category><![CDATA[mod_limitipconn]]></category>
		<category><![CDATA[带宽]]></category>
		<category><![CDATA[并发连接数]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=281</guid>
		<description><![CDATA[　　Linux+Apache的稳定性、安全性和性能以及低廉的价格正在赢得越来越多的市场份额，使 用Linux+Apache作网站服务器的朋友也越来越多，而Apache作为一种http服务，相比FTP总是不容易控制，特别是当网站以http方式 提供软件/音乐下载时，若是每个用户都开启多个线程并没有带宽的限制，将很快达到http的最大连接数或者造成网络壅塞，使得网站的许多正常服务都无法运 行。不过，Apache的使用者们早已开发出了mod_limitipconn和mod_bandwidth两个模块，来控制http的并发连接数和用户 所能够使用的带宽，下面将以RedHat Linux 7.3+Apache 1.3.7来说明它们的使用方法。]]></description>
			<content:encoded><![CDATA[<p>　　Linux+Apache的稳定性、安全性和性能以及低廉的价格正在赢得越来越多的市场份额，使 用Linux+Apache作网站服务器的朋友也越来越多，而Apache作为一种http服务，相比FTP总是不容易控制，特别是当网站以http方式 提供软件/音乐下载时，若是每个用户都开启多个线程并没有带宽的限制，将很快达到http的最大连接数或者造成网络壅塞，使得网站的许多正常服务都无法运 行。不过，Apache的使用者们早已开发出了mod_limitipconn和mod_bandwidth两个模块，来控制http的并发连接数和用户 所能够使用的带宽，下面将以RedHat Linux 7.3+Apache 1.3.7来说明它们的使用方法。</p>
<p><strong> 一、使用mod_limitipconn限制Apache的并发连接数</strong></p>
<p>　　mod_limitipconn可以控制每个IP地址同时连接服务器某一个目录的并发连接数，是一个非常有用的模块，其官方网页是 http://dominia.org/djao/limitipconn.html，最新版本为for Apache 1.3.7的0.04，并且还有支持Apache 2.x的模块下载，由于本人使用Apache 1.3.7版本，所以请使用2.x版本Apache的朋友到其官方网站察看具体的使用方法。</p>
<p>　　<a href="http://ourapache.com/archives/tag/mod_limitipconn" class="st_tag internal_tag" rel="tag" title="标签 mod_limitipconn 下的日志">mod_limitipconn</a> for Apache 1.3x提供三种安装方式，分别是tar包、rpm安装文件和rpm源文件，由于rpm包只能用在 RedHat 7.x 版本，并且不支持检测代理服务器，所以我们一般都使用tar包的安装方式。</p>
<p>　　以管理员方式登陆服务器，然后在服务器上运行 wget http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz 将mod_limitipconn的tar包下载到服务器，然后按照再运行tar zxvf mod_limitipconn-0.04.tar.gz将tar包解压缩，会在当前目录下生成mod_limitipconn-0.04目录，然后cd mod_limitipconn-0.04进入此目录，下一步就是使用apxs将目录中的mod_limitipconn.c编译。这时，我们需要确定自 己的Apache安装在那个目录，并且找到apxs命令放在哪里。</p>
<p>　　通过命令whereis <a href="http://ourapache.com/archives/tag/apxs" class="st_tag internal_tag" rel="tag" title="标签 apxs 下的日志">apxs</a>，我们可以确定apxs命令的路径，如我的apxs命令所在为/usr/sbin/<a href="http://ourapache.com/archives/tag/apxs" class="st_tag internal_tag" rel="tag" title="标签 apxs 下的日志">apxs</a>，则输入/usr/sbin/<a href="http://ourapache.com/archives/tag/apxs" class="st_tag internal_tag" rel="tag" title="标签 apxs 下的日志">apxs</a> -c -i -a mod_limitipconn.c对mod_limitipconn.c进行编译，此命令会自动在你Apache的配置文件httpd.conf中加入 需要的信息，并且将生成的mod_limitipconn.so模块拷贝到Apache的模块目录。不过为了确认此命令是否正常运作，请首先检查自己的 Apache模块目录（我的是/usr/lib/apache），看内部是否含有mod_limitipconn.so文件，没有的话请将 mod_limitipconn-0.04目录中生成的文件拷贝到此处。</p>
<p>　　刚才命令自动生成的httpd.conf可能有些错误，在我的系统中，它将LoadModule limitipconn_module modules/mod_limitipconn.so放在了</p>
<blockquote><p>LoadModule python_module modules/mod_python.so</p></blockquote>
<p>之间，而将AddModule mod_limitipconn.c放在了</p>
<blockquote><p>AddModule mod_python.c</p></blockquote>
<p>之间，直接造成了mod_limitipconn模块不能正常运行，所以请将这两行分别移动到没 有的相应行中，然后请确认mod_status模块已经加载，并且在 mod_status下添加了ExtendedStatus On这一行。这时我们的mod_limitipconn模块就安装完毕，下一步就是对某个目录进行并发连接数的设置了。</p>
<p>　　mod_limitipconn可以对全局和虚拟主机进行不同的限制，其语法结构都是</p>
<blockquote><p>#所限制的目录所在，此处表示主机的根目录<br />
MaxConnPerIP 3 #所限制的每个IP并发连接数为3个<br />
NoIPLimit image/* #对图片不做IP限制</p>
<p>#所限制的目录所在，此处表示主机的/mp3目录<br />
MaxConnPerIP 1 #所限制的每个IP并发连接数为1个<br />
OnlyIPLimit audio/mpeg video #该限制只对视频和音频格式的文件</p></blockquote>
<p>　　当对全局进行限制时，将这段代码放在httpd.conf文件没有VirtualHost的地方，若是对某个虚拟主机进行限制，请将其放 在和之间，我们可以通过更改Location以及 MaxConnPerIP方便的控制所限制的目录和并发连接数。</p>
<p>　　最后，只要重新启动Apache服务，并发连接数的限制就可以生效。</p>
<p><strong>二、使用mod_bandwidth控制Apache的带宽</strong></p>
<p>　　Apache 1.3.7实际上带有mod_bandwidth支持，只是没有此模块的so文件，我们所做的就是下载mod_bandwidth的源文件进行编译，并对mod_bandwidth进行相应的设置。</p>
<p>　　在下载之前，请先确认自己的Apache配置文件httpd.conf中是否含有</p>
<blockquote><p>LoadModule bandwidth_module modules/<a href="http://ourapache.com/archives/tag/mod_bandwidth" class="st_tag internal_tag" rel="tag" title="标签 mod_bandwidth 下的日志">mod_bandwidth</a>.so</p></blockquote>
<p>以及</p>
<blockquote><p>AddModule mod_bandwidth.c</p></blockquote>
<p>若是没有，请加上</p>
<blockquote><p>LoadModule bandwidth_module<br />
libexec/apache/mod_bandwidth.so<br />
AddModule mod_bandwidth.c</p></blockquote>
<p>　　并且这两行必须分别加在相应区域的最前面，使得这个模块以最低的优先级运行。（不过1.3.7的Apache应该有，呵呵）。</p>
<p>　　确认后，请输入 wget ftp://ftp.cohprog.com/pub/apache/module/1.3.0/mod_bandwidth.c 将源文件下载到服务器，然后请使用apxs对其进行编译，编译方法和mod_limitipconn的基本相同，如我输入/usr/sbin/apxs -c mod_bandwidth.c -o /usr/lib/apache(Apache的模块目录），编译程序会自动将编译成功的mod_bandwidth.so文件放到Apache的模块目 录，您也可以自己确认一下，若是不正常，拷贝过去即可。</p>
<p>　　mod_bandwidth运行时需要一些特定的目录，按照默认情况，请运行以下命令创建并更改目录的权限：</p>
<blockquote><p>mkdir /tmp/apachebw<br />
mkdir /tmp/apachebw/link<br />
mkdir /tmp/apachebw/master<br />
chmod -R 777 /tmp/apachebw</p></blockquote>
<p>　　然后再打开httpd.conf文件，加上以下内容</p>
<blockquote><p>BandWidthDataDir “/tmp/apachebw/”<br />
BandWidthModule on</p></blockquote>
<p>　　这时，我们就能够对所需要限制带宽的目录进行相应的设置，此处的目录请使用服务器的绝对路径。如我们想限制服务器/home/www /thinkjam/download/soft目录的下载速度，也就是限制网址http://download.thinkjam.org/soft目 录下软件的下载速度，则为httpd.conf文件增加以下内容</p>
<blockquote><p>BandWidth thinkjam.org 0 #来自thinkjam.org的下载不受速度限制<br />
BandWidth 210.51.21 0 #来自210.51.21网段的下载不受速度限制<br />
BandWidth all 327680 #来自其它网段的速度都限制为327680Byte，即30KB/s</p></blockquote>
<p>　　设置完毕后，重新启动Apache服务，即可生效。</p>
<p>　　mod_bandwidth还有许多其它有用的参数，如在中间加上MaxConnection 120则可以限制某个目录的最多连接数，当超过指定连接数时，拒绝新的连接，此参数与mod_limitipconn模块结合可以控制某个目录的最多连接人数。</p>
<p>　　其它的参数请朋友们到其官方网站 http://www.cohprog.com/v3/bandwidth/doc-en.html 察看相关的文档。</p>
<p>　　Apache的功能确实强大，很多功能都可以通过添加模块来实现，在 http://modules.apache.org/ 可以找到更多的模块，我们也可以编写自己的模块来实现相应的功能。</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年02月19号 -- <a href="http://ourapache.com/archives/151" title="IE环境下的安全警告汇总收藏">IE环境下的安全警告汇总收藏</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/312" title="apache配置（如何禁止列出目录内容）">apache配置（如何禁止列出目录内容）</a></li><li>2009年01月15号 -- <a href="http://ourapache.com/archives/38" title="Apache服务器安全防范">Apache服务器安全防范</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/187" title="header中的Cache-control参数说明">header中的Cache-control参数说明</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/32" title="htaccess学习笔记">htaccess学习笔记</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/13" title="单独编译apache的rewrite模块">单独编译apache的rewrite模块</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/193" title="header Content-Type类型">header Content-Type类型</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/206" title="http header详解">http header详解</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/117" title="让Apache按日期保存日志数据">让Apache按日期保存日志数据</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/mod_bandwidth" title="mod_bandwidth" rel="tag">mod_bandwidth</a>, <a href="http://ourapache.com/archives/tag/mod_limitipconn" title="mod_limitipconn" rel="tag">mod_limitipconn</a>, <a href="http://ourapache.com/archives/tag/%e5%b8%a6%e5%ae%bd" title="带宽" rel="tag">带宽</a>, <a href="http://ourapache.com/archives/tag/%e5%b9%b6%e5%8f%91%e8%bf%9e%e6%8e%a5%e6%95%b0" title="并发连接数" rel="tag">并发连接数</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/281/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache+Django性能优化之mod_wsgi篇</title>
		<link>http://ourapache.com/archives/275</link>
		<comments>http://ourapache.com/archives/275#comments</comments>
		<pubDate>Thu, 13 Aug 2009 09:53:11 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[mod_wsgi]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=275</guid>
		<description><![CDATA[我们一直使用 Django ，玩聚的各个产品前端都是架设于 Django 之上，如：SR/RT。如果你对 Django 有所了解，可以跳过下面的简介： 什么是Django Django 是一个开放源代码的Web应用框架，由Python写成，主力开发者是Adrian Holovaty。它采用了MVC的设计模式。 Django 的名字来自于比利时的爵士吉他手Django Reinhardt，他是欧陆爵士乐发展的奠基人，也是爵士史上最伟大的吉他巨匠，中国乐迷称之为“三指琴魔”。 Django 源自一个在线新闻 Web 站点，于 2005 年7月在BSD许可证下发布。Django 框架的核心组件有： 用于创建模型的对象关系映射 为最终用户设计的管理界面 一流的 URL 设计 设计者友好的模板语言 缓存系统 如何上手Django 新手入门参考Django Step by Step之limodou版。 DjangoProject.com 是 Django 框架的主页。其中的文档包括： How to install Django，展示了如何在一台开发机器上设置 Django Database API reference，使用 Django ORM 库的指南 Django template language，为模板作者准备的一份简单指南 How to serve static [...]]]></description>
			<content:encoded><![CDATA[<p>我们一直使用 <a href="http://www.djangoproject.com/" target="_blank">Django</a> ，玩聚的各个产品前端都是架设于 <a href="http://ourapache.com/archives/tag/django" class="st_tag internal_tag" rel="tag" title="标签 Django 下的日志">Django</a> 之上，如：<a href="http://sr.ju690.com/" target="_blank">SR</a>/<a href="http://rt.ju690.com/" target="_blank">RT</a>。如果你对 <a href="http://www.djangoproject.com/" target="_blank">Django</a> 有所了解，可以跳过下面的简介：</p>
<p>什么是<a href="http://www.djangoproject.com/" target="_blank">Django</a></p>
<p><strong>Django </strong>是一个开放源代码的Web应用框架，由Python写成，主力开发者是Adrian Holovaty。它采用了MVC的设计模式。</p>
<p><strong>Django </strong>的名字来自于比利时的爵士吉他手Django Reinhardt，他是欧陆爵士乐发展的奠基人，也是爵士史上最伟大的吉他巨匠，中国乐迷称之为“三指琴魔”。</p>
<p><strong>Django </strong>源自一个在线新闻 Web 站点，于 2005 年7月在BSD许可证下发布。Django 框架的核心组件有：</p>
<ul>
<li>用于创建模型的对象关系映射</li>
<li>为最终用户设计的管理界面</li>
<li>一流的 URL 设计</li>
<li>设计者友好的模板语言</li>
<li>缓存系统</li>
</ul>
<p>如何上手<a href="http://www.djangoproject.com/" target="_blank">Django</a></p>
<p>新手入门参考<a href="http://www.woodpecker.org.cn/obp/django/django-stepbystep/newtest/doc/" target="_blank">Django Step by Step之limodou版</a>。</p>
<p><a href="http://www.djangoproject.com/">DjangoProject.com</a> 是 Django 框架的主页。其中的文档包括：</p>
<ul>
<li><a href="http://www.djangoproject.com/documentation/install/">How to install Django</a>，展示了如何在一台开发机器上设置 Django</li>
<li><a href="http://www.djangoproject.com/documentation/db_api/">Database API reference</a>，使用 Django ORM 库的指南</li>
<li><a href="http://www.djangoproject.com/documentation/templates/">Django template language</a>，为模板作者准备的一份简单指南</li>
<li><a href="http://www.djangoproject.com/documentation/static_files/">How to serve static files</a>，如何在开发过程中通过设置 Django 来提供静态文件服务的介绍（<strong>不要</strong>在产品环境中这样做）</li>
<li><a href="http://www.djangoproject.com/documentation/modpython/">How to use Django with mod_python</a>，这是一份有关利用 mod_python 组合使用 Django 和 Apache 的指南</li>
<li><a href="http://www.djangoproject.com/documentation/generic_views/">Generic views</a>，展示了如何使用 Django 的通用视图更快地实现通用的 Web 应用程序模式</li>
</ul>
<p><strong>Django+Apache+mod_python 的用法</strong></p>
<p>一般上手搭配 Django 的是 Apache+<a href="http://www.modpython.org/" target="_blank">mod_python</a> ，从这个<a href="http://man.chinaunix.net/develop/python/mod_python/mod_python.html" target="_blank">早年间的翻译文档</a>可以了解 <a href="http://man.chinaunix.net/develop/python/mod_python/mod_python.html#head-871e5f352b5d3e7a56f7879bd1d31f478a3ae23e" target="_blank">Apache怎样处理请求</a>以及<a href="http://man.chinaunix.net/develop/python/mod_python/mod_python.html#head-1da20b19de452e61f844bf2c5900bf37bd5e9ff4" target="_blank">mod_python到底做了什么</a>。</p>
<p>不过，既然 Django 都已经在文档中说“<strong>it has been mostly superseded by the simpler </strong><a href="http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/#howto-deployment-modwsgi"><em><strong>mod_wsgi deployment option</strong></em></a><strong>./mod_python 多半已被更简单的 <a href="http://ourapache.com/archives/tag/mod_wsgi" class="st_tag internal_tag" rel="tag" title="标签 mod_wsgi 下的日志">mod_wsgi</a> 替代了。</strong>”那么我们就应该一上手就用 mod_wsgi 。</p>
<p><strong>为何要切换到 mod_wsgi ？</strong></p>
<p>mod_python 其实也不差。</p>
<p>但我一直困惑于 Apache+mod_python 的莫名频繁崩溃，错误日志中会出现大量的如下错误：</p>
<blockquote><p>[error] [client X.X.X.X] OSError: [Errno 0] Error<br />
[notice] Parent: child process exited with status <strong>3221225477</strong> &#8212; Restarting.</p></blockquote>
<p>这个状态号 3221225477 基本没什么意义，再加上 OSError 0 ，这个异常日志让人很无奈。甚至在 Windows 平台下，Apache 最恶劣情况下竟然会弹出一个崩溃错误框，此时事件日志会报告：</p>
<blockquote><p>cation Popup:0:29722:26:EVENTLOG_INFORMATION_TYPE:弹出应用程序: Microsoft Visual C++ Runtime Library: Runtime Error!<br />
Program: C:\Apache2.2\bin\httpd.exe<br />
This application has requested the Runtime to terminate it in an unusual way.</p></blockquote>
<p>一直无法对症下药。于是，期冀 mod_wsgi 能让我摆脱这两个问题。</p>
<p>另一个就是性能。</p>
<p><a href="http://code.google.com/p/modwsgi/wiki/PerformanceEstimates" target="_blank">modwsgi 性能评估</a>中列出这样的数字对比：</p>
<p><strong>Mechanism </strong><strong>Requests/sec</strong></p>
<p>mod_cgi (ScriptAlias) 10</p>
<p>mod_python (PythonHandler) 400</p>
<p>mod_wsgi (WSGIDaemonProcess) 700</p>
<p>mod_wsgi (.htaccess/SetHandler) 850</p>
<p>mod_wsgi (WSGIScriptAlias) 900</p>
<p>从数字可以看出，<a href="http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIScriptAlias" target="_blank">WSGIScriptAlias</a> 是最优选择。当然这个数字也没什么，后面人家说了“任何性能提高，都将被你使用的大型Web框架如Django或TurboGears吃掉，尤其是用了数据库后端，大多数的 overhead 源自Python Web Framework以及任何访问数据库时的瓶颈。mod_wsgi上的 overhead 只是很小的一块，这一小块上的任何性能提高都很难被注意到。”</p>
<p><strong>切换到 mod_wsgi 很容易</strong></p>
<p><a href="http://blog.csdn.net/zhengyun_ustc/" target="_blank">郑昀</a>@<a href="http://rt.ju690.com/" target="_blank">玩聚RT</a> 20090810</p>
<p>1、下载</p>
<p>可以从 <a href="http://code.google.com/p/modwsgi/downloads/list" target="_blank">modwsgi 的下载目录</a> 下载你所需要的版本。</p>
<p>对于 Windows 平台，可能需要阅读“<a href="http://code.google.com/p/modwsgi/wiki/InstallationOnWindows" target="_blank">Installation On Windows</a>”，并从这个页面上提示的 <a href="http://adal.chiriliuc.com/mod_wsgi/revision_1018_2.3/mod_wsgi_py25_apache22/" target="_blank">mod_wsgi_py25_apache22 目录</a> 下载 mod_wsgi.so (即我们的平台是Apache2.2+Python2.5+Django1.0.3)。</p>
<p>2、放置</p>
<p>把 mod_wsgi 放到你的Apache安装目录下的 modules 文件夹内。</p>
<p>3、配置Apache</p>
<p>在Apache配置文件httpd.conf中，增加一行：</p>
<blockquote><p>LoadModule wsgi_module modules/mod_wsgi.so</p></blockquote>
<p>4、修改Virtual Host配置</p>
<p>Apache 可以配置很多个 Named-based <a href="http://httpd.apache.org/docs/2.2/vhosts/" target="_blank">Virtual Hosts</a> ，可以在一个服务器上部署多个Web Sites。</p>
<p>mod_python 下的 VirtualHost 配置主要复杂在 Python 配置这块，如下所示：</p>
<blockquote><p>&lt;VirtualHost *:80&gt;<br />
ServerName rt.ju690.com<br />
ServerAlias rt.ju690.cn<br />
DocumentRoot d:/SocialRecommend</p>
<p>&lt;Location “/”&gt;<br />
SetHandler python-program<br />
PythonPath “['d:/SocialRecommend']+sys.path”<br />
PythonHandler django.core.handlers.modpython<br />
SetEnv DJANGO_SETTINGS_MODULE settings_yourproject<br />
PythonAutoReload Off<br />
PythonDebug Off</p>
<p>&lt;/Location&gt;</p>
<p>Alias /static d:/SocialRecommend/static<br />
&lt;Location “/static”&gt;<br />
SetHandler None<br />
&lt;/Location&gt;<br />
&lt;Directory “d:/SocialRecommend/static”&gt;<br />
Order Deny,Allow<br />
Allow from all<br />
&lt;/Directory&gt;</p>
<p>&lt;/VirtualHost&gt;</p></blockquote>
<p>现在改为 mod_wsgi ，只需要稍加改变即可：</p>
<blockquote><p>&lt;VirtualHost *:80&gt;<br />
ServerName rt.ju690.com<br />
ServerAlias rt.ju690.cn<br />
DocumentRoot D:/SocialRecommend<br />
<strong><span style="color: #ff0000;">WSGIScriptAlias / D:\SocialRecommend\wsgi\yourproject.wsgi</span></strong><br />
Alias /static d:/SocialRecommend/static<br />
&lt;Location “/static”&gt;<br />
SetHandler None<br />
&lt;/Location&gt;<br />
&lt;Directory “d:/SocialRecommend/static”&gt;<br />
Order Deny,Allow<br />
Allow from all<br />
&lt;/Directory&gt;<br />
<strong>&lt;Directory “d:/SocialRecommend/wsgi”&gt;<br />
Order Deny,Allow<br />
Allow from all<br />
&lt;/Directory&gt;<br />
</strong>&lt;/VirtualHost&gt;</p></blockquote>
<p><a href="http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIScriptAlias" target="_blank">WSGIScriptAlias 的定义参见 modwsgi wiki</a> ，主要是映射一个URL到一个文件系统地址并委派目标文件为WSGI Script。</p>
<p>赋予本地wsgi文件夹Allow from all权限，是因为这样才能执行WSGI Script。</p>
<p>5、建立wsgi script</p>
<p>在你的web site django总目录下新建一个文件夹wsgi。</p>
<p>在 wsgi 文件夹下新建一个文件 yourproject.wsgi ，内容如下所示：</p>
<blockquote><p># complete_project.wsgi is configured to live in projects/complete_project/deploy.<br />
# If you move this file you need to reconfigure the paths below.</p>
<p>import os<br />
import sys</p>
<p># redirect sys.stdout to sys.stderr for bad libraries like geopy that uses<br />
# print statements for optional import exceptions.<br />
sys.stdout = sys.stderr</p>
<p>from os.path import abspath, dirname, join<br />
from site import addsitedir</p>
<p>from django.core.handlers.wsgi import WSGIHandler</p>
<p>sys.path.insert(0, abspath(join(dirname(__file__), “../”)))<br />
sys.path.insert(0, abspath(join(dirname(__file__), “. . /. . /”)))</p>
<p>os.environ["DJANGO_SETTINGS_MODULE"] = “yourprojectname.settings_yourproject” #你的settings module名</p>
<p>application = WSGIHandler()</p></blockquote>
<p>6、重启Aapche即可。</p>
<p>参考资源：</p>
<p>1、<a href="http://code.google.com/p/modwsgi/" target="_blank">mod_wsgi</a> / <a href="http://www.modpython.org/" target="_blank">mod_python</a> ；</p>
<p>2、<a href="http://code.google.com/p/modwsgi/wiki/PerformanceEstimates" target="_blank">Performance Estimates for mod_wsgi</a> ；</p>
<p>3、<a href="http://code.djangoproject.com/wiki/django_apache_and_mod_wsgi" target="_blank">How to use django with mod_wsgi</a> 。</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年02月10号 -- <a href="http://ourapache.com/archives/126" title="meta标签的一些解释">meta标签的一些解释</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/111" title="Apache 中内存管理的三种境界 ">Apache 中内存管理的三种境界 </a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/209" title="面向站长和网站管理员的Web缓存加速指南">面向站长和网站管理员的Web缓存加速指南</a></li><li>2009年02月6号 -- <a href="http://ourapache.com/archives/72" title="gzip 与 deflate">gzip 与 deflate</a></li><li>2010年04月13号 -- <a href="http://ourapache.com/archives/326" title="解决linux下安装ssl后，apache重启时需要密码">解决linux下安装ssl后，apache重启时需要密码</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/273" title="Apache和IIS共享80端口的四个方法">Apache和IIS共享80端口的四个方法</a></li><li>2010年03月9号 -- <a href="http://ourapache.com/archives/318" title="Apache2中俩种设置PHP的异同">Apache2中俩种设置PHP的异同</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/172" title="查询并禁止apache中异常访问量的用户">查询并禁止apache中异常访问量的用户</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/68" title="apache最大连接数性能测试">apache最大连接数性能测试</a></li><li>2009年09月2号 -- <a href="http://ourapache.com/archives/294" title="HTTP Referer二三事">HTTP Referer二三事</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/django" title="Django" rel="tag">Django</a>, <a href="http://ourapache.com/archives/tag/mod_wsgi" title="mod_wsgi" rel="tag">mod_wsgi</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/275/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>关于HTTP 协议中的 KeepAlive</title>
		<link>http://ourapache.com/archives/236</link>
		<comments>http://ourapache.com/archives/236#comments</comments>
		<pubDate>Wed, 01 Apr 2009 11:27:11 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[KeepAlive]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=236</guid>
		<description><![CDATA[其中使用PHP实现持久的HTTP连接，让我费了很多心思。
曾经想过使用C语言编写一个PHP的扩展来实现，后来发现pfsockopen这个函数，让我豁然开朗，避免重新发明一个轮子，呵呵。]]></description>
			<content:encoded><![CDATA[<p>这篇文章已经写完将近一年了，最近从历史邮件里面翻出来，和大家分享一下。<br />
其中使用PHP实现持久的HTTP连接，让我费了很多心思。<br />
曾经想过使用C语言编写一个PHP的扩展来实现，后来发现pfsockopen这个函数，让我豁然开朗，避免重新发明一个轮子，呵呵。</p>
<p>一，KeepAlive的概念：</p>
<p>参见 http://en.wikipedia.org/wiki/HTTP_persistent_connection</p>
<p>二，KeepAlive的客户端实现：</p>
<p>使用了PHP支持的 pfsockopen 来实现，参见：http://cn.php.net/pfsockopen</p>
<p>KeepAlive必要的Header有：</p>
<blockquote><p>Connection: Keep-Alive<br />
Content-Length: xxx</p></blockquote>
<p>三，性能对比测试：</p>
<p>几种对比实现方式：</p>
<blockquote><p>1，使用fsockopen来实现，读取body内容后，关闭连接，参见测试程序中的ohttp_get实现。<br />
2，使用pfsockopen来实现，读取body内容后，不关闭连接，参见测试程序中的phttp_get实现。<br />
3，php实现的file_get_contents<br />
4，第三方测试工具ab</p></blockquote>
<p>前三种测试在测试程序中都包含了。</p>
<p>测试用例 一：</p>
<p>前三种php实现的客户端单进程单线程请求lighttpd服务器一个16字节的静态文件。顺序请求10000次。<br />
客户端与服务器部署在不同服务器，通过内网请求。</p>
<p>测试结果：</p>
<p>第一次：</p>
<blockquote><p>[root@localhost ~]# /opt/bin/php tp.php<br />
phttp_get: 5.3641529083252<br />
ohttp_get: 8.1628580093384<br />
file_get_contents: 12.217950105667</p></blockquote>
<p>第二次：</p>
<blockquote><p>[root@localhost ~]# /opt/bin/php tp.php<br />
phttp_get: 5.033059835434<br />
ohttp_get: 9.589075088501<br />
file_get_contents: 12.775387048721</p></blockquote>
<p>第三次：</p>
<blockquote><p>[root@localhost ~]# /opt/bin/php tp.php<br />
phttp_get: 5.0181269645691<br />
ohttp_get: 8.2286441326141<br />
file_get_contents: 11.089616060257</p></blockquote>
<p>测试用例 二：</p>
<p>使用第三方工具ab来进行测试，-k参数开打开keepalive支持，不做并发测试，顺序请求10000次。<br />
客户端与服务器部署在不同服务器，通过内网请求。</p>
<p>以下测试结果部分省略：</p>
<p>未打开keepalive：</p>
<blockquote><p>[root@localhost ~]# ab -n 10000 -c 1 “http://10.69.2.206:8080/sms/ns2/save_msg.txt”</p>
<p>Finished 10000 requests</p>
<p>Concurrency Level: 1<br />
Time taken for tests: 10.410467 seconds<br />
Complete requests: 10000<br />
Failed requests: 0<br />
Write errors: 0<br />
Total transferred: 2480000 bytes<br />
HTML transferred: 160000 bytes<br />
Requests per second: 960.57 [#/sec] (mean)<br />
Time per request: 1.041 [ms] (mean)<br />
Time per request: 1.041 [ms] (mean, across all concurrent requests)<br />
Transfer rate: 232.55 [Kbytes/sec] received</p>
<p>Connection Times (ms)<br />
min mean[+/-sd] median max<br />
Connect: 0 0 30.0 0 3002<br />
Processing: 0 0 0.4 0 9<br />
Waiting: 0 0 0.3 0 9<br />
Total: 0 0 30.0 0 3003</p></blockquote>
<p>打开keepalive：</p>
<blockquote><p>[root@localhost ~]# ab -k -n 10000 -c 1 “http://10.69.2.206:8080/sms/ns2/save_msg.txt”</p>
<p>Finished 10000 requests</p>
<p>Concurrency Level: 1<br />
Time taken for tests: 4.148619 seconds<br />
Complete requests: 10000<br />
Failed requests: 0<br />
Write errors: 0<br />
Keep-Alive requests: 9412<br />
Total transferred: 2527060 bytes<br />
HTML transferred: 160000 bytes<br />
Requests per second: 2410.44 [#/sec] (mean)<br />
Time per request: 0.415 [ms] (mean)<br />
Time per request: 0.415 [ms] (mean, across all concurrent requests)<br />
Transfer rate: 594.66 [Kbytes/sec] received</p>
<p>Connection Times (ms)<br />
min mean[+/-sd] median max<br />
Connect: 0 0 0.1 0 5<br />
Processing: 0 0 2.1 0 203<br />
Waiting: 0 0 2.1 0 203<br />
Total: 0 0 2.1 0 203</p></blockquote>
<p>四，在实际中的应用</p>
<p>以上实现的phttp_get和mysql memcache的 中的“保持连接”概念类似，这种技术一般来说，只适用于fastcgi模式的web服务器。<br />
对于本机之间的http通信，在测试过程中发现phttp_get的优势有限，基本合乎逻辑。<br />
对于本身处理时间比较长的服务，phttp_get的优势也不明显。<br />
综上，phttp_get适用于fastcgi模式的web应用调用远程http服务，且此http服务器响应时间比较短的情况。</p>
<p>五，服务端需要注意的事项</p>
<p>1，http服务器必须支持HTTP/1.1协议<br />
2，php应用必须返回Content-Length:的header，具体实现参见：</p>
<p>http://cn.php.net/manual/en/function.ob-get-length.php</p>
<p>需要在代码中加入：</p>
<blockquote><p>ob_start();<br />
$size=ob_get_length();<br />
header(”Content-Length: $size”);<br />
ob_end_flush();</p></blockquote>
<p>最后附上测试代码：</p>
<blockquote><p>&lt;?php</p>
<p>//$url=http://10.69.2.206:8080/sms/ns2/save_msg.txt</p>
<p>function ohttp_get($host,$port,$query,&amp;$body)<br />
{<br />
$fp=pfsockopen($host,$port,$errno,$errstr,1);<br />
if(!$fp)<br />
{<br />
var_dump($errno,$errstr);<br />
return -1;<br />
}<br />
$out = “GET ${query} HTTP/1.1\r\n”;<br />
$out.= “Host: ${host}\r\n”;<br />
$out.= “Connection: close\r\n”;<br />
$out.= “\r\n”;<br />
fwrite($fp,$out);<br />
$line=trim(fgets($fp));<br />
$header.=$line;<br />
list($proto,$rcode,$result)=explode(” “,$line);<br />
$len=-1;<br />
while( ($line=trim(fgets($fp))) != “” )<br />
{<br />
$header.=$line;<br />
if(strstr($line,”Content-Length:”))<br />
{<br />
list($cl,$len)=explode(” “,$line);<br />
}<br />
if(strstr($line,”Connection: close”))<br />
{<br />
$close=true;<br />
}<br />
}<br />
if($len &lt; 0)<br />
{<br />
echo “ohttp_get must cope with Content-Length header!\n”;<br />
return -1;<br />
}<br />
$body=fread($fp,$len);<br />
if($close)<br />
fclose($fp);<br />
return $rcode;<br />
}<br />
function phttp_get($host,$port,$query,&amp;$body)<br />
{<br />
$fp=pfsockopen($host,$port,$errno,$errstr,1);<br />
if(!$fp)<br />
{<br />
var_dump($errno,$errstr);<br />
return -1;<br />
}<br />
$out = “GET ${query} HTTP/1.1\r\n”;<br />
$out.= “Host: ${host}\r\n”;<br />
$out.= “Connection: Keep-Alive\r\n”;<br />
$out.= “\r\n”;<br />
fwrite($fp,$out);<br />
$line=trim(fgets($fp));<br />
$header.=$line;<br />
list($proto,$rcode,$result)=explode(” “,$line);<br />
$len=-1;<br />
while( ($line=trim(fgets($fp))) != “” )<br />
{<br />
$header.=$line;<br />
if(strstr($line,”Content-Length:”))<br />
{<br />
list($cl,$len)=explode(” “,$line);<br />
}<br />
if(strstr($line,”Connection: close”))<br />
{<br />
$close=true;<br />
}<br />
}<br />
if($len &lt; 0)<br />
{<br />
echo “phttp_get must cope with Content-Length header!\n”;<br />
return -1;<br />
}<br />
$body=fread($fp,$len);<br />
if($close)<br />
fclose($fp);<br />
return $rcode;<br />
}</p>
<p>$time1=microtime(true);<br />
for($i=0;$i&lt;10000;$i++)<br />
{<br />
$host=”10.69.2.206″;<br />
$port=8080;<br />
$query=”/sms/ns2/save_msg.txt”;<br />
$body=””;<br />
$r=ohttp_get($host,$port,$query,$body);<br />
if($r != 200)<br />
{<br />
echo “return code : $r\n”;<br />
}<br />
}<br />
$time2=microtime(true);<br />
for($i=0;$i&lt;10000;$i++)<br />
{<br />
$url=”http://10.69.2.206:8080/sms/ns2/save_msg.txt”;<br />
$host=”10.69.2.206″;<br />
$port=8080;<br />
$query=”/sms/ns2/save_msg.txt”;<br />
$body=””;<br />
$r=phttp_get($host,$port,$query,$body);<br />
if($r != 200)<br />
{<br />
echo “return code : $r\n”;<br />
}<br />
}<br />
$time3=microtime(true);<br />
for($i=0;$i array( ‘timeout’ =&gt; 1 )<br />
)<br />
);<br />
$body=file_get_contents($url, 0, $ctx);<br />
$r=200;<br />
if($r != 200)<br />
{<br />
echo “return code : $r\n”;<br />
}<br />
}<br />
$time4=microtime(true);</p>
<p>echo “phttp_get: “.($time3-$time2).”\n”;<br />
echo “ohttp_get: “.($time2-$time1).”\n”;<br />
echo “file_get_contents: “.($time4-$time3).”\n”;</p>
<p>?&gt;</p></blockquote>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年02月10号 -- <a href="http://ourapache.com/archives/109" title="谈谈Apache的优化">谈谈Apache的优化</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/29" title="Apache 中KeepAlive 配置的合理使用(优化) ">Apache 中KeepAlive 配置的合理使用(优化) </a></li><li>2009年01月5号 -- <a href="http://ourapache.com/archives/21" title="关于keepalive的解释">关于keepalive的解释</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/keepalive" title="KeepAlive" rel="tag">KeepAlive</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/236/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache Prefork和Worker模式的性能比较测试</title>
		<link>http://ourapache.com/archives/232</link>
		<comments>http://ourapache.com/archives/232#comments</comments>
		<pubDate>Mon, 30 Mar 2009 13:07:44 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[prefork]]></category>
		<category><![CDATA[worker]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=232</guid>
		<description><![CDATA[相对来说，prefork方式速度要稍高于worker，然而它需要的cpu和memory资源也稍多于woker。]]></description>
			<content:encoded><![CDATA[<div>选择prefork还是worker可以在编译时使用–with-mpm=MPM参数指定,默认为prefork</div>
<div><strong></strong> </div>
<div><strong><a href="http://ourapache.com/archives/tag/prefork" class="st_tag internal_tag" rel="tag" title="标签 prefork 下的日志">prefork</a></strong></div>
<div> </div>
<div>prefork采用预派生子进程方式，用单独的子进程来处理 不同的请求，进程之间彼此独立。在make编译和make install安装后，使用httpd -l来确定当前使用的MPM是prefork.c。查看httpd-mpm.conf配置文件，里面包含如下默认的配置段：</div>
<div> </div>
<blockquote>
<div>&lt;IfModule prefork.c&gt;<br />
StartServers 5<br />
MinSpareServers 5<br />
MaxSpareServers 10<br />
MaxClients 150<br />
MaxRequestsPerChild 0<br />
&lt;/IfModule&gt;</div>
</blockquote>
<div>
prefork 控制进程在最初建立“StartServers”个子进程后，为了满足MinSpareServers设置的需要创建一个进程，等待一秒钟，继续创建两 个，再等待一秒钟，继续创建四个……如此按指数级增加创建的进程数，最多达到每秒32个，直到满足MinSpareServers设置的值为止。这种模式 可以不必在请求到来时再产生新的进程，从而减小了系统开销以增加性能。</div>
<div> </div>
<div>MaxSpareServers设置了最大的空闲进程数，如果空闲进程数大于这个 值，Apache会自动kill掉一些多余进程。这个值不要设得过大，但如果设的值比MinSpareServers小，Apache会自动把其调整为 MinSpareServers+1。如果站点负载较大，可考虑同时加大MinSpareServers和MaxSpareServers。</div>
<div> </div>
<div>MaxRequestsPerChild设置的是每个子进程可处理的请求数。每个子进程在处理了“MaxRequestsPerChild”个请求后将自 动销毁。0意味着无限，即子进程永不销毁。虽然缺省设为0可以使每个子进程处理更多的请求，但如果设成非零值也有两点重要的好处：1、可防止意外的内存泄 漏。2、在服务器负载下降的时侯会自动减少子进程数。因此，可根据服务器的负载来调整这个值。</div>
<div> </div>
<div>MaxClients是这些指令中最为重要的一个，设定的是 Apache可以同时处理的请求，是对Apache性能影响最大的参数。其缺省值150是远远不够的，如果请求总数已达到这个值（可通过ps -ef|grep http|wc -l来确认），那么后面的请求就要排队，直到某个已处理请求完毕。这就是系统资源还剩下很多而HTTP访问却很慢的主要原因。虽然理论上这个值越大，可以 处理的请求就越多，但Apache默认的限制不能大于256。ServerLimit指令无须重编译Apache就可以加大MaxClients。</div>
<blockquote>
<div>&lt;IfModule prefork.c&gt;</div>
<div>ServerLimit  10000<br />
StartServers 5<br />
MinSpareServers 5<br />
MaxSpareServers 10<br />
MaxClients 10000<br />
MaxRequestsPerChild 0<br />
&lt;/IfModule&gt;</div>
</blockquote>
<div> </div>
<div><strong><a href="http://ourapache.com/archives/tag/worker" class="st_tag internal_tag" rel="tag" title="标签 worker 下的日志">Worker</a></strong></div>
<p><strong></strong></p>
<div>
相对于prefork，worker全新的支持多线程和多进程混合模型的MPM。由于使用线程来处理，所以可以处理相对海量的请求，而系统资源的开销要小于 基于进程的服务器。但是，worker也使用了多进程，每个进程又生成多个线程，以获得基于进程服务器的稳定性。在configure –with-mpm=worker后，进行make编译、make install安装。在缺省生成的httpd-mpm.conf中有以下默认配置段：</div>
<blockquote>
<div>&lt;IfModule worker.c&gt;<br />
StartServers 2<br />
MaxClients 150<br />
MinSpareThreads 25<br />
MaxSpareThreads 75<br />
ThreadsPerChild 25<br />
MaxRequestsPerChild 0<br />
&lt;/IfModule&gt;</div>
</blockquote>
<div>Worker 由主控制进程生成“StartServers”个子进程，每个子进程中包含固定的ThreadsPerChild线程数，各个线程独立地处理请求。同样，为了不在请求到来时再生成线程，MinSpareThreads和MaxSpareThreads设置了最少和最多的空闲线程数；而MaxClients 设置了同时连入的clients最大总数。如果现有子进程中的线程总数不能满足负载，控制进程将派生新的子进程。</div>
<div>MinSpareThreads和 MaxSpareThreads的最大缺省值分别是75和250。这两个参数对Apache的性能影响并不大，可以按照实际情况相应调节。 ThreadsPerChild是worker MPM中与性能相关最密切的指令。</div>
<div>ThreadsPerChild的最大缺省值是64，如果负载较大，64也是不够的。这时要显式使用 ThreadLimit指令，它的最大缺省值是20000。</div>
<div>Worker模式下所能同时处理的请求总数是由子进程总数乘以ThreadsPerChild 值决定的，应该大于等于MaxClients。如果负载很大，现有的子进程数不能满足时，控制进程会派生新的子进程。默认最大的子进程总数是16，加大时 也需要显式声明ServerLimit（最大值是20000）。需要注意的是，如果显式声明了ServerLimit，那么它乘以 ThreadsPerChild的值必须大于等于MaxClients，而且MaxClients必须是ThreadsPerChild的整数倍，否则 Apache将会自动调节到一个相应值。</div>
<blockquote>
<div>&lt;IfModule worker.c&gt;<br />
ServerLimit 25<br />
ThreadLimit 200<br />
StartServers 3<br />
MaxClients 2000<br />
MinSpareThreads 50<br />
MaxSpareThreads 200<br />
ThreadsPerChild 100<br />
MaxRequestsPerChild 0<br />
&lt;/IfModule&gt;</div>
</blockquote>
<div>下面是利用Apache自带的测试工具ab对Server进行测试的情况(设定请求的index页面为6bytes),cpu%为cpu占用率，mem为内存使用量(M为单位)，RequestsPerSecond为每秒处理的请求数。</div>
<div>1、Prefor方式<br />
  <span style="color: #0000ff;">(ServerLimit,StartServer,MinSpareServers,MaxSpareServers,MaxClients,MaxRequestPerChild)</span>            </div>
<table border="1" cellspacing="0">
<tbody>
<tr>
<td colspan="4" width="357" height="18">
<table style="width: 255px; height: 450px;" border="1" cellspacing="1" cellpadding="1" width="255">
<tbody>
<tr>
<td><span style="color: #000000;">-n/-c(ab参数)</span></td>
<td>Cpu%</td>
<td>Mem</td>
<td>
<div>Requestspersecond</div>
</td>
</tr>
<tr>
<td colspan="4"><span style="color: #0000ff;">(－,5,5,10,150,0)</span></td>
</tr>
<tr>
<td>100000/100</td>
<td>28.8</td>
<td>285</td>
<td>8434</td>
</tr>
<tr>
<td>100000/200</td>
<td>29.2</td>
<td>304</td>
<td>8032</td>
</tr>
<tr>
<td>100000/500</td>
<td>25.3</td>
<td>323</td>
<td>7348</td>
</tr>
<tr>
<td>100000/1000</td>
<td>24.4</td>
<td>330</td>
<td>5886</td>
</tr>
<tr>
<td colspan="4"><span style="color: #0000ff;">(10000,5,5,10,500,0)</span></td>
</tr>
<tr>
<td>100000/100</td>
<td>28.7</td>
<td>371</td>
<td>8345</td>
</tr>
<tr>
<td>100000/200</td>
<td>27.4</td>
<td>389</td>
<td>7929</td>
</tr>
<tr>
<td>100000/500</td>
<td>24.9</td>
<td>417</td>
<td>7229</td>
</tr>
<tr>
<td>100000/1000</td>
<td>23.4</td>
<td>437</td>
<td>6676</td>
</tr>
<tr>
<td colspan="4"><span style="color: #0000ff;">(10000,5,5,10,1000,0)</span></td>
</tr>
<tr>
<td>100000/100</td>
<td>28.8</td>
<td>408</td>
<td>8517</td>
</tr>
<tr>
<td>100000/200</td>
<td>27.0</td>
<td>422</td>
<td>8045</td>
</tr>
<tr>
<td>100000/500</td>
<td>24.2</td>
<td>455</td>
<td>7236</td>
</tr>
<tr>
<td>100000/1000</td>
<td>22.5</td>
<td>470</td>
<td>6570</td>
</tr>
<tr>
<td colspan="4"><span style="color: #0000ff;">(10000,5,5,10,1500,0)</span></td>
</tr>
<tr>
<td>100000/100</td>
<td>29.6</td>
<td>330</td>
<td>8407</td>
</tr>
<tr>
<td>100000/200</td>
<td>28.1</td>
<td>349</td>
<td>8014</td>
</tr>
<tr>
<td>100000/500</td>
<td>26.4</td>
<td>380</td>
<td>7290</td>
</tr>
<tr>
<td>100000/1000</td>
<td>24.0</td>
<td>400</td>
<td>6686</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<div>2、Worker方式<br />
(<span style="color: #0000ff;">ServerLimt,Threadlimt,Startservers,MaxClients,MinspareThread,MaxspareThread,ThreadperChild,MaxRequestPerChild)</span><br />
                   </div>
<table style="width: 281px; height: 422px;" border="1" cellspacing="1" cellpadding="1" width="281">
<tbody>
<tr>
<td>-n/-c(ab参数)</td>
<td>cpu%</td>
<td>mem</td>
<td>RequestsperSecond</td>
</tr>
<tr>
<td colspan="4"><span style="color: #0000ff;">(50,500,5,10000,50,200,200,0)</span></td>
</tr>
<tr>
<td>100000/100 </td>
<td>18.6</td>
<td>188</td>
<td>6020</td>
</tr>
<tr>
<td>100000/200</td>
<td>20.1</td>
<td>195</td>
<td>5892</td>
</tr>
<tr>
<td>100000/500</td>
<td>19.8</td>
<td>209</td>
<td>5708</td>
</tr>
<tr>
<td>100000/1000</td>
<td>22.2</td>
<td>218</td>
<td>6081</td>
</tr>
<tr>
<td colspan="4"><span style="color: #0000ff;">(100,500,5,10000,50,200,100,0)</span></td>
</tr>
<tr>
<td>100000/100 </td>
<td>24.5</td>
<td>240</td>
<td>6919</td>
</tr>
<tr>
<td>100000/200</td>
<td>23.6</td>
<td>247</td>
<td>6798</td>
</tr>
<tr>
<td>100000/500</td>
<td>24.6</td>
<td>254</td>
<td>6827</td>
</tr>
<tr>
<td>100000/1000</td>
<td>22.3</td>
<td>271</td>
<td>6114</td>
</tr>
<tr>
<td colspan="4"><span style="color: #0000ff;">(200,500,5,10000,50,200,50,0)</span></td>
</tr>
<tr>
<td>100000/100 </td>
<td>27.3</td>
<td>301</td>
<td>7781</td>
</tr>
<tr>
<td>100000/200</td>
<td>27.4</td>
<td>307</td>
<td>7789</td>
</tr>
<tr>
<td>100000/500</td>
<td>26.0</td>
<td>320</td>
<td>7141</td>
</tr>
<tr>
<td>100000/1000</td>
<td>21.8</td>
<td>344</td>
<td>6110</td>
</tr>
</tbody>
</table>
<div>相对来说，prefork方式速度要稍高于worker，然而它需要的cpu和memory资源也稍多于woker。</div>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年08月16号 -- <a href="http://ourapache.com/archives/288" title="Apache两种常用工作模式比较:prefork和worker">Apache两种常用工作模式比较:prefork和worker</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/234" title="Apache的prefork模式和worker模式">Apache的prefork模式和worker模式</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/222" title="Apache 2.0中prefork.c模块和worker.c模块的比较">Apache 2.0中prefork.c模块和worker.c模块的比较</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/229" title="对Apache中并发控制参数prefork理解和调优">对Apache中并发控制参数prefork理解和调优</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/64" title="Apache连接数设置prefork">Apache连接数设置prefork</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/62" title="对apache中并发控制参数prefork理解和调优">对apache中并发控制参数prefork理解和调优</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/prefork" title="prefork" rel="tag">prefork</a>, <a href="http://ourapache.com/archives/tag/worker" title="worker" rel="tag">worker</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/232/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>通过SNMP协议来监视Apache服务器</title>
		<link>http://ourapache.com/archives/227</link>
		<comments>http://ourapache.com/archives/227#comments</comments>
		<pubDate>Mon, 09 Mar 2009 06:45:52 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[SNMP]]></category>
		<category><![CDATA[日志]]></category>
		<category><![CDATA[监视]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=227</guid>
		<description><![CDATA[    SNMP 是简单网管协议，支持SNMP的服务器或网络设备可以被OpenView、Tivoli等网管软件统一管理，目前有很多开源的SNMP模块可以加装到 Apache网站服务器之上，对于Apache 1.3版来讲，mod_snmp模块可以支持第1版和2版的SNMP协议；对于Apache 2版来讲，mod_apache_snmp模块可以编译成Apache的DSO直接支持第1版、第2版和第3版的SNMP协议。有了SNMP模块，外部网管软件就可以对Apache网站服务器的各种实时性能参数进行查看了，这些参数包含“服务器连续在线时间、平均负载、一段时间内的错误数、提供网站服务的字节数和连接请求数”。SNMP模块遇到突然激增的并发连接请求数时会向控制台报警。管理SNMP资源的开源工具软件有：“net-snmp, OpenNMS,Najios等”。]]></description>
			<content:encoded><![CDATA[<p>    <a href="http://ourapache.com/archives/tag/snmp" class="st_tag internal_tag" rel="tag" title="标签 SNMP 下的日志">SNMP</a> 是简单网管协议，支持SNMP的服务器或网络设备可以被OpenView、Tivoli等网管软件统一管理，目前有很多开源的SNMP模块可以加装到 Apache网站服务器之上，对于Apache 1.3版来讲，mod_snmp模块可以支持第1版和2版的SNMP协议；对于Apache 2版来讲，mod_apache_snmp模块可以编译成Apache的DSO直接支持第1版、第2版和第3版的SNMP协议。有了SNMP模块，外部网管软件就可以对Apache网站服务器的各种实时性能参数进行查看了，这些参数包含“服务器连续在线时间、平均负载、一段时间内的错误数、提供网站服务的字节数和连接请求数”。SNMP模块遇到突然激增的并发连接请求数时会向控制台报警。管理SNMP资源的开源工具软件有：“net-<a href="http://ourapache.com/archives/tag/snmp" class="st_tag internal_tag" rel="tag" title="标签 SNMP 下的日志">snmp</a>, OpenNMS,Najios等”。</p>
<p><strong>用开源工具分析日志</strong></p>
<p>    有很多开源和商业版的工具软件可以对产生的Apache日志文件做分析和处理，通常的步骤是：<br />
1.选取一个日志文件。<br />
2.分析日志文件内容。<br />
3.生成包含不同类别内容的统计信息网页输出。</p>
<p>    Webalizer(<a onclick="pageTracker._trackPageview('/outbound/article/www.mrunix.net');" href="http://www.mrunix.net/webalizer/">http://www.mrunix.net/webalizer/</a>)和AWStats(<a onclick="pageTracker._trackPageview('/outbound/article/awstats.sf.net');" href="http://awstats.sf.net/">http://awstats.sf.net</a>)是较为流行的日志文件分析工具；还有一些工具可以记录来访者具体访问路线，比如Vistors和Pathalizer工具，可以分别从<a onclick="pageTracker._trackPageview('/outbound/article/www.hping.org');" href="http://www.hping.org/visitors/">http://www.hping.org/visitors/</a>和<a onclick="pageTracker._trackPageview('/outbound/article/pathalizer.bzzt.net');" href="http://pathalizer.bzzt.net/">http://pathalizer.bzzt.net/</a>下载。</p>
<p><strong>实时监视日志</strong></p>
<p>    使用apachetop命令行工具来显示apache服务器当前的运行状态，类似于Unix等系统下的top命令工具。对流量比较低的Unix- Apache网站也可以使用tail命令来记录实时日志信息，tail -f /logfile/。通过扫描错误日志文件中的记录，分析出恶意连接请求，常用的错误日志文件扫描工具有Logscan和ScanErrLog，可以分别从<a onclick="pageTracker._trackPageview('/outbound/article/www.garand.net');" href="http://www.garand.net/security.php">http://www.garand.net/security.php</a>和<a onclick="pageTracker._trackPageview('/outbound/article/www.librelogiciel.com');" href="http://www.librelogiciel.com/software/">http://www.librelogiciel.com/software/</a>去下载这些工具。</p>
<p><strong>将连接请求日志记录到数据库</strong></p>
<p>    Apache 本身没有将记录转发到数据库的功能，必须要第三方脚本和模块来支持。这里列举几个：mod_log_sql模块允许将连接请求直接记入MySQL数据库，然后用Apache LogView SQL工具来参看库中的记录；pglogd工具可以记录日志到PostgreSQL数据库中。</p>
<p><strong>将日志文件转存和归档</strong><br />
CustomLog “|bin/rotatelogs /var/logs/apachelog<br />
86400″ common</p>
<p>    如果网站流量较高，日志文件很容易就会变得很大，需要进行转存和归档处理。转存日志文件时需要压缩和保存，在线进行这项工作可以使用Apache提供的rotatelogs来完成，类似工具还可以在<a onclick="pageTracker._trackPageview('/outbound/article/cronolog.org');" href="http://cronolog.org/">http://cronolog.org/</a>上找到。例子中用rotatelogs工具将每天的日志做了转存和归档处理，一天共有86400秒。查看Apache帮助文件可以了解更多的rotatelogs工具参数。注意如果rotatelogs工具所在的目录名含有空格，则需要用跳转符号\来指定。</p>
<p><strong>IP地址和域名之间对应处理</strong></p>
<p>    将HostNameLookups 设置成on，那么日志记录中将显示来访者所在的域名，设置成on可降低服务器性能。为了解决这一问题，Apache提供了一个事后分析IP地址域名信息的工具logresolve，例如$ logresolve &lt; access_log &gt; resolved_log</p>
<p>    如果用代理服务器或网关设备来完成的网站访问，Apache服务器将只能记录到代理服务器和网关的IP地址和域名。</p>
<p>如何自动启动Apache服务器</p>
<blockquote><p>#!/bin/bash<br />
if [ 'ps -waux | grep -v grep | grep -c httpd' -lt 1<br />
]; then apachectl restart; fi</p></blockquote>
<p>    在windows 平台下以服务方式启动的Aapche遇到意外退出后可以由服务管理器自动自动，Unix平台下需要借助watchdog脚本来实现自动启动功能， watchdog程序专门用来监视其他程序的运行状态，发现被监视的程序退出或停止后可以重新将他们启动。例子中简单的linux脚本将监视系统的进程表，如果网站服务器httpd进程消失，则负责将它重新启动，使用该脚本的条件有2个，首先保证该脚本文件具备可执行权限，第二必须将该文件设置到 cron文件中，使之可以在预定的时间间隔内运行，如果使用Solaris系统，需要将例子中的ps -waux改成ps -ef。用户可以访问<a onclick="pageTracker._trackPageview('/outbound/article/perl.apache.org');" href="http://perl.apache.org/docs/general/control/control.html">http://perl.apache.org/docs/general/control/control.html</a>网页发现更多高级的watchdog类脚本工具，大多数linux发行版自带一些用于Apache的脚本工具。</p>
<p><strong>日志文件的分割和合并</strong></p>
<p>    如果用户的网站环境是用服务器集群来搭建的，通常需要将所有服务器上的日志做合并成单个文件后，才可以进行分析和处理。相似的道理，如果在单台服务器上运行多个虚拟网站，则需要将单个日志文件分割成多个部分供不同的虚拟网站用户去分析。在Apache服务器源码的support/文件夹下可以找到相应的脚本工具split-logfile等。在<a onclick="pageTracker._trackPageview('/outbound/article/www.coker.com.au');" href="http://www.coker.com.au/logtools/">http://www.coker.com.au/logtools/</a>网页可以找到一些其他的日志工具。比如vlogger工具就可以替代cronologs来对单个服务器上的虚拟网站日志进行分别处理，该工具在<a onclick="pageTracker._trackPageview('/outbound/article/n0rp.chemlab.org');" href="http://n0rp.chemlab.org/vlogger/">http://n0rp.chemlab.org/vlogger/</a>下载。</p>
<p>为虚拟网站保存独立的日志文件</p>
<blockquote><p>&lt;virtualhost&gt;<br />
  ServerName vhost1.21nw.com<br />
  CustomLog logs/vhost1.21nw.com_log combined<br />
  ErrorLog logs/vhost2.21nw.com_log<br />
  …….<br />
&lt;/virtual host&gt;</p></blockquote>
<p>    使用CustomLog标志段在Apache配置文件的&lt;Virtualhost&gt;区块内实现虚拟网站日志文件的独立处理。</p>
<blockquote><p>LogFormat “%v %h %l %u %t \”%r\” %&gt;s %b” common_virtualhost<br />
CustomLog logs/access_log common_virtualhost</p></blockquote>
<p>    在Apache全局配置中配置方法，其中的v%负责把提供服务的虚拟网站记录下来，对于配置了很多虚拟网站的单台服务器来说，这种配置不错。如果不想记录虚拟服务器的日志只需要在配置文件中加入”CustomLog /dev/null”就可以了。</p>
<p><strong>日志文件中常见的条目</strong></p>
<p>缺少favicon.ico文件，该文件可在浏览器的标题栏显示网站的个性图案；<br />
缺少robots.txt文件，利于站点复制工具和搜索引擎使用；<br />
覆写httpd.pid文件，网站服务器不正常退出后遗留的PID记录文件；<br />
陌生的长记录条，</p>
<blockquote><p>“SEARCH /\x90\x02\xb1\x02\xb1\x02\xb1\x02 …”<br />
“GET /scripts/..%252f../winnt/system32/cmd.exe?/<br />
  c+dir HTTP/1.0…”<br />
“GET /default.ida?NNNNNNN NNNNNNNNNNNNNNNNNN …”</p></blockquote>
<p>    类似的记录条表示访问者请求了网站上根本没有的cmd.exe，root.exe或dir等文件。<br />
日志文件中的一些条目经常反映了那些自动探测网站服务器漏洞的动作，多数来源于针对IIS网站服务器的蠕虫和恶意程序。有时候也会发现一些针对Apache的漏洞，所以为了保证Apache的正常运行，用户应保持经常更新Apache软件。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年06月1号 -- <a href="http://ourapache.com/archives/243" title="玩转apache之日志">玩转apache之日志</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/224" title="监视并记录Apache网站服务器的运行">监视并记录Apache网站服务器的运行</a></li><li>2009年02月26号 -- <a href="http://ourapache.com/archives/184" title="Apache日志文件（配置和管理）">Apache日志文件（配置和管理）</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/176" title="网站服务器(Apache)的日志与监视">网站服务器(Apache)的日志与监视</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/172" title="查询并禁止apache中异常访问量的用户">查询并禁止apache中异常访问量的用户</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/117" title="让Apache按日期保存日志数据">让Apache按日期保存日志数据</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/snmp" title="SNMP" rel="tag">SNMP</a>, <a href="http://ourapache.com/archives/tag/%e6%97%a5%e5%bf%97" title="日志" rel="tag">日志</a>, <a href="http://ourapache.com/archives/tag/%e7%9b%91%e8%a7%86" title="监视" rel="tag">监视</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/227/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>监视并记录Apache网站服务器的运行</title>
		<link>http://ourapache.com/archives/224</link>
		<comments>http://ourapache.com/archives/224#comments</comments>
		<pubDate>Mon, 09 Mar 2009 06:25:29 +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=224</guid>
		<description><![CDATA[Apache提供了广泛记录运行时各方面信息的工具。比如有条件性的记录日志，日志循环，确定IP地址等时普遍会遇到的问题。还讲解很多用于检测您的Apache服务器状态以及分析其日志的捆绑的第三方模块和工具。]]></description>
			<content:encoded><![CDATA[<p> Apache提供了广泛记录运行时各方面信息的工具。比如有条件性的记录日志，日志循环，确定IP地址等时普遍会遇到的问题。还讲解很多用于检测您的Apache服务器状态以及分析其日志的捆绑的第三方模块和工具。</p>
<p>默认的Apache日志文件</p>
<p>    Apache提供很多检测和日志工具来追踪服务器的正确运行。默认的Apache配置提供两个日志文件，放置在安装目录下的日志目录里面。</p>
<p>access_log 这个文件（在windows下对应access.log文件）包含了服务器已经处理过的请求的信息，比如说请求的URL，客户端的IP地址，请求是否被成功完成等。error_log 这个文件（在windows下对应error.log文件）包含了与错误情况相关的信息，以及服务器生命周期中不同的大事件。</p>
<p>创建日志格式</p>
<blockquote><p>LogFormat “%h %l %u %t “%r” %&gt;s %b” common<br />
LogFormat “%h %l %u %t “%r” %&gt;s %b”    “%{Referer}i” “%{User-agent}i”” combined</p></blockquote>
<p>    LogFormat 指令允许你告诉Apache你想要记录请求的哪些方面。而你仍需附加的指令来告诉Apache在哪里记录那些信息，这在下一章中将会介绍。下面的例子显示了两种最受欢迎的格式的配置：普通日志格式和整合日志格式。当Apache收到一个请求，他将会用相应的请求属性来替代以%为前缀的每一个域。如果您正在使用普通日志格式，您的日志文件里的每一项输入看起来都将是这样的：</p>
<blockquote><p>192.168.200.4 &#8211; someuser [12/Jun/2005:08:33:34    +0500] “GET /example.png HTTP/1.0″ 200 1234</p></blockquote>
<p>    如果您正在使用整合日志格式，您的日志文件里的每一项输入看起来则都将是这样的：</p>
<blockquote><p>192.168.200.4 &#8211; someuser [12/Jun/2005:08:33:34     +0500] “GET /example.png HTTP/1.0″ 200 1234<br />
    <a onclick="pageTracker._trackPageview('/outbound/article/www.example.com');" href="http://www.example.com/index.html">http://www.21nw.com/index.html</a> “Mozilla/5.0    (Windows; U; Windows NT 5.1; en-US; rv:1.7.7)”</p></blockquote>
<p>    尽管有附件提供日志格式的详尽索引，下表描述了一些最为重要的域：</p>
<blockquote><p># %h: 客户端（例如，浏览器）向服务器发出连接请求时自己的当时的IP地址或域名(需开启HostNameLookups)。<br />
# %u: 使用HTTP方式认证用户时，记录下的用户的编号。<br />
# %t: 服务器接受到连接请求的时间。<br />
# %r: 客户端发出的原始连接请求中的文本信息，包含所使用的HTTP方法。<br />
# %&gt;s: 服务器应答浏览器后的返回状态代码，200表示请求成功。.<br />
# %b: 服务器应答浏览器发出的单个请求的回传对象的内容大小（字节为单位），不统计数据包头部字节。<br />
整合日志格式在普通日志格式的基础上扩展出了两个附加的域。定义为：<br />
# %{Referer}i: 连接请求数据包包头，包含指向当前页面的文档关联信息。<br />
# %{User-agent}i: 用户代理连接请求数据包包头，包含客户浏览器的信息。</p></blockquote>
<p>创建一个自定义日志文件</p>
<blockquote><p>CustomLog logs/access_log common<br />
TransferLog logs/sample.log</p></blockquote>
<p>    您可能会想创建Apache自带以外的新的日志文件。下面的例子将运用CustomLog来创建一个新的日志文件，并保存由一个之前定义好的日志格式，即前一章提到的common，所定义的信息。您还可以用格式本身的定义来替换昵称。一个附加的，更为简单的指令是Transferlog，它只接受最后一个 LogFormat指令提供的定义。</p>
<p>重导向日志到一个外部的程序</p>
<blockquote><p>TransferLog “|bin/rotatelogs /var/logs/apachelog 86400″</p></blockquote>
<p>    你也可以用CustomLog或TransferLog将日志的输出重导向（输出）到一个外部的程序，而不是一个文件。要做到这一点，首先您需要以输出字符 “|”开头，跟着是接收日志标准输入信息的程序之路经。本例运用Apache自带的rotatelogs程序，在稍后的章节中会对其有所介绍。</p>
<p>    当有一个外部程序被使用，它将作为启动httpd的用户被运行。如果服务器是被超级管理员所启动，它就会是超级管理员，完全确保这个程序是安全的。并且，当进入一个非Unix平台上的一个文件路径时，需要小心确保只有正斜杠被使用，即使这个平台可能是允许使用反斜杠的。总的来说，在整个配置文件中总是使用正斜杠是个好主意。</p>
<p>有条件的日志请求</p>
<blockquote><p>SetEnvIf Request_URI “(.gif|.jpg)$” image<br />
CustomLog logs/access_log common env=!image<br />
SetEnvIf Remote_Addr 192.168.200.5 specialmachine<br />
CustomLog logs/special_access_log common env=specialmachine</p></blockquote>
<p>    你可以根据可变的环境决定是否记录一个请求。这种可变可以根据许多参数，比如客户端的IP地址或请求中某个头部的存在，事先设置好。正如本例中所显示， CustomLog指令可以将可变的环境作为第三个参数来接受。如果存在可变的环境，它就将被记录，否则就不会。如果这个可变的环境被一个”!”开头否定，那么不存在可变的环境将会被记录。本例将告诉您如何避免在日志里以GIF和JPEG的格式记录图像，及如何从一个特定的IP地址记录请求道一个单独的日志文件。另一个例子请参加下一节。</p>
<p>谁在连接你的网站</p>
<blockquote><p>SetEnvIfNoCase Referer www.21nw.com internalreferral<br />
LogFormat “%{Referer}i -&gt; %U” referer<br />
CustomLog logs/referer.log referer env=!internalreferral</p></blockquote>
<p>    可以通过记录Referer的值来检测哪些人连接了你的网站，Referer变量位于用户发送连接请求数据包的头部，数据包头中还包含了用户访问的目的网站的URL地址。通过这种方法可以记录下绝大部分网站访问者。也可以把来自特定网站(<a href="http://www.21nw.com">www.21nw.com</a>)地址段的来访者排除出日志记录文件。</p>
<p>利用模块参数(mod_status)来监视Apache服务器</p>
<blockquote><p>&lt;location /server-status&gt;<br />
  SetHandler server-status<br />
  Order Deny,Allow<br />
  Deny from all<br />
  Allow from 192.168.0<br />
&lt;/location&gt;</p></blockquote>
<p>    Apache 服务器中可以使用的功能模块很多，有服务器内置的也有外挂的，这些模块工作的状态和性能就是通过mod_status参数来记录的，记录的内容有“哪些模块参与了网站应答服务、哪些模块处于空闲状态、服务器的开启/关闭时间。正在处理的连接请求数和访问者数量(需要指定ExtendedStatus记号) -该模块记录对高负荷网站服务器性能有很大影响”。例子中记录的模块状态统计结果可以用浏览器访问<a onclick="pageTracker._trackPageview('/outbound/article/www.example.com');" href="http://www.example.com/server-status">http://www.21nw.com/server-status</a>页面来查看。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年06月1号 -- <a href="http://ourapache.com/archives/243" title="玩转apache之日志">玩转apache之日志</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/227" title="通过SNMP协议来监视Apache服务器">通过SNMP协议来监视Apache服务器</a></li><li>2009年02月26号 -- <a href="http://ourapache.com/archives/184" title="Apache日志文件（配置和管理）">Apache日志文件（配置和管理）</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/176" title="网站服务器(Apache)的日志与监视">网站服务器(Apache)的日志与监视</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/172" title="查询并禁止apache中异常访问量的用户">查询并禁止apache中异常访问量的用户</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/117" title="让Apache按日期保存日志数据">让Apache按日期保存日志数据</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/%e6%97%a5%e5%bf%97" title="日志" rel="tag">日志</a>, <a href="http://ourapache.com/archives/tag/%e7%9b%91%e8%a7%86%e6%97%a5%e5%bf%97" title="监视日志" rel="tag">监视日志</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/224/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache 2.0中prefork.c模块和worker.c模块的比较</title>
		<link>http://ourapache.com/archives/222</link>
		<comments>http://ourapache.com/archives/222#comments</comments>
		<pubDate>Mon, 09 Mar 2009 06:16:58 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[prefork]]></category>
		<category><![CDATA[worker]]></category>
		<category><![CDATA[模块]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=222</guid>
		<description><![CDATA[Apache 2.0中prefork.c模块和worker.c模块的比较]]></description>
			<content:encoded><![CDATA[<p>空闲子进程：是指没有正在处理请求的子进程。</p>
<p><span style="color: #0000ff;"><strong><a href="http://ourapache.com/archives/tag/prefork" class="st_tag internal_tag" rel="tag" title="标签 prefork 下的日志">prefork</a>.c模块(一个非线程型的、预派生的MPM)</strong></span><br />
prefork MPM 使用多个子进程，每个子进程只有一个线程。每个进程在某个确定的时间只能维持一个连接。在大多数平台上，Prefork MPM在效率上要比Worker MPM要高，但是内存使用大得多。prefork的无线程设计在某些情况下将比worker更有优势：它可以使用那些没有处理好线程安全的第三方模块，并且对于那些线程调试困难的平台而言，它也更容易调试一些。</p>
<p>ServerLimit 20000<br />
StartServers 5<br />
MinSpareServers 5<br />
MaxSpareServers 10<br />
MaxClients 1000<br />
MaxRequestsPerChild 0</p>
<p><span style="color: #ff0000;">perfork模块最大并发数为 MaxClients = 1000</span></p>
<p>ServerLimit 2000<br />
//默认的MaxClient最大是256个线程,如果想设置更大的值，就的加上ServerLimit这个参数。20000是ServerLimit这个参数的最大值。如果需要更大，则必须编译apache,此前都是不需要重新编译Apache。<br />
生效前提：必须放在其他指令的前面</p>
<p>StartServers 5<br />
//指定服务器启动时建立的子进程数量，prefork默认为5。</p>
<p>MinSpareServers 5<br />
//指定空闲子进程的最小数量，默认为5。如果当前空闲子进程数少于MinSpareServers ，那么Apache将以最大每秒一个的速度产生新的子进程。此参数不要设的太大。</p>
<p>MaxSpareServers 10<br />
//设置空闲子进程的最大数量，默认为10。如果当前有超过MaxSpareServers数量的空闲子进程，那么父进程将杀死多余的子进程。此参数不要设的太大。如果你将该指令的值设置为比MinSpareServers小，Apache将会自动将其修改成”MinSpareServers+1″。</p>
<p>MaxClients 256<br />
//限定同一时间客户端最大接入请求的数量(单个进程并发线程数)，默认为256。任何超过MaxClients限制的请求都将进入等候队列,一旦一个链接被释放，队列中的请求将得到服务。要增大这个值，你必须同时增大ServerLimit （与MaxClient相同）。</p>
<p>MaxRequestsPerChild 10000<br />
//每个子进程在其生存期内允许伺服的最大请求数量，默认为10000.到达MaxRequestsPerChild的限制后，子进程将会结束。如果MaxRequestsPerChild为”0″，子进程将永远不会结束。</p>
<p><span style="color: #0000ff;">将MaxRequestsPerChild设置成非零值有两个好处：</span><br />
1.可以防止(偶然的)内存泄漏无限进行，从而耗尽内存。<br />
2.给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。</p>
<p><span style="color: #0000ff;">工作方式：</span><br />
一个单独的控制进程(父进程)负责产生子进程，这些子进程用于监听请求并作出应答。Apache总是试图保持一些备用的(spare)或者是空闲的子进程用于迎接即将到来的请求。这样客户端就不需要在得到服务前等候子进程的产生。在Unix系统中，父进程通常以root身份运行以便邦定80端口，而 Apache产生的子进程通常以一个低特权的用户运行。User和Group指令用于设置子进程的低特权用户。运行子进程的用户必须要对它所服务的内容有读取的权限，但是对服务内容之外的其他资源必须拥有尽可能少的权限。</p>
<p><span style="color: #0000ff;"><strong><a href="http://ourapache.com/archives/tag/worker" class="st_tag internal_tag" rel="tag" title="标签 worker 下的日志">worker</a>.c模块(支持混合的多线程多进程的多路处理模块)</strong></span><br />
worker MPM 使用多个子进程，每个子进程有多个线程。每个线程在某个确定的时间只能维持一个连接。通常来说，在一个高流量的HTTP服务器上，Worker MPM是个比较好的选择，因为Worker MPM的内存使用比Prefork MPM要低得多。但worker MPM也由不完善的地方，如果一个线程崩溃，整个进程就会连同其所有线程一起”死掉”.由于线程共享内存空间，所以一个程序在运行时必须被系统识别为”每个线程都是安全的”。</p>
<p>ServerLimit 50<br />
ThreadLimit 200<br />
StartServers 5<br />
MaxClients 5000<br />
MinSpareThreads 25<br />
MaxSpareThreads 500<br />
ThreadsPerChild 100<br />
MaxRequestsPerChild 0</p>
<p><span style="color: #ff0000;">公式：<br />
ThreadLimit &gt;= ThreadsPerChild<br />
MaxClients &lt;= ServerLimit * ThreadsPerChild 必须是ThreadsPerChild的倍数<br />
MaxSpareThreads &gt;= MinSpareThreads+ThreadsPerChild</span></p>
<p><span style="color: #ff0000;">worker模块最大并发数为 MaxClients = 5000</span></p>
<p>ServerLimit 16<br />
//服务器允许配置的进程数上限。这个指令和ThreadLimit结合使用设置了MaxClients最大允许配置的数值。任何在重启期间对这个指令的改变都将被忽略，但对MaxClients的修改却会生效。</p>
<p>ThreadLimit 64<br />
//每个子进程可配置的线程数上限。这个指令设置了每个子进程可配置的线程数ThreadsPerChild上限。任何在重启期间对这个指令的改变都将被忽略，但对ThreadsPerChild的修改却会生效。默认值是”64″.</p>
<p>StartServers 3<br />
//服务器启动时建立的子进程数，默认值是”3″。</p>
<p>MinSpareThreads 75<br />
//最小空闲线程数,默认值是”75″。这个MPM将基于整个服务器监视空闲线程数。如果服务器中总的空闲线程数太少，子进程将产生新的空闲线程。</p>
<p>MaxSpareThreads 250<br />
//设置最大空闲线程数。默认值是”250″。这个MPM将基于整个服务器监视空闲线程数。如果服务器中总的空闲线程数太多，子进程将杀死多余的空闲线程。MaxSpareThreads的取值范围是有限制的。Apache将按照如下限制自动修正你设置的值：worker要求其大于等于 MinSpareThreads加上ThreadsPerChild的和</p>
<p>MaxClients 400<br />
//允许同时伺服的最大接入请求数量(最大线程数量)。任何超过MaxClients限制的请求都将进入等候队列。默认值是”400″ ,16(ServerLimit)乘以25(ThreadsPerChild)的结果。因此要增加MaxClients的时候，你必须同时增加 ServerLimit的值。</p>
<p>ThreadsPerChild 25<br />
//每个子进程建立的常驻的执行线程数。默认值是25。子进程在启动时建立这些线程后就不再建立新的线程了。</p>
<p>MaxRequestsPerChild 0<br />
//设置每个子进程在其生存期内允许伺服的最大请求数量。到达MaxRequestsPerChild的限制后，子进程将会结束。如果MaxRequestsPerChild为”0″，子进程将永远不会结束。</p>
<p><span style="color: #0000ff;">将MaxRequestsPerChild设置成非零值有两个好处：</span><br />
1.可以防止(偶然的)内存泄漏无限进行，从而耗尽内存。<br />
2.给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。<br />
注意<br />
对于KeepAlive链接，只有第一个请求会被计数。事实上，它改变了每个子进程限制最大链接数量的行为。</p>
<p><span style="color: #0000ff;">工作方式：</span><br />
每个进程可以拥有的线程数量是固定的。服务器会根据负载情况增加或减少进程数量。一个单独的控制进程(父进程)负责子进程的建立。每个子进程可以建立 ThreadsPerChild数量的服务线程和一个监听线程，该监听线程监听接入请求并将其传递给服务线程处理和应答。Apache总是试图维持一个备用(spare)或是空闲的服务线程池。这样，客户端无须等待新线程或新进程的建立即可得到处理。在Unix中，为了能够绑定80端口，父进程一般都是以 root身份启动，随后，Apache以较低权限的用户建立子进程和线程。User和Group指令用于设置Apache子进程的权限。虽然子进程必须对其提供的内容拥有读权限，但应该尽可能给予它较少的特权。另外，除非使用了suexec ，否则，这些指令设置的权限将被CGI脚本所继承。</p>
<p>硬限制：</p>
<p>ServerLimi和ThreadLimit这两个指令决定了活动子进程数量和每个子进程中线程数量的硬限制。要想改变这个硬限制必须完全停止服务器然后再启动服务器(直接重启是不行的)。</p>
<p>Apache在编译ServerLimit时内部有一个硬性的限制，你不能超越这个限制。<br />
prefork MPM最大为”ServerLimit 200000″<br />
其它MPM(包括work MPM)最大为”ServerLimit 20000</p>
<p>Apache在编译ThreadLimit时内部有一个硬性的限制，你不能超越这个限制。<br />
mpm_winnt是”ThreadLimit 15000″<br />
其它MPM(包括work prefork)为”ThreadLimit 20000</p>
<p>注意<br />
使用ServerLimit和ThreadLimit时要特别当心。如果将ServerLimit和ThreadLimit设置成一个高出实际需要许多的值，将会有过多的共享内存被分配。当设置成超过系统的处理能力，Apache可能无法启动，或者系统将变得不稳定。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年08月16号 -- <a href="http://ourapache.com/archives/288" title="Apache两种常用工作模式比较:prefork和worker">Apache两种常用工作模式比较:prefork和worker</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/234" title="Apache的prefork模式和worker模式">Apache的prefork模式和worker模式</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/232" title="Apache Prefork和Worker模式的性能比较测试">Apache Prefork和Worker模式的性能比较测试</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/229" title="对Apache中并发控制参数prefork理解和调优">对Apache中并发控制参数prefork理解和调优</a></li><li>2009年02月6号 -- <a href="http://ourapache.com/archives/76" title="Apache 模块说明">Apache 模块说明</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/64" title="Apache连接数设置prefork">Apache连接数设置prefork</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/62" title="对apache中并发控制参数prefork理解和调优">对apache中并发控制参数prefork理解和调优</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/prefork" title="prefork" rel="tag">prefork</a>, <a href="http://ourapache.com/archives/tag/worker" title="worker" rel="tag">worker</a>, <a href="http://ourapache.com/archives/tag/%e6%a8%a1%e5%9d%97" title="模块" rel="tag">模块</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/222/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache common-pool, common-dbcp源码解读与对象池原理剖析</title>
		<link>http://ourapache.com/archives/211</link>
		<comments>http://ourapache.com/archives/211#comments</comments>
		<pubDate>Fri, 27 Feb 2009 11:24:08 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[common-dbcp]]></category>
		<category><![CDATA[common-pool]]></category>
		<category><![CDATA[对象池]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=211</guid>
		<description><![CDATA[最近在做一个内部测试工具类的优化工作中接触到了连接池, 对象池技术, 将原有的未使用连接池的数据库访问操作改成连接池方式.性能有了非常大的提升, 事实证明, 经过两次改造, 原来一个比较大的测试类需要500多秒, 第一次优化后只需要300多秒, 第二次改用连接池之后同一个测试类只需要80多秒.下面是改造过程中的一些总结.
对象池就是以”空间换时间”的 一种常用缓存机制, 这里的”时间”特指创建时间,因此这也给出了对象池的适用范围:如果一种对象的创建过程非常耗时的话, 那么请使用对象池. 内部原理简单的说, 就是将创建的对象放到一个容器中, 用完之后不是销毁而是再放回该容器, 让其他的对象调用, 对象池中还涉及到一些高级的技术, 比如过期销毁, 被破坏时销毁, 对象数超过池大小销毁, 对象池中没有可用空闲对象时等待等等.]]></description>
			<content:encoded><![CDATA[<p><span>最近在做一个内部测试工具类的优化工作中接触到了连接池, 对象池技术, 将原有的未使用连接池的数据库访问操作改成连接池方式.性能有了非常大的提升, 事实证明, 经过两次改造, 原来一个比较大的测试类需要500多秒, 第一次优化后只需要300多秒, 第二次改用连接池之后同一个测试类只需要80多秒.下面是改造过程中的一些总结.<br />
对象池就是以”空间换时间”的 一种常用缓存机制, 这里的”时间”特指创建时间,因此这也给出了对象池的适用范围:如果一种对象的创建过程非常耗时的话, 那么请使用对象池. 内部原理简单的说, 就是将创建的对象放到一个容器中, 用完之后不是销毁而是再放回该容器, 让其他的对象调用, 对象池中还涉及到一些高级的技术, 比如过期销毁, 被破坏时销毁, 对象数超过池大小销毁, 对象池中没有可用空闲对象时等待等等.</span></p>
<p>apache的common-pool工具库是对池化技术原理的一种具体实现. 在阐述原来之前, 这里先理解几个概念:<br />
<strong><a href="http://ourapache.com/archives/tag/%e5%af%b9%e8%b1%a1%e6%b1%a0" class="st_tag internal_tag" rel="tag" title="标签 对象池 下的日志">对象池</a></strong>(ObjectPool接口): 可以把它认为是一种容器, 它是用来装池对象的, 并且包含了用来创建池对象的工厂对象<br />
<strong>池对象</strong>:就是要放到池容器中的对象, 理论上可以是任何对象.<br />
<strong>对象池工厂</strong>(ObjectPoolFactory接口):用来创建对象池的工厂, 这个没什么好说的.<br />
<strong>池对象工厂</strong>(PoolableObjectFactory 接口):用来创建池对象, 将不用的池对象进行钝化(passivateObject), 对要使用的池对象进行激活(activeObject), 对池对象进行验证(validateObject), 对有问题的池对象进行销毁(destroyObject)等工作</p>
<p>对象池中封装了创建, 获取, 归还, 销毁池对象的职责, 当然这些工作都是通过池对象工厂来实施的, 容器内部还有一个或多个用来盛池对象的容器.对象池会对容器大小, 存放时间, 访问等待时间, 空闲时间等等进行一些控制, 因为可以根据需要来调整这些设置.</p>
<p>当 需要拿一个池对象的时候, 就从容器中取出一个, 如果容器中没有的话, 而且又没有达到容器的最大限制, 那么就调用池对象工厂, 新建一个池对象, 并调用工厂的激活方法, 对创建的对象进行激活, 验证等一系列操作. 如果已经达到池容器的最大值, 而对象池中又经没有空闲的对象, 那么将会继续等待, 直到有新的空闲的对象被丢进来, 当然这个等待也是有限度的, 如果超出了这个限度, 对象池就会抛出异常.</p>
<p>“出来 混, 总是要还的”, 池对象也是如此, 当将用完的池对象归还到对象池中的时候, 对象池会调用池对象工厂对该池对象进行验证, 如果验证不通过则被认为是有问题的对象, 将会被销毁, 同样如果容器已经满了, 这个归还池对象将变的”无家可归”, 也会被销毁, 如果不属于上面两种情况, 对象池就会调用工厂对象将其钝化并放入容器中. 在整个过程中, 激活, 检查, 钝化处理都不是必须的, 因此我们在实现PoolableObjectFactory接口的时候, 一般不作处理, 给空实现即可, 所以诞生了BasePoolableObjectFactory.</p>
<p>当然你也可以将要已有的对象创建好, 然后通过addObject放到对象池中去, 以备后用.</p>
<p>为了确保对对象池的访问都是线程安全的, 所有对容器的操作都必须放在synchronized中.</p>
<p>在 apache的common-pool工具库中有5种对象池:GenericObjectPool和 GenericKeyedObjectPool, SoftReferenceObjectPool, StackObjectPool, StackKeyedObjectPool.<br />
五种对象池可分为两类, 一类是无key的:</p>
<p><span><img class="alignnone size-full wp-image-212" title="1" src="http://www.ourapache.com/wp-content/uploads/2009/02/1.gif" alt="1" width="673" height="557" /><br />
</span></p>
<p>另一类是有key的:</p>
<p><img class="alignnone size-full wp-image-213" title="2" src="http://www.ourapache.com/wp-content/uploads/2009/02/2.gif" alt="2" width="749" height="582" /></p>
<p>前面两种用CursorableLinkedList来做容器, SoftReferenceObjectPool用ArrayList做容器, 一次性创建所有池化对象, 并对容器中的对象进行了软引用(SoftReference)处理, 从而保证在内存充足的时候池对象不会轻易被jvm垃圾回收, 从而具有很强的缓存能力. 最后两种用Stack做容器. 不带key的对象池是对前面池技术原理的一种简单实现, 带key的相对复杂一些, 它会将池对象按照key来进行分类, 具有相同的key被划分到一组类别中, 因此有多少个key, 就会有多少个容器. 之所以需要带key的这种对象池, 是因为普通的对象池通过makeObject()方法创建的对象基本上都是一模一样的, 因为没法传递参数来对池对象进行定制. 因此四种池对象的区别主要体现在内部的容器的区别, Stack遵循”后进先出”的原则并能保证线程安全, CursorableLinkedList是一个内部用游标(cursor)来定位当前元素的双向链表, 是非线程安全的, 但是能满足对容器的并发修改.ArrayList是非线程安全的, 便利方便的容器.</p>
<p>使用对象池的一般步骤:创建一个池对象工厂, 将该工厂注入到对象池中, 当要取池对象, 调用borrowObject, 当要归还池对象时, 调用returnObject, 销毁池对象调用clear(), 如果要连池对象工厂也一起销毁, 则调用close().<br />
下面是一些时序图:<br />
borrowObject:</p>
<p><img class="alignnone size-full wp-image-214" title="3" src="http://www.ourapache.com/wp-content/uploads/2009/02/3.gif" alt="3" width="405" height="251" /></p>
<p>returnObject:</p>
<p><img class="alignnone size-full wp-image-215" title="4" src="http://www.ourapache.com/wp-content/uploads/2009/02/4.gif" alt="4" width="428" height="206" /></p>
<p>invalidateObject:</p>
<p><img class="alignnone size-full wp-image-217" title="51" src="http://www.ourapache.com/wp-content/uploads/2009/02/51.gif" alt="51" width="457" height="126" /></p>
<p>apache的连接池工具库common-dbcp是common-pool在数据库访问方面的一个具体应用.当对common-pool熟悉之后, 对common-dbcp就很好理解了. 它通过对已有的Connection, Statment对象包装成池对象PoolableConnection, PoolablePreparedStatement. 然后在这些池化的对象中, 持有一个对对象池的引用, 在关闭的时候, 不进行真正的关闭处理, 而是通过调用:<br />
<code>1. _pool.returnObject(this); </code><br />
或:<br />
<code>1. _pool.returnObject(_key,this); </code><br />
这样一句, 将连接对象放回连接池中.<br />
而对应的对象池前者采用的是ObjectPool, 后者是KeyedObjectPool, 因为一个数据库只对应一个连接, 而执行操作的Statement却根据Sql的不同会分很多种. 因此需要根据sql语句的不同多次进行缓存<br />
在对连接池的管理上, common-dbcp主要采用两种对象:<br />
一个是PoolingDriver, 另一个是PoolingDataSource, 二者的区别是PoolingDriver是一个更底层的操作类, 它持有一个连接池映射列表, 一般针对在一个jvm中要连接多个数据库, 而后者相对简单一些. 内部只能持有一个连接池, 即一个数据源对应一个连接池.<br />
下面是common-dbcp的结构关系:</p>
<p><span><img class="alignnone size-full wp-image-218" title="6" src="http://www.ourapache.com/wp-content/uploads/2009/02/6.gif" alt="6" width="912" height="547" /></span></p>
<p>下面是参考了common-dbcp的例子之后写的一个从连接池中获取连接的工具类</p>
<blockquote><p>1. /**<br />
2. * 创建连接<br />
3. *<br />
4. * @since 2009-1-22 下午02:58:35<br />
5. */<br />
6. public class ConnectionUtils {<br />
7. // 一些common-dbcp内部定义的protocol<br />
8. private static final String POOL_DRIVER_KEY = “jdbc:apache:commons:dbcp:”;<br />
9. private static final String POLLING_DRIVER = “org.apache.commons.dbcp.PoolingDriver”;<br />
10.<br />
11. /**<br />
12. * 取得池化驱动器<br />
13. *<br />
14. * @return<br />
15. * @throws ClassNotFoundException<br />
16. * @throws SQLException<br />
17. */<br />
18. private static PoolingDriver getPoolDriver() throws ClassNotFoundException,<br />
19. SQLException {<br />
20. Class.forName(POLLING_DRIVER);<br />
21. return (PoolingDriver) DriverManager.getDriver(POOL_DRIVER_KEY);<br />
22. }<br />
23.<br />
24. /**<br />
25. * 销毁所有连接<br />
26. *<br />
27. * @throws Exception<br />
28. */<br />
29. public static void destory() throws Exception {<br />
30. PoolingDriver driver = getPoolDriver();<br />
31. String[] names = driver.getPoolNames();<br />
32. for (String name : names) {<br />
33. driver.getConnectionPool(name).close();<br />
34. }<br />
35. }<br />
36.<br />
37. /**<br />
38. * 从连接池中获取数据库连接<br />
39. */<br />
40. public static Connection getConnection(TableMetaData table)<br />
41. throws Exception {<br />
42. String key = table.getConnectionKey();<br />
43.<br />
44. PoolingDriver driver = getPoolDriver();<br />
45.<br />
46. ObjectPool pool = null;<br />
47. // 这里找不到连接池会抛异常, 需要catch一下<br />
48. try {<br />
49. pool = driver.getConnectionPool(key);<br />
50. } catch (Exception e) {<br />
51. }<br />
52.<br />
53. if (pool == null) {<br />
54. // 根据数据库类型构建连接工厂<br />
55. ConnectionFactory connectionFactory = null;<br />
56. if (table.getDbAddr() != null<br />
57. &amp;&amp; TableMetaData.DB_TYPE_MYSQL == table.getDbType()) {<br />
58. Class.forName(TableMetaData.MYSQL_DRIVER);<br />
59. connectionFactory = new DriverManagerConnectionFactory(table<br />
60. .getDBUrl(), null);<br />
61. } else {<br />
62. Class.forName(TableMetaData.ORACLE_DRIVER);<br />
63. connectionFactory = new DriverManagerConnectionFactory(table<br />
64. .getDBUrl(), table.getDbuser(), table.getDbpass());<br />
65. }<br />
66.<br />
67. // 构造连接池<br />
68. ObjectPool connectionPool = new GenericObjectPool(null);<br />
69. new PoolableConnectionFactory(connectionFactory, connectionPool,<br />
70. null, null, false, true);<br />
71.<br />
72. // 将连接池注册到driver中<br />
73. driver.registerPool(key, connectionPool);<br />
74. }<br />
75.<br />
76. // 从连接池中拿一个连接<br />
77. return DriverManager.getConnection(POOL_DRIVER_KEY + key);<br />
78. }<br />
79.<br />
80. }</p></blockquote>
<p>虽然对象池技术在实际开发过程中用的不是很多, 但是理解之后对我们写程序还是有莫大的好处的, 至少我是这样的</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年09月2号 -- <a href="http://ourapache.com/archives/294" title="HTTP Referer二三事">HTTP Referer二三事</a></li><li>2009年08月12号 -- <a href="http://ourapache.com/archives/268" title="Etag和Expires">Etag和Expires</a></li><li>2009年09月6号 -- <a href="http://ourapache.com/archives/306" title="网络流量尽在掌控">网络流量尽在掌控</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/284" title="Apache负载均衡设置方法: mod_proxy">Apache负载均衡设置方法: mod_proxy</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/224" title="监视并记录Apache网站服务器的运行">监视并记录Apache网站服务器的运行</a></li><li>2009年06月7号 -- <a href="http://ourapache.com/archives/251" title="apxs是Apache编译和安装扩展模块的工具">apxs是Apache编译和安装扩展模块的工具</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/165" title="Apache 设置web 缓存">Apache 设置web 缓存</a></li><li>2009年05月8号 -- <a href="http://ourapache.com/archives/245" title="用apache实现禁止IP段或者主机对某个目录的访问">用apache实现禁止IP段或者主机对某个目录的访问</a></li><li>2009年01月15号 -- <a href="http://ourapache.com/archives/38" title="Apache服务器安全防范">Apache服务器安全防范</a></li><li>2009年02月6号 -- <a href="http://ourapache.com/archives/79" title="TCP 相关参数解释">TCP 相关参数解释</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/common-dbcp" title="common-dbcp" rel="tag">common-dbcp</a>, <a href="http://ourapache.com/archives/tag/common-pool" title="common-pool" rel="tag">common-pool</a>, <a href="http://ourapache.com/archives/tag/%e5%af%b9%e8%b1%a1%e6%b1%a0" title="对象池" rel="tag">对象池</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/211/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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 />
<a href="http://ourapache.com/archives/tag/apxs" class="st_tag internal_tag" rel="tag" title="标签 apxs 下的日志">apxs</a> -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><a href="http://ourapache.com/archives/tag/%e9%85%8d%e7%bd%ae" class="st_tag internal_tag" rel="tag" title="标签 配置 下的日志">配置</a>：</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/<a href="http://ourapache.com/archives/tag/mod_limitipconn" class="st_tag internal_tag" rel="tag" title="标签 mod_limitipconn 下的日志">mod_limitipconn</a>-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/<a href="http://ourapache.com/archives/tag/mod_bandwidth" class="st_tag internal_tag" rel="tag" title="标签 mod_bandwidth 下的日志">mod_bandwidth</a>.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>Apache2运用mod_deflate提升网络页面浏览速度</title>
		<link>http://ourapache.com/archives/119</link>
		<comments>http://ourapache.com/archives/119#comments</comments>
		<pubDate>Tue, 10 Feb 2009 07:03:59 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[mod_deflate]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=119</guid>
		<description><![CDATA[apache2已经用mod_deflate代替了mod_gzip
apache2已经包含了mod_deflate
以上的做法是压缩一般的网页html、xml、php、css、js等格式文件的输出，虽然会占用一点服务器的资源，不过这个可以减少带宽被占用的情况:)
这里：DeflateCompressionLevel 9是指压缩程度的等级，从1到9，9是最高级别的。这样做可以压缩到20%的大小，最少也有50%。至于jpg等已经压缩过的文件，就不需要再压缩了。]]></description>
			<content:encoded><![CDATA[<p>apache2已经用mod_deflate代替了mod_gzip</p>
<p>apache2已经包含了mod_deflate</p>
<p>打开模组</p>
<p>/usr/local/apache2/bin/<a href="http://ourapache.com/archives/tag/apxs" class="st_tag internal_tag" rel="tag" title="标签 apxs 下的日志">apxs</a> -i -c /yourpath/httpd-2.2.3/modules/filters/<a href="http://ourapache.com/archives/tag/mod_deflate" class="st_tag internal_tag" rel="tag" title="标签 mod_deflate 下的日志">mod_deflate</a>.c</p>
<p>httpd.conf添加</p>
<p>LoadModule deflate_module modules/mod_deflate.so</p>
<p>如果想只压缩html,text,xml 如果下面配置:</p>
<p>AddOutputFilterByType DEFLATE text/html text/plain text/xml</p>
<p>下面给出我的配置档:</p>
<p>LoadModule deflate_module modules/mod_deflate.so<br />
SetOutputFilter DEFLATE</p>
<p>BrowserMatch ^Mozilla/4 gzip-only-text/html<br />
BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html</p>
<p># Don’t compress images<br />
SetEnvIfNoCase Request_URI \<br />
\.(?:gif|jpe?g|png)$ no-gzip dont-vary<br />
SetEnvIfNoCase Request_URI \<br />
\.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary<br />
SetEnvIfNoCase Request_URI \<br />
\.pdf$ no-gzip dont-vary<br />
SetEnvIfNoCase Request_URI \<br />
\.(css|js)$ no-gzip dont-vary</p>
<p># Make sure proxies don’t deliver the wrong content<br />
Header append Vary User-Agent env=!dont-vary<br />
DeflateFilterNote Input input_info<br />
DeflateFilterNote Output output_info<br />
DeflateFilterNote Ratio ratio_info<br />
LogFormat ‘”%r” %{output_info}n/%{input_info}n (%{ratio_info}n%%)’ deflate<br />
CustomLog logs/deflate_log.log deflate</p>
<p>在apache的使用手册上还有这么一句,但是不知道为什么不能添加上去.</p>
<p># Make sure proxies don’t deliver the wrong content<br />
Header append Vary User-Agent env=!dont-vary</p>
<p>这个可以压缩 SVN 出来的文件。</p>
<p>———————————————</p>
<p>不能添加的原因是下面的模组没有打开：</p>
<p>LoadModule headers_module modules/mod_headers.so</p>
<p>=================</p>
<p>Apache deflate模块配置说明<br />
前几天一直在找apache2.0以dso方式编译后加载deflate模块的办法<br />
试了apxs -ica mod_deflate.c N次，始终是报</p>
<p>Cannot load /opt/apache/modules/mod_deflate.so into server: /opt/apache/modules/mod_deflate.so: undefined symbol: deflate</p>
<p>异常的痛苦，什么ldd mod_deflate.so后再export LIB_LIBRARY_PATH呀，都试了N次，google也go了N天。终于在google上go出来一篇文章，终于解决，方法如下：</p>
<p>vi /usr/local/apache2/bin/apr-config<br />
修改LDFLAGS=” ” 为 LDFLAGS=”-lz”<br />
然后再apxs -ica mod_deflate.c<br />
就OK了</p>
<p>另外在配置deflate规则时<br />
apache2.0推荐加上这句</p>
<p>Header append Vary User-Agent env=!dont-vary</p>
<p>以便确保不会输出在压缩过程中出现内容方面的error<br />
但一般情况下，在测试apache的语法过程中会现出<br />
Invalid command ‘Header’, perhaps mis-spelled or defined by a module not included in the server configuration<br />
解决办法就是加载一个headers模块就OK了</p>
<p>不过最好还是在编译apache模块时直接加上–enable-deflate –enable-headers就省事多了。</p>
<p>一、 需求<br />
压缩apache的输出内容，降低网站带宽<br />
二、 加载Apache的deflate模块<br />
1、 修改apr-config</p>
<p>vi /usr/local/apache2/bin/apr-config</p>
<p>修改LDFLAGS=” ” 为 LDFLAGS=”-lz”<br />
2、 到apache源安装目录下,例如</p>
<p>cd /root/httpd-2.0.55/modules/filters</p>
<p>3、加载mod_deflate模块</p>
<p>/usr/local/apache2/bin/apxs -i -a -c mod_deflate.c</p>
<p>如果没有安装headers模块，加载headers模块</p>
<p>cd /root/httpd-2.0.55/modules/metadata</p>
<p>加载mod_headers模块</p>
<p>/usr/local/apache2/bin/apxs -i -a –c mod_headers.c</p>
<p>三、配置Apache主配置文件<br />
1. 在httpd.conf主配置文件里添加如下行</p>
<p>#声明输入流的byte数量<br />
DeflateFilterNote Input instream<br />
#声明输出流的byte数量<br />
DeflateFilterNote Output outstream<br />
#声明压缩的百分比<br />
DeflateFilterNote Ratio ratio<br />
#声明日志类型<br />
LogFormat ‘”%r” %{outstream}n/%{instream}n (%{ratio}n%%)’ deflate<br />
CustomLog logs/deflate_log deflate</p>
<p>#指定压缩参数</p>
<p># Insert filter<br />
SetOutputFilter DEFLATE</p>
<p># Netscape 4.x has some problems…<br />
BrowserMatch ^Mozilla/4 gzip-only-text/html</p>
<p># Netscape 4.06-4.08 have some more problems<br />
BrowserMatch ^Mozilla/4\.0[678] no-gzip</p>
<p># MSIE masquerades as Netscape, but it is fine<br />
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html</p>
<p># NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48<br />
# the above regex won’t work. You can use the following<br />
# workaround to get the desired effect:<br />
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html</p>
<p># Don’t compress images<br />
SetEnvIfNoCase Request_URI \.(?:gif|jpg|cab|jpe?g|exe|bmp|mp3|rar|zip|swf|png)$ no-gzip dont-vary</p>
<p># Make sure proxies don’t deliver the wrong content<br />
Header append Vary User-Agent env=!dont-vary</p>
<p>二、日志输出格式如下</p>
<p>[root@trffic2 logs]# tail -f access_log<br />
“GET /apache_pb.gif HTTP/1.1″ -/- (-%)<br />
“GET /manual/ HTTP/1.1″ 2163/7434 (29%)<br />
“GET /manual/style/css/manual.css HTTP/1.1″ 3973/18335 (21%)<br />
“GET /manual/style/css/manual-loose-100pc.css HTTP/1.1″ 1006/2882 (34%)<br />
“GET /manual/style/css/manual-print.css HTTP/1.1″ 2994/13017 (23%)</p>
<p>_________________</p>
<p>apache1.3.x可以用mod_gzip进行优化网页浏览的速度，可以明显的感觉到速度的提升。在apache2中也尝试用mod_gzip，但是配置后确发现网页不能正确显示（空白页），所以改换mod_deflate。<br />
在Linux命令行下运行以下命令安装mod_deflate模块（斜体是apache2的目录）</p>
<p>/usr/local/apache2/bin/apxs -i -c /root/httpd-2.0.48/modules/filters/mod_deflate.c</p>
<p>编辑httpd.conf，加入以下内容：</p>
<p>LoadModule deflate_module modules/mod_deflate.so<br />
DeflateFilterNote ratio<br />
LogFormat ‘”%v %h %l %u %t “%r” %&amp;gt;s %b “%{Referer}i” “%{User-Agent}i”” (%{ratio}n)’ deflate</p>
<p># Insert filter<br />
SetOutputFilter DEFLATE</p>
<p># Netscape 4.x has some problems…<br />
BrowserMatch ^Mozilla/4 gzip-only-text/html</p>
<p># Netscape 4.06-4.08 have some more problems<br />
BrowserMatch ^Mozilla/4.0[678] no-gzip</p>
<p># MSIE masquerades as Netscape, but it is fine<br />
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html</p>
<p># Don’t compress images<br />
SetEnvIfNoCase Request_URI<br />
.(?:gif|jpe?g|png)$ no-gzip dont-vary</p>
<p># Make sure proxies don’t deliver the wrong content</p>
<p># Header命令不对？注释这一行<br />
# Header append Vary User-Agent env=!dont-vary</p>
<p>#查找Customlog 注释原来的的一行，改成<br />
CustomLog logs/deflate_log deflate</p>
<p>#查看logs目录下deflate_log文件，你可以看到许多这样的信息：<br />
“www.21php.com 220.163.107.88 &#8211; - [27/Mar/2004:01:03:55 -0800] “GET /ad/usrlogo/21PHPLOGO_88X31.gif HTTP/1.1″ 200 3656 “http://soft.ttee.com/vbb/” “Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)”” (-)<br />
“www.21php.com 211.144.88.138 &#8211; - [27/Mar/2004:01:03:57 -0800] “GET /tutorial/tutorial.php?tid=68 HTTP/1.1″ 200 5173 “http://www.21php.com/tutorial/tutorial.php?catalogid=12″ “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; .NET CLR 1.0.3705; Alexa Toolbar)”” (29)<br />
“www.21php.com 211.144.88.138 &#8211; - [27/Mar/2004:01:03:58 -0800] “GET /style.cssHTTP/1.1″ 304 &#8211; “http://www.21php.com/tutorial/tutorial.php?tid=68″ “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; .NET CLR 1.0.3705; Alexa Toolbar)”” (-)<br />
“www.21php.com 211.144.88.138 &#8211; - [27/Mar/2004:01:03:58 -0800] “GET /images/bar-4.gif HTTP/1.1″ 304 &#8211; “http://www.21php.com/tutorial/tutorial.php?tid=68″ “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; .NET CLR 1.0.3705; Alexa Toolbar)”” (-)<br />
“www.21php.com 211.144.88.138 &#8211; - [27/Mar/2004:01:03:58 -0800] “GET /images/logo.gif HTTP/1.1″ 304 &#8211; “http://www.21php.com/tutorial/tutorial.php?tid=68″ “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; .NET CLR 1.0.3705; Alexa Toolbar)”” (-)<br />
“www.21php.com 211.144.88.138 &#8211; - [27/Mar/2004:01:03:58 -0800] “GET /images/icon1.gif HTTP/1.1″ 304 &#8211; “http://www.21php.com/tutorial/tutorial.php?tid=68″ “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; .NET CLR 1.0.3705; Alexa Toolbar)”” (-)</p>
<p>Boban 写于2004年3月27日凌晨</p>
<p>附注：关于mod_deflate的详细内容，可以参考http://httpd.apache.org/docs-2.0/mod/mod_deflate.html<br />
__________________</p>
<p>如果apache是rpm安装的，那么默认就已经有mod_deflate这个模块了。<br />
更详细的可以看这里：http://sysoev.ru/mod_deflate/readme.html</p>
<p>因为mod_deflate相比较mod_gzip来说，有了更多的更新，所以我用上了它！<br />
注意：mod_gzip在apache1.x上用起来比较好，但是在apache2.x上用起来就不是很爽，老出错，也许是我的水平问题，没办法，所以改用：mod_deflate</p>
<p>我的apache：2.0.55<br />
配置如下：（修改：httpd.conf）</p>
<p>DeflateCompressionLevel 9<br />
AddOutputFilterByType DEFLATE text/html text/plain text/xml<br />
application/x-httpd-php<br />
AddOutputFilter DEFLATE js css</p>
<p>BrowserMatch ^Mozilla/4 gzip-only-text/html<br />
BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html<br />
Header append Vary User-Agent env=!dont-vary</p>
<p>DeflateFilterNote deflate_ratioLogFormat “%v %h %l %u %t \”%r\” %&amp;gt;s %b mod_deflate: %{deflate_ratio}n pct.” vhost_with_deflate_infoCustomLog logs/order.7180.com-access_log vhost_with_deflate_info</p>
<p>将以上的配置文字加入到：之间即可:)</p>
<p>以上的做法是压缩一般的网页html、xml、php、css、js等格式文件的输出，虽然会占用一点服务器的资源，不过这个可以减少带宽被占用的情况:)<br />
这里：DeflateCompressionLevel 9是指压缩程度的等级，从1到9，9是最高级别的。这样做可以压缩到20%的大小，最少也有50%。至于jpg等已经压缩过的文件，就不需要再压缩了。</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年09月6号 -- <a href="http://ourapache.com/archives/306" title="网络流量尽在掌控">网络流量尽在掌控</a></li><li>2010年04月13号 -- <a href="http://ourapache.com/archives/326" title="解决linux下安装ssl后，apache重启时需要密码">解决linux下安装ssl后，apache重启时需要密码</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/314" title="使用Apache做负载均衡">使用Apache做负载均衡</a></li><li>2010年04月13号 -- <a href="http://ourapache.com/archives/322" title="apache 的AcceptMutex 的理解">apache 的AcceptMutex 的理解</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/273" title="Apache和IIS共享80端口的四个方法">Apache和IIS共享80端口的四个方法</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/190" title="header Content-Disposition参数说明">header Content-Disposition参数说明</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/3" title="apache的配置优化">apache的配置优化</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/111" title="Apache 中内存管理的三种境界 ">Apache 中内存管理的三种境界 </a></li><li>2009年01月5号 -- <a href="http://ourapache.com/archives/19" title="重大漏洞, 让Apache上传不安全-php.rar">重大漏洞, 让Apache上传不安全-php.rar</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/104" title="Apache和IIS共享80端口的四个方法">Apache和IIS共享80端口的四个方法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/mod_deflate" title="mod_deflate" rel="tag">mod_deflate</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/119/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>谈谈Apache的优化</title>
		<link>http://ourapache.com/archives/109</link>
		<comments>http://ourapache.com/archives/109#comments</comments>
		<pubDate>Tue, 10 Feb 2009 06:52:58 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[KeepAlive]]></category>
		<category><![CDATA[优化]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=109</guid>
		<description><![CDATA[今天说说Apache的优化。为什么要优化？因为服务器资源不够用。资源有很多方面，但根据木桶理论，只要有一种资源不够用，整个服务器的性能就会受到影响（所谓瓶颈）。]]></description>
			<content:encoded><![CDATA[<p>今天说说Apache的优化。为什么要优化？因为服务器资源不够用。资源有很多方面，但根据木桶理论，只要有一种资源不够用，整个服务器的性能就会受到影响（所谓瓶颈）。</p>
<p><strong>服务器资源</strong></p>
<p>那么服务器的资源包括哪些？对于网站来说主要是<strong>CPU</strong>、<strong>TCP连接数</strong>这两者。 CPU表现在任务数上，在Linux下使用<strong>平均负载</strong>(loadavg)来衡量。可通过以下命令来查看（参考<a href="http://tech.idv2.com/2006/08/31/about-proc-loadavg/"><span style="color: #448608;">这篇文章</span></a>）：</p>
<p>cat /proc/loadavg</p>
<p>对于单CPU的服务器，loadavg高于1，表明任务队列出现了等待，CPU忙不过来了。超过2以上就会明显感到性能降低了。</p>
<p>TCP连接数可通过以下命令查看：<br />
netstat -ant | grep :80 | wc -l</p>
<p>如果要实时监控服务器资源，可参考<a href="http://www.opennms.org/"><span style="color: #448608;">OpenNMS</span></a>项目。</p>
<p><span style="color: blue;">注1：内存不算，低廉的价格使得网站服务器很少有因为内存不够而down掉的。</span><br />
<span style="color: blue;">注2：CPU%是瞬时的CPU使用率，通常无法反映出整体负载。</span></p>
<p> </p>
<p><strong>Apache配置命令</strong></p>
<p>Apache在资源方面的配置命令主要有以下几条。</p>
<div>
<table border="0">
<tbody>
<tr>
<td><a href="http://ourapache.com/archives/tag/keepalive" class="st_tag internal_tag" rel="tag" title="标签 KeepAlive 下的日志">KeepAlive</a></td>
<td>是否允许持续连接</td>
</tr>
<tr>
<td>MaxKeepAliveRequests</td>
<td>允许的持续连接的最大数</td>
</tr>
<tr>
<td>KeepAliveTimeout</td>
<td>持续连接在没有请求多少秒后切断</td>
</tr>
<tr>
<td>StartServers</td>
<td>最初启动时启动多少个服务器进程</td>
</tr>
<tr>
<td>MinSpareServers</td>
<td>空闲服务器进程的最小数</td>
</tr>
<tr>
<td>MaxSpareServers</td>
<td>空闲服务器进程的最大数</td>
</tr>
<tr>
<td>MaxRequestsPerChild</td>
<td>每个子进程处理的最大请求数</td>
</tr>
</tbody>
</table>
</div>
<p><strong>KeepAlive</strong></p>
<p>前三个KeepAlive相关的指令用来设置持续连接。通常都是每个HTTP请求对应一个TCP连接，但对于一个包含许多图片的网页来说，客户端会在瞬间发出多个HTTP请求，此时多次建立TCP连接会大大降低响应速度。此时通过持续连接，可以允许用户在一个TCP连接中发出多个HTTP请求，减少TCP连接建立次数，提高响应速度。</p>
<p>这种情况下，应当通过access_log统计出连续HTTP请求出现的次数、间隔时间、访问量，以确定 MaxKeepAliveRequests 和 KeepAliveTimeout 的值。 KeepAliveTimeout 太小发挥不了持续连接的作用；太大了，持续连接迟迟不断，浪费TCP连接数不说，更糟糕的是系统中的 httpd 进程数目会因此不断增加，使得系统负载升高，甚至会导致服务器失去响应。</p>
<p>但是在处理动态网页请求时，由于用户很少会瞬间请求多个动态网页（一般都是打开页面之后阅读好半天才点下一页），此时打开KeepAlive无异于浪费TCP连接数。</p>
<p>结论就是，放动态网页的就 KeepAlive Off 以提高吞吐量，放静态内容如图片、js代码等就 KeepAlive On 以减少TCP连接建立次数。</p>
<p>但一个Apache只能有一种 KeepAlive 设置，怎么办？很简单，弄两台服务器，一个专门放脚本，一个专门放图片。</p>
<p><strong>服务器进程数</strong></p>
<p>再说说下面的 StartServers、MinSpareServers、MaxSpareServers。 StartServers基本不用修改，因为Apache会自动调节子进程数。 MinSpareServers和MaxSpareServers是空闲子进程数目，何为空闲子进程？假设某一时刻系统中共有30个httpd进程，其中一个是父进程，20个在处理请求，那么空闲子进程数就是9个。</p>
<p>空闲进程少了，大量的突发请求会使服务器疲于进程创建，降低效率；而太多反而会增加系统进程数，增大系统负载。</p>
<p>实际上，默认值已足够处理一般的突发请求，所以除非是流量特别特别巨大的网站，否则不要修改这些设置。</p>
<p><span style="color: blue;">就算流量特别特别大，也是通过负载平衡系统来降低每台服务器的访问量，不会修改这几个值。</span></p>
<p><strong>MaxRequestsPerChild</strong></p>
<p>这个值设置子进程在处理多少个请求之后自动结束。这个选项是用来防止进程由于内存泄漏等使用内存过多。一般默认值即可。</p>
<p><strong>总结</strong></p>
<p>说来说去其实最重要的还是 KeepAlive 的设置，而性能调节也就是调整 KeepAlive、KeepAliveTimeout 值。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年04月1号 -- <a href="http://ourapache.com/archives/236" title="关于HTTP 协议中的 KeepAlive">关于HTTP 协议中的 KeepAlive</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/29" title="Apache 中KeepAlive 配置的合理使用(优化) ">Apache 中KeepAlive 配置的合理使用(优化) </a></li><li>2009年01月5号 -- <a href="http://ourapache.com/archives/21" title="关于keepalive的解释">关于keepalive的解释</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/3" title="apache的配置优化">apache的配置优化</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/keepalive" title="KeepAlive" rel="tag">KeepAlive</a>, <a href="http://ourapache.com/archives/tag/%e4%bc%98%e5%8c%96" title="优化" rel="tag">优化</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/109/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>对apache中并发控制参数prefork理解和调优</title>
		<link>http://ourapache.com/archives/62</link>
		<comments>http://ourapache.com/archives/62#comments</comments>
		<pubDate>Thu, 22 Jan 2009 07:26:26 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[prefork]]></category>
		<category><![CDATA[并发控制参数]]></category>
		<category><![CDATA[调优]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=62</guid>
		<description><![CDATA[一个apache有linux下的并发不是很高的,大约到3K的样子(其实处理的http的请求可能只有300/s),普通的服务器都会不同程度的出现问题.apache有关并发控制主要是 prefork和worker二个其中一个来控制.我们可以使用httpd -l来确定当前使用的MPM是prefork.c,还是Worker.c.下面是apache中有关prefork的配置.下面是我优化过的参数.]]></description>
			<content:encoded><![CDATA[<p>一个apache有linux下的并发不是很高的,大约到3K的样子(其实处理的http的请求可能只有300/s),普通的服务器都会不同程度的出现问题.apache有关并发控制主要是 prefork和worker二个其中一个来控制.我们可以使用httpd -l来确定当前使用的MPM是prefork.c,还是Worker.c.下面是apache中有关prefork的配置.下面是我优化过的参数.</p>
<p>&lt;IfModule <a href="http://ourapache.com/archives/tag/prefork" class="st_tag internal_tag" rel="tag" title="标签 prefork 下的日志">prefork</a>.c&gt;</p>
<p>#有这个参数就不必像apache1一样修改源码才能修改256客户数的限制,听讲要放到最前面才会生效,2000是这个参数的最大值<br />
ServerLimit 2000<br />
#指定服务器启动时建立的子进程数量，prefork默认为5。<br />
StartServers 25</p>
<p>#指定空闲子进程的最小数量，默认为5。如果当前空闲子进程数少于MinSpareServers ，那么Apache将以最大每秒一个的速度产生新的子进程。此参数不要设的太大。<br />
MinSpareServers 25</p>
<p>#设置空闲子进程的最大数量，默认为10。如果当前有超过MaxSpareServers数量的空闲子进程，那么父进程将杀死多余的子进程。此参数 不要设的太大。如果你将该指令的值设置为比MinSpareServers小，Apache将会自动将其修改成”MinSpareServers+1&#8243;。<br />
MaxSpareServers 50</p>
<p>#限定同一时间客户端最大接入请求的数量(单个进程并发线程数)，默认为256。任何超过MaxClients限制的请求都将进入等候队列,一旦一个链接被释放，队列中的请求将得到服务。要增大这个值，你必须同时增大ServerLimit 。<br />
MaxClients 2000</p>
<p>#每个子进程在其生存期内允许伺服的最大请求数量，默认为10000.到达MaxRequestsPerChild的限制后，子进程将会结束。如果MaxRequestsPerChild为”0&#8243;，子进程将永远不会结束。<br />
MaxRequestsPerChild 10000</p>
<p>&lt;/IfModule&gt;</p>
<p>将MaxRequestsPerChild设置成非零值有两个好处：<br />
1.可以防止(偶然的)内存泄漏无限进行，从而耗尽内存。<br />
2.给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。</p>
<p>工作方式：<br />
一个单独的控制进程(父进程)负责产生子进程，这些子进程用于监听请求并作出应答。Apache总是试图保持一些备用的 (spare)或者是空闲的子进程用于迎接即将到来的请求。这样客户端就不需要在得到服务前等候子进程的产生。在Unix系统中，父进程通常以root身 份运行以便邦定80端口，而 Apache产生的子进程通常以一个低特权的用户运行。User和Group指令用于设置子进程的低特权用户。运行子进程的用户必须要对它所服务的内容有 读取的权限，但是对服务内容之外的其他资源必须拥有尽可能少的权限。</p>
<p><span style="color: #ff6600;">对上面的有些值，一定要记的不是越大越好.这个需要经过几次尝试和出错之后才能选好要使用的值(不同的硬件处理水平不一样)。最重要的值是maxclient允许足够多的 工作进程，同时又不会导致服务器进行过度的交换(死机)。如果传入的请求超出处理能力而让服务器当掉的话，那么至少满足此值的那些请求会得到服务，其他请求被阻塞这样会更加好。</span></p>
<p> </p>
<p><strong>我们调优常常要查看httpd进程数（即prefork模式下Apache能够处理的并发请求数）</strong>：</p>
<p>#ps -ef | grep httpd | wc -l</p>
<p>出现的结果,就是当前Apache能够处理的多少个并发请求，这个值Apache根据负载情况自动调.</p>
<p><strong>查看Apache的并发请求数及其TCP连接状态： </strong></p>
<p>#netstat -n | awk &#8216;/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}&#8217;</p>
<p>上面这句来自己我一个新浪的朋友<a href="http://blog.s135.com/"><span style="color: #729752;">张宴</span></a>.</p>
<p>返回结果示例：<br />
LAST_ACK 5<br />
SYN_RECV 30<br />
ESTABLISHED 1597<br />
FIN_WAIT1 51<br />
FIN_WAIT2 504<br />
TIME_WAIT 1057<br />
其中的SYN_RECV表示正在等待处理的请求数；ESTABLISHED表示正常数据传输状态；TIME_WAIT表示处理完毕，等待超时结束的请求数。</p>
<p>状态：描述<br />
CLOSED：无连接是活动的或正在进行<br />
LISTEN：服务器在等待进入呼叫<br />
SYN_RECV：一个连接请求已经到达，等待确认<br />
SYN_SENT：应用已经开始，打开一个连接<br />
ESTABLISHED：正常数据传输状态<br />
FIN_WAIT1：应用说它已经完成<br />
FIN_WAIT2：另一边已同意释放<br />
ITMED_WAIT：等待所有分组死掉<br />
CLOSING：两边同时尝试关闭<br />
TIME_WAIT：另一边已初始化一个释放<br />
LAST_ACK：等待所有分组死掉</p>
<p>可以使用<span style="font-family: 宋体;">Linux下的webbench来作压力测试.</span></p>
<p>更新日期:08年9月28日.</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年08月16号 -- <a href="http://ourapache.com/archives/288" title="Apache两种常用工作模式比较:prefork和worker">Apache两种常用工作模式比较:prefork和worker</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/234" title="Apache的prefork模式和worker模式">Apache的prefork模式和worker模式</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/232" title="Apache Prefork和Worker模式的性能比较测试">Apache Prefork和Worker模式的性能比较测试</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/229" title="对Apache中并发控制参数prefork理解和调优">对Apache中并发控制参数prefork理解和调优</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/222" title="Apache 2.0中prefork.c模块和worker.c模块的比较">Apache 2.0中prefork.c模块和worker.c模块的比较</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/64" title="Apache连接数设置prefork">Apache连接数设置prefork</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/prefork" title="prefork" rel="tag">prefork</a>, <a href="http://ourapache.com/archives/tag/%e5%b9%b6%e5%8f%91%e6%8e%a7%e5%88%b6%e5%8f%82%e6%95%b0" title="并发控制参数" rel="tag">并发控制参数</a>, <a href="http://ourapache.com/archives/tag/%e8%b0%83%e4%bc%98" title="调优" rel="tag">调优</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/62/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache服务器安全防范</title>
		<link>http://ourapache.com/archives/38</link>
		<comments>http://ourapache.com/archives/38#comments</comments>
		<pubDate>Thu, 15 Jan 2009 09:58:03 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[安全]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=38</guid>
		<description><![CDATA[Apache服务器走到那里，unix/linux就跟到那里，这足以说明在WEB服务器领域Apache的优良性能与市场占有率

这今天互联网的大环境下，web服务已经成为公司企业必不可少的业务，大多数的安全问题也跟随而来，攻击重点也转移为web攻击，许多web与颇有价值的客户服务与电子商业活动结合在一起，这也是吸引恶意攻击重要原因。 ]]></description>
			<content:encoded><![CDATA[<p style="text-indent: 2em;">Apache服务器走到那里，unix/linux就跟到那里，这足以说明在WEB服务器领域Apache的优良性能与市场占有率</p>
<p style="text-indent: 2em;">这今天互联网的大环境下，web服务已经成为公司企业必不可少的业务，大多数的安全问题也跟随而来，攻击重点也转移为web攻击，许多web与颇有价值的客户服务与电子商业活动结合在一起，这也是吸引恶意攻击重要原因。</p>
<p style="text-indent: 2em;">先来了解下web所面临的安全风险</p>
<p style="text-indent: 2em;">HTTP拒绝服务攻击</p>
<p style="text-indent: 2em;">攻击者通过某些手段使服务器拒绝对http应答，这使Apache对系统资源（cup时间与内存）需求巨增，最终造成系统变慢甚至完全瘫痪，Apache服务器最大的缺点是，它的普遍性使它成为众矢之的，Apache服务器无时无刻不受到DoS攻击威胁，主要有下边几种</p>
<p style="text-indent: 2em;">1.数据包洪水攻击</p>
<p style="text-indent: 2em;">一种中断服务器或本地网络的方法是数据包洪水攻击，它通常使用internet控制报文协议（ICMP，属于网络层协议）</p>
<p style="text-indent: 2em;">包或是udp包，在最简单的形式下，这些攻击都是使服务器或网络负载过重，这意味这攻击者的网络速度必须比目标主机网络速度要快，使用udp包的优势是不会有任何包返回到黑客的计算机（udp效率要比tcp高17倍），而使用ICMP包的优势是攻击者能让攻击更加富与变化，发送有缺陷的包会搞乱并锁住受害者的网络，目前流行的趋势是攻击者欺骗服务器，让其相信正在受来自自身的洪水攻击</p>
<p style="text-indent: 2em;">2.磁盘攻击</p>
<p style="text-indent: 2em;">这是一种很不道德的攻击，它不仅影响计算机的通信，还破坏其硬件，伪造的用户请求利用写命令攻击目标计算机硬盘，让其超过极限，并强制关闭，结局很悲惨</p>
<p style="text-indent: 2em;">3.路由不可达</p>
<p style="text-indent: 2em;">通常DoS攻击，集中在路由器上，攻击者首先获得控制权并操纵目标机器，当攻击者能更改路由表条目时候，会导致整个网络无法通信，这种攻击很阴险，隐蔽，因为网络管理员需要排除的网络不通原因很多，其中一些原因需要详细分辨</p>
<p style="text-indent: 2em;">4.分布式拒绝服务攻击</p>
<p style="text-indent: 2em;">这也是最具有威胁的DDoS攻击，名称很容易理解，简单说就是群欧，很多客户机同时单条服务器，你会发现你将伤痕累累，Apache服务器特别容易受到攻击，无论是DDos还是隐藏来源的攻击，因为Apache无处不在，特别是为Apache特意打造的病毒（特选SSL蠕虫），潜伏在许多主机上，攻击者通过病毒可以操纵大量被感染的机器，对特定目标发动一次浩大的DDoS攻击，通过将蠕虫散播到大量主机，大规模的点对点攻击得以进行，除非你不提供服务，要不然几乎无法阻止这样的攻击，这种攻击通常会定位到大型的网站上。</p>
<p style="text-indent: 2em;">缓冲区溢出，这种攻击很普遍，攻击者利用CGI程序编写一些缺陷程序偏离正常的流程，程序使用静态的内存分配，攻击者就可以发送一个超长的请求使缓冲区溢出，比如，一些perl编写的处理用户请求的网关脚本，一但缓冲区溢出，攻击者就可以执行恶意指令</p>
<p style="text-indent: 2em;">非法获取root权限</p>
<p style="text-indent: 2em;">如果Apache以root权限运行，系统上一些程序的逻辑缺陷或缓冲区溢出漏洞，会让攻击者很容易在本地系统获取linux服务器上的管理者权限，在一些远程情况下，攻击者会利用一些以root身份执行的有缺陷的系统守护进程来取得root权限，或利用有缺陷的服务进程漏洞来取得普通用户权限，以远程登陆，进而控制整个系统。</p>
<p style="text-indent: 2em;">这边这些都是服务将会遇到的攻击手段，下边来说，如何打造安全的Apache服务器</p>
<p style="text-indent: 2em;">如果你能遵守下边这些建议，那么你将得到一台相对安全的apache服务器</p>
<p style="text-indent: 2em;">一：勤打补丁</p>
<p style="text-indent: 2em;">你必须要相信这个是最有用的手段，缓冲区溢出等漏洞都必须使用这种手段来防御，勤快点相信对你没有坏处</p>
<p style="text-indent: 2em;">在http:www.apache.org上最新的changelog中都写有：bug fix ,security bug fix的字样，做为负责任的管理员要经常关注相关漏洞，及时升级系统添加补丁。使用最新安全版本对加强apache至关重要</p>
<p style="text-indent: 2em;">二：隐藏和伪装Apache的版本</p>
<p style="text-indent: 2em;">打乱攻击者的步骤，给攻击者带来麻烦，相信是管理员愿意看到的。软件的漏洞信息和版本是相关的，在攻击者收集你服务软件信息时候给与迷惑是个不错的选择，何况版本号，对攻击者来说相当与GPS定位一样重要</p>
<p style="text-indent: 2em;">默认情况，系统会把apache版本模块都显示出来（http返回头），如果列举目录的话，会显示域名信息（文件列表正文），去除Apache版本号的方法是修改配置文件，找到关键字,修改为下边</p>
<p style="text-indent: 2em;">ServerSignature off</p>
<p style="text-indent: 2em;">ServerTokens prod</p>
<p style="text-indent: 2em;">通过分析web服务器类型，大致可以推测操作系统类型，win使用iis,linux普遍apache，默认的Apache配置里没有任何信息保护机制，并且允许目录浏览，通过目录浏览，通常可以得到类似“apache/1.37 Server at apache.linuxforum.net Port 80”或“apache/2.0.49(unix)PHP/4.3.8”的信息</p>
<p style="text-indent: 2em;">通过修改配置文件中的ServerTokens参数，可以将Apache的相关信息隐藏起来，如果不行的话，可能是提示信息被编译在程序里了，要隐藏需要修改apache的源代码，然后重新编译程序，以替换内容</p>
<p style="text-indent: 2em;">编辑ap_release.h文件，</p>
<p style="text-indent: 2em;">修改”#define AP_SERVER_BASEPRODUCT”Apache”"为</p>
<p style="text-indent: 2em;">“#define AP_SERVER_BASEPRODUCT”Microsoft-IIS/5.0&#8243;</p>
<p style="text-indent: 2em;">编辑os/unix/os.h文件</p>
<p style="text-indent: 2em;">修改”#define PLATFORM”Unix”"为</p>
<p style="text-indent: 2em;">“#define PLATFORM&#8217;Win32&#8243;</p>
<p style="text-indent: 2em;">修改完成后，重新编译，安装apache,在修改配置文件为上边做过的，再次启动apache后，用工具扫描，发现提示信息中已经显示为windows操作系统了</p>
<p style="text-indent: 2em;">顺便说下，现在这个论坛，就有点不太讲究，这是论坛错误的返回信息，看了有点汗地感觉</p>
<p style="text-indent: 2em;">Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.4.6 mod_ssl/2.2.8 OpenSSL/0.9.8g Server at forum.ubuntu.org.cn Port 80</p>
<p style="text-indent: 2em;">这个等于告诉恶意用户很多有用信息，虽然说不算开了门，但等于被告诉了门在那里，还是相当危险的</p>
<p style="text-indent: 2em;">三：建立安全的目录结构apache服务器包括四个目录结构</p>
<p style="text-indent: 2em;">ServerRoot #保存配置文件，二进制文件与其他服务器配置文件</p>
<p style="text-indent: 2em;">DocumentRoot #保存web站点内容，包括HTML文件和图片等</p>
<p style="text-indent: 2em;">ScripAlias #保存CGI脚本</p>
<p style="text-indent: 2em;">Customlog 和 Errorlog #保存日志和错误日志</p>
<p style="text-indent: 2em;">建议的目录结构为，以上四种目录相互独立并且不存在父子逻辑关系</p>
<p style="text-indent: 2em;">注：</p>
<p style="text-indent: 2em;">ServerRoot目录只能为root用户访问</p>
<p style="text-indent: 2em;">DocumentRoot目录应该能够被管理web站点内容的用户访问和使用apache服务器的apache用户与组访问</p>
<p style="text-indent: 2em;">ScripAlias目录应该只能被CGI开发人员和apache用户访问</p>
<p style="text-indent: 2em;">Customlog 和 Errorlog只能被root访问</p>
<p style="text-indent: 2em;">下边是一个安全目录结构的事例</p>
<p style="text-indent: 2em;">+&#8212;&#8212;-/etc/</p>
<p style="text-indent: 2em;">|</p>
<p style="text-indent: 2em;">| +&#8212;-/http (ServerRoot)</p>
<p style="text-indent: 2em;">| +&#8212;-/logs (Customlog 和 Errorlog)</p>
<p style="text-indent: 2em;">|</p>
<p style="text-indent: 2em;">+&#8212;&#8212;-var/www</p>
<p style="text-indent: 2em;">|</p>
<p style="text-indent: 2em;">| +&#8212;/cgi-bin (ScripAlias)</p>
<p style="text-indent: 2em;">| +&#8212;/html (DocumentRoot)</p>
<p style="text-indent: 2em;">这样的目录结构是比较安全的，因为目录之间独立，某个目录权限错误不会影响到其他目录</p>
<p style="text-indent: 2em;">四：为apache使用专门的用户与组</p>
<p style="text-indent: 2em;">按照最小特权的原则，需要给apache分配一个合适的权限，让其能够完成web服务</p>
<p style="text-indent: 2em;">注：</p>
<p style="text-indent: 2em;">最小特权原则是系统安全中最基本的原则之一，限制使用者对系统及数据进行存取所需要的最小权限，保证用户可以完成任务，同时也确保被窃取或异常操作所造成的损失</p>
<p style="text-indent: 2em;">必须保证apache使用一个专门的用户与组，不要使用系统预定的帐户，比如nobody用户与nogroup组</p>
<p style="text-indent: 2em;">因为只有root用户可以运行apache，DocumentRoot应该能够被管理web站点内容的用户访问和使用apache服务器的apache用户与组访问，例如，希望“test”用户在web站点发布内容，并且可以以httpd身份运行apache服务器，可以这样设定</p>
<p style="text-indent: 2em;">groupadd webteam</p>
<p style="text-indent: 2em;">usermod -G webteam test</p>
<p style="text-indent: 2em;">chown -R httpd.webteam /www/html</p>
<p style="text-indent: 2em;">chmod -R 2570 /www/htdocs</p>
<p style="text-indent: 2em;">只有root能访问日志，推荐这样的权限</p>
<p style="text-indent: 2em;">chown -R root.root /etc/logs</p>
<p style="text-indent: 2em;">chown -R 700 /etc/logs</p>
<p style="text-indent: 2em;">五：web目录的访问策略</p>
<p style="text-indent: 2em;">对于可以访问的web目录，要使用相对保守的途径进行访问，不要让用户查看任何目录索引列表</p>
<p style="text-indent: 2em;">禁止使用目录索引：</p>
<p style="text-indent: 2em;">apache在接到用户对一个目录的访问时，会查找DirectoryIndex指令指定的目录索引文件，默认为index.html，如果该文件不存在，那么apache会创建动态列表为用户显示该目录的内容，这样就会暴露web站点结构，因此需要修改配置文件禁止显示动态目录索引，修改httpd.conf</p>
<p style="text-indent: 2em;">Options -Indexes FollowSymLinks</p>
<p style="text-indent: 2em;">Options指令通知apache禁止使用目录索引，FollowSymLinks表示不允许使用符号连接。</p>
<p style="text-indent: 2em;">禁止默认访问：</p>
<p style="text-indent: 2em;">要的安全策略必须要禁止默认访问的存在，只对指定的目录开放权限，如果允许访问/var/www/html目录，使用如下设定</p>
<p style="text-indent: 2em;">Order deny,allow</p>
<p style="text-indent: 2em;">Allow from all</p>
<p style="text-indent: 2em;">禁止用户重载：</p>
<p style="text-indent: 2em;">为了禁止用户对目录配置文件（htaccess）进行重载（修改），可以这样设定</p>
<p style="text-indent: 2em;">AllowOverride None</p>
<p style="text-indent: 2em;">六：apache服务器访问控制</p>
<p style="text-indent: 2em;">apache的access.conf文件负责设置文件的访问权限，可以实现互联网域名和ip地址的访问控制</p>
<p style="text-indent: 2em;">如允许192.168.1.1到192.168.1.254的主机访问，可以这样设定</p>
<p style="text-indent: 2em;">order deny,allow</p>
<p style="text-indent: 2em;">deny from all</p>
<p style="text-indent: 2em;">allow from pair 192.168.1.0/255.255.255.0</p>
<p style="text-indent: 2em;">七：apache服务器的密码保护</p>
<p style="text-indent: 2em;">.htaccess文件是apache上的一个设置文件，它是一个文本文件，.htaccess文件提供了针对目录改变配置的方法</p>
<p style="text-indent: 2em;">既通过在一个特定的文档目录中放置一个包含一个或多个指令的文件（.htaccess文件），以作用于此目录和子目录。</p>
<p style="text-indent: 2em;">.htaccess的功能包括设置网页密码，设置发生错误时出现的文件，改变首业的文件名（如，index.html）,禁止读取文件名，重新导向文件，加上MIME类别，禁止目录下的文件等。</p>
<p style="text-indent: 2em;">注：.htaccess是一个完整的文件名，不是***.htaccess或其他格式，在/abc目录下放置一个.htaccess文件，那么/abc与它的子目录都会被这个文件影响，但/index.html不会被影响</p>
<p style="text-indent: 2em;">.htaccess的建立和使用比较复杂点，如果感兴趣的朋友可以回帖发问，这里就不具体写出来了，这种保护要比某些程序实现的保护安全，那种方法可以通过被猜测方法获取密码，用.htaccess很难被破解，但文本方式的验证会比较慢，对少量用户没影响，但对大量用户就必须使用带数据模块的验证了，这需要编译源代码时候开启模块，默认是不开启的</p>
<p style="text-indent: 2em;">八：让apache运行在“监牢”中</p>
<p style="text-indent: 2em;">“监牢”的意思是指通过chroot机制来更改某个软件运行时所能看到的根目录，简单说，就是被限制在指定目录中，保证软件只能对该目录与子目录文件有所动作，从而保证整个服务器的安全，即使被破坏或侵入，损伤也不大</p>
<p style="text-indent: 2em;">以前，unix/linux上的daemon都是以root权限启动的，当时，这是一件理所当然的事情，像apache这样的服务器软件，需要绑定到80端口上来监听请求，而root是唯一有这种权限的用户，随着攻击手段和强度的增加，这样会使服务器受到相当大的威胁，一但被利用缓冲区溢出漏洞，就可以控制整个系统。现在的服务器设计通常以root启动，然后进程放弃root权限，改为某个低级的帐号运行。这种方式显然会降低对系统的危害，但攻击者还是会寻找漏洞提升权限，即使无法获得root权限，也可以删除文件，涂改主页等</p>
<p style="text-indent: 2em;">为了进一步提高系统安全性，linux内核引入chroot机制，chroot是内核中的一个系统调用，软件可以通过调用函数库的chroot函数，来更改某个进程所能见到的跟目录，比如，apache软件安装在/usr/local/httpd目录，以root启动apache,这个root权限的父进程会派生数个以nobody权限运行的子进程，父进程监听80端口，然后交给某个子进程处理，这时候子进程所处的目录续承父进程，即/usr/local/httpd目录，但是一但目录权限设定错误，被攻击的apache子进程可以访问/usr/local , /usr ,/tmp甚至整个文件系统，因为apache进程所处的跟目录仍然是整个文件系统的跟目录，如果可以用chroot将apache限制在/usr/local/httpd/下，那么apache所存取的文件都被限制在/usr/local/httpd下，创建chroot监牢的作用就是将进程权限限制在文件目录树下，保证安全。</p>
<p style="text-indent: 2em;">如果自己手动apache的监牢，将是很烦琐和复杂的工作，需要牵扯到库文件，这里可以使用jail包来简化监牢的实现</p>
<p style="text-indent: 2em;">jail的官方网站为： <a href="http://www.jmcresearch.com/"><span style="color: #51909f;">http://www.jmcresearch.com</span></a>有兴趣可以逛逛</p>
<p style="text-indent: 2em;">这里也不写出具体的创建过程稍微麻烦，如果对安全有需要的话，请回帖，会及时补上</p>
<p style="text-indent: 2em;">九：apache服务器防范Dos</p>
<p style="text-indent: 2em;">apache服务经常会碰到Dos攻击，防范的主要手段是通过软件，apahce Dos Evasive Maneuvers Module</p>
<p style="text-indent: 2em;">来实现的，它是一款mod_access的代替软件，可以对抗DoS攻击，该软件可以快速拒绝来自相同地址对同一URL的重复请求，通过查询内部一张各子进程的哈希表来实现</p>
<p style="text-indent: 2em;">可以到网址：http://online/.securityfocus.com/tools/ 上下载软件</p>
<p style="text-indent: 2em;">十：减少CGI和SSI风险</p>
<p style="text-indent: 2em;">CGI脚本的漏洞已经成为WEB服务器的首要安全隐患，通常是程序编写CGI脚本产生了许多漏洞，控制CGI的漏洞除了在编写时候注意对输入数据的合法检查，对系统调用的谨慎使用等因素外，首先使用CGI程序所有者的ID来运行这些程序，即使被漏洞危害也仅限于该ID能访问的文件，不会对整个系统带来致命的危害，因此需要谨慎使用CGI程序。</p>
<p style="text-indent: 2em;">1.3版的apache集成了suEXEC程序，可以为apache提供CGI程序的控制支持，可以把suEXEC看做一个包装器，在Apache接到CGI程序的调用请求后，把这个请求交给suEXEC来负责完成具体调用，并从suEXEC返回结果，suEXEC可以解决一些安全问题，但会影响速度</p>
<p style="text-indent: 2em;">如果是对安全性要求很高时候，建议使用suEXEC，此外还有一个软件CGIWrap，它的安全性要高与suEXEC</p>
<p style="text-indent: 2em;">减少SSI脚本风险，如果用exec等SSI命令运行外部程序，也会存在类似CGI脚本风险，除了内部调试程序时，应使用</p>
<p style="text-indent: 2em;">option命令禁止其使用：</p>
<p style="text-indent: 2em;">Option IncludesNOEXEC</p>
<p style="text-indent: 2em;">十一：使用ssl加固Apache</p>
<p style="text-indent: 2em;">使用具有SSL功能的服务器，可以提高网站敏感页的安全性能，SSL工作与TCP/IP协议和HTTP协议之间</p>
<p style="text-indent: 2em;">SSL可以加密互联网上传递的数据流，提供身份验证，在线购物而不必担心别人窃取信用卡信息，在基于电子商务和基于web邮件的地方非常重要。</p>
<p style="text-indent: 2em;">SSL的应用相对还是比较麻烦的，有需要的话，可以发贴或查看资料，这几就不多写，篇幅不够</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2008年12月27号 -- <a href="http://ourapache.com/archives/11" title="apxs &#8211; Apache 扩展工具">apxs &#8211; Apache 扩展工具</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/117" title="让Apache按日期保存日志数据">让Apache按日期保存日志数据</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/27" title="php+mysql+apache编码深度解析">php+mysql+apache编码深度解析</a></li><li>2010年03月9号 -- <a href="http://ourapache.com/archives/316" title="htaccess二级目录重写找不到路径">htaccess二级目录重写找不到路径</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/193" title="header Content-Type类型">header Content-Type类型</a></li><li>2009年08月16号 -- <a href="http://ourapache.com/archives/288" title="Apache两种常用工作模式比较:prefork和worker">Apache两种常用工作模式比较:prefork和worker</a></li><li>2010年04月13号 -- <a href="http://ourapache.com/archives/326" title="解决linux下安装ssl后，apache重启时需要密码">解决linux下安装ssl后，apache重启时需要密码</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/64" title="Apache连接数设置prefork">Apache连接数设置prefork</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/3" title="apache的配置优化">apache的配置优化</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/312" title="apache配置（如何禁止列出目录内容）">apache配置（如何禁止列出目录内容）</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/%e5%ae%89%e5%85%a8" title="安全" rel="tag">安全</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/38/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>不再为Apache进程淤积、耗尽内存而困扰</title>
		<link>http://ourapache.com/archives/35</link>
		<comments>http://ourapache.com/archives/35#comments</comments>
		<pubDate>Tue, 06 Jan 2009 08:45:50 +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=35</guid>
		<description><![CDATA[可能有很多系统管理员都为这样的情形而困扰过：Apache进程动辄占用内存几百兆，而且剧烈浮动，变化无常，有时甚至耗掉上G内存。在访问者那里的表现就是网站速度极不稳定，间歇性抽风，有时甚至会有5-30分钟无法打开网页。这时候，你的上司或同事可能会急切地打来电话问：我们的网站怎么上不去了？我们今天还要xxxx呢！但这时你的SSH也无法像往常一样忠实地给你一个“login:”，因为它也连不上服务器了。这个时候你的服务器在做什么呢？你找出各种理由向他们解释之后，过上一段时间，网站能够正常访问了，你也终于SSH上了服务器（听起来系统管理员真没用），然后你会用dmesg或者在/var/log/messages里面发现一堆有关内存的信息，什么DMA了，HighMem了，其中会包含类似这样一行：
Out of Memory: Killed process 6760 (httpd).
它告诉你的信息是，你的服务器物理内存耗尽，也没什么好向交换区淘汰的了，只好杀掉了你的Apache的一个进程。之所以选择这个进程，基本上就是因为它占用的物理内存最多。]]></description>
			<content:encoded><![CDATA[<div id="read_tpc" class="tpc_content">
<div>本篇文章是为使用Apache+MySQL，并为Apache耗尽内存而困扰的系统管理员而写。如果您没有耐心读完本文，请参考以下步骤：</div>
<ol>
<li>修改/etc/my.cnf,加上这样一行：<br />
log-slow-queries=queries-slow.log</li>
<li>重启MySQL</li>
<li>酌情过上一段时间，执行mysqldumpslow命令，或直接查看datadir/queries-slow.log,从中找出执行超时的SQL语句。其中datadir是MySQL所有数据库的存放路径。</li>
<li>根据上一步找出的SQL语句的内容，找到相应的数据表和脚本文件，查看超时原因所在。可能的原因有：数据量确实太大，未使用索引加快查询速度，等等。但程序没写好肯定是原因之一。</li>
<li>根据查出的原因酌情解决。</li>
</ol>
<div>可能有很多系统管理员都为这样的情形而困扰过：Apache进程动辄占用内存几百兆，而且剧烈浮动，变化无常，有时甚至耗掉上G内存。在访问者那里的表现就是网站速度极不稳定，间歇性抽风，有时甚至会有5-30分钟无法打开网页。这时候，你的上司或同事可能会急切地打来电话问：我们的网站怎么上不去了？我们今天还要xxxx呢！但这时你的SSH也无法像往常一样忠实地给你一个“login:”，因为它也连不上服务器了。这个时候你的服务器在做什么呢？你找出各种理由向他们解释之后，过上一段时间，网站能够正常访问了，你也终于SSH上了服务器（听起来系统管理员真没用），然后你会用dmesg或者在/var/log/messages里面发现一堆有关内存的信息，什么DMA了，HighMem了，其中会包含类似这样一行：</div>
<div>Out of Memory: Killed process 6760 (httpd).</div>
<div>它告诉你的信息是，你的服务器物理内存耗尽，也没什么好向交换区淘汰的了，只好杀掉了你的Apache的一个进程。之所以选择这个进程，基本上就是因为它占用的物理内存最多。</div>
<div> </div>
<div>很没面子的说，我被这样的问题困扰了大半年。我曾在网上疯狂地搜索解决的办法，那些文章一般都会告诉你修改httpd.conf,把MinSpareThreads或是MaxSpareThreads或是MaxRequestsPerChild设小一点，我尝试过各种设定，都没有明显的效果。我甚至曾极端地经把MaxRequestsPerChild设为1，但是Apache的进程还是会淤积，超过ServerLimit设定值，直到耗尽内存。</div>
<div> </div>
<div>我曾经怀疑过是PHP内存泄漏，因为PHP官方不保证PHP的各种扩展是线程安全的，推荐使用prefork MPM而不是worker MPM.于是我也曾经把ThreadsPerChild设为1，因为这样每个进程也就只有一个线程，在一定意义上相当于prefork MPM，但是这种做法还是没有效果，问题依旧。</div>
<div> </div>
<div>大约一周以前，我在检查MySQL的运行状态的时候，发现有一项Slow_queries数值很高，我敏感地认识到可能是某个程序的SQL语句没有写好，而且很可能就是这样的程序导致Apache进程淤积。然后我翻阅了MySQL手册中有关<a href="http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html" target="_blank"><span style="color: #2b76b0;">Slow query log</span></a>的部分，按照那里的指示，修改/etc/my.cnf,在mysqld那一段加上如下一行：</div>
<div> </div>
<div>log-slow-queries=queries-slow.log</div>
<div> </div>
<div>重启MySQL。过上一段时间以后，用mysqldumpslow命令找出了执行超时的那条语句，根据那条查询的内容，我找出相应的脚本。那是一个留言本页面，程序确实没有写好，成了垃圾广告的乐园。有人通过这个页面向数据库里面写入了超过10万条的流言，而正常的留言还不到300条。而且这个程序里面分页的做法，居然是查询数据表里面所有10万条数据并排序，而用到的只有区区10条。竟然不使用LIMIT语句，我<a href="mailto:~@#$%"><span style="color: #2b76b0;">~@#$%</span></a>^&amp;*!后来证实这个留言本已经是废弃的了（我想也不可能是正在使用的，因为每次都执行超时，已经无法使用了），就删掉了。之后，就再也没有出现过进程淤积、内存耗尽的问题。在ThreadsPerChild=64的情况下，每个Apache进程的内存一般就几十兆，最多的时候也就只有200M,进程数量也很少超过六七个。</div>
<div> </div>
<div>历经千辛万苦，终于搞定了这个问题。在此加以总结，希望本文能够给跟我一样被程序员害惨的系统管理员们一点点帮助。</div>
</div>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年04月8号 -- <a href="http://ourapache.com/archives/238" title="apache软件体系结构  ">apache软件体系结构  </a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/181" title="Apache并发控制、查看进程数、TCP连接、压缩功能说明">Apache并发控制、查看进程数、TCP连接、压缩功能说明</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/111" title="Apache 中内存管理的三种境界 ">Apache 中内存管理的三种境界 </a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/%e5%86%85%e5%ad%98" title="内存" rel="tag">内存</a>, <a href="http://ourapache.com/archives/tag/%e8%bf%9b%e7%a8%8b" title="进程" rel="tag">进程</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/35/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apxs &#8211; Apache 扩展工具</title>
		<link>http://ourapache.com/archives/11</link>
		<comments>http://ourapache.com/archives/11#comments</comments>
		<pubDate>Sat, 27 Dec 2008 15:30:44 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[apxs]]></category>
		<category><![CDATA[扩展]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=11</guid>
		<description><![CDATA[apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具，用于编译一个或多个源程序或目标代码文件为动态共享对象，使之可以用由mod_so提供的LoadModule指令在运行时加载到Apache服务器中。
因此，要使用这个扩展机制，你的平台必须支持DSO特性，而且Apache httpd必须内建了mod_so模块。apxs工具能自动探测是否具备这样的条件。]]></description>
			<content:encoded><![CDATA[<p>apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具，用于编译一个或多个源程序或目标代码文件为动态共享对象，使之可以用由mod_so提供的LoadModule指令在运行时加载到Apache服务器中。</p>
<p>因此，要使用这个扩展机制，你的平台必须支持DSO特性，而且Apache httpd必须内建了mod_so模块。apxs工具能自动探测是否具备这样的条件，你也可以自己用这个命令手动探测：</p>
<p>$ httpd -l</p>
<p>该命令的输出列表中应该有mod_so模块。如果所有这些条件均已具备，则可以很容易地借助apxs安装你自己的DSO模块以扩展Apache服务器的功能：</p>
<p>$ <a href="http://ourapache.com/archives/tag/apxs" class="st_tag internal_tag" rel="tag" title="标签 apxs 下的日志">apxs</a> -i -a -c mod_foo.c<br />
gcc -fpic -DSHARED_MODULE -I/path/to/apache/include -c mod_foo.c<br />
ld -Bshareable -o mod_foo.so mod_foo.o<br />
cp mod_foo.so /path/to/apache/modules/mod_foo.so<br />
chmod 755 /path/to/apache/modules/mod_foo.so<br />
[activating module 'foo' in /path/to/apache/etc/httpd.conf]<br />
$ apachectl restart<br />
/path/to/apache/sbin/apachectl restart: httpd not running, trying to start<br />
[Tue Mar 31 11:27:55 1998] [debug] mod_so.c(303): loaded module foo_module<br />
/path/to/apache/sbin/apachectl restart: httpd started<br />
$ _</p>
<p>其中的参数files可以是任何C源程序文件(.c)、目标代码文件(.o)、甚至是一个库(.a)。apxs工具会根据其后缀自动编译C源程序或者连接目标代码和库。但是，使用预编译的目标代码时，必须保证它们是地址独立代码(PIC)，使之能被动态地加载。如果使用GCC编译，则应该使用 -fpic 参数；如果使用其他C编译器，则应该查阅其手册，为apxs使用相应的编译参数。</p>
<p>有关Apache对DSO的支持的详细信息，可以阅读mod_so文档，或者直接阅读src/modules/standard/mod_so.c源程序。<br />
<span style="font-size: large;">语法</span><br />
apxs -g [ -S name=value ] -n modname</p>
<p>apxs -q [ -S name=value ] query &#8230;</p>
<p>apxs -c [ -S name=value ] [ -o dsofile ] [ -I incdir ] [ -D name=value ] [ -L libdir ] [ -l libname ] [ -Wc,compiler-flags ] [ -Wl,linker-flags ] files &#8230;</p>
<p>apxs -i [ -S name=value ] [ -n modname ] [ -a ] [ -A ] dso-file &#8230;</p>
<p>apxs -e [ -S name=value ] [ -n modname ] [ -a ] [ -A ] dso-file &#8230;</p>
<p><span style="font-size: large;">一般选项</span><br />
-n modname<br />
它明确设置了 -i(安装)和 -g(模板生成)选项的模块名称。对 -g 选项，它是必须的；对 -i 选项，apxs工具会根据源代码判断，或(在失败的情况下)按文件名推测出这个模块的名称。<br />
查询选项<br />
-q<br />
查询某种apxs设置的信息。该选项的query参数可以是下列一个或多个字符串：CC, CFLAGS, CFLAGS_SHLIB, INCLUDEDIR, LD_SHLIB, LDFLAGS_SHLIB, LIBEXECDIR, LIBS_SHLIB, SBINDIR, SYSCONFDIR, TARGET 。<br />
这个参数用于手动查询某些设置。比如，要手动处理Apache的C头文件，可以在Makefile中使用：</p>
<p>INC=-I`apxs -q INCLUDEDIR`</p>
<p><span style="font-size: large;">配置选项</span><br />
-S name=value<br />
此选项可以改变apxs的上述设置。<br />
模板生成选项<br />
-g<br />
此选项生成一个名为name的子目录(见选项 -n)和其中的两个文件：一个是名为mod_name.c的样板模块源程序，可以用来建立你自己的模块，或是学习使用apxs机制的良好开端；另一个则是对应的Makefile ，用于编译和安装此模块。<br />
DSO编译选项<br />
-c<br />
此选项表示需要执行编译操作。它首先会编译C源程序(.c)files为对应的目标代码文件(.o)，然后连接这些目标代码和files中其余的目标代码文件(.o和.a)，以生成动态共享对象dsofile 。如果没有指定 -o 选项，则此输出文件名由files中的第一个文件名推测得到，也就是默认为mod_name.so 。<br />
-o dsofile<br />
明确指定所建立的动态共享对象的文件名，它不能从files文件列表中推测得到。如果没有明确指定，则其文件名将为mod_unknown.so 。<br />
-D name=value<br />
此选项直接传递到给编译命令，用于增加自定义的编译变量。<br />
-I incdir<br />
此选项直接传递到给编译命令，用于增加自定义的包含目录。<br />
-L libdir<br />
此选项直接传递到给连接命令，用于增加自定义的库文件目录。<br />
-l libname<br />
此选项直接传递到给连接命令，用于增加自定义的库文件。<br />
-Wc,compiler-flags<br />
此选项用于向编译命令 libtool &#8211;mode=compile 中附加compiler-flags ，以增加编译器特有的选项。<br />
-Wl,linker-flags<br />
此选项用于向连接命令 libtool &#8211;mode=link 中附加linker-flags ，以增加连接器特有的选项。<br />
DSO的安装和配置选项<br />
-i<br />
此选项表示需要执行安装操作，以安装一个或多个动态共享对象到服务器的modules目录中。<br />
-a<br />
此选项自动增加一个LoadModule行到httpd.conf文件中，以激活此模块，或者，如果此行已经存在，则启用之。<br />
-A<br />
与 -a 选项类似，但是它增加的LoadModule命令有一个井号前缀(#)，即此模块已经准备就绪但尚未启用。<br />
-e<br />
表示需要执行编辑操作，它可以与 -a 和 -A 选项配合使用，与 -i 操作类似，修改Apache的httpd.conf文件，但是并不安装此模块。</p>
<p><span style="font-size: large;">举例</span><br />
假设有一个扩展Apache功能的模块mod_foo.c ，使用下列命令，可以将C源程序编译为共享模块，以在运行时加载到Apache服务器中：</p>
<p>$ apxs -c mod_foo.c<br />
/path/to/libtool &#8211;mode=compile gcc &#8230; -c mod_foo.c<br />
/path/to/libtool &#8211;mode=link gcc &#8230; -o mod_foo.la mod_foo.slo<br />
$ _</p>
<p>然后，必须修改Apache的配置，以确保有一个LoadModule指令来加载此共享对象。为了简化这一步骤，apxs可以自动进行该操作，以安装此共享对象到”modules”目录，并更新httpd.conf文件，命令如下：</p>
<p>$ apxs -i -a mod_foo.la<br />
/path/to/instdso.sh mod_foo.la /path/to/apache/modules<br />
/path/to/libtool &#8211;mode=install cp mod_foo.la /path/to/apache/modules &#8230; chmod 755 /path/to/apache/modules/mod_foo.so<br />
[activating module 'foo' in /path/to/apache/conf/httpd.conf]<br />
$ _</p>
<p>如果配置文件中尚不存在，会增加下列的行：</p>
<p>LoadModule foo_module modules/mod_foo.so</p>
<p>如果你希望默认禁用此模块，可以使用 -A 选项，即：</p>
<p>$ apxs -i -A mod_foo.c</p>
<p>要快速测试apxs机制，可以建立一个Apache模块样板及其对应的Makefile ：</p>
<p>$ apxs -g -n foo<br />
Creating [DIR] foo<br />
Creating [FILE] foo/Makefile<br />
Creating [FILE] foo/modules.mk<br />
Creating [FILE] foo/mod_foo.c<br />
Creating [FILE] foo/.deps<br />
$ _</p>
<p>然后，立即可以编译此样板模块为共享对象并加载到Apache服务器中：</p>
<p>$ cd foo<br />
$ make all reload<br />
apxs -c mod_foo.c<br />
/path/to/libtool &#8211;mode=compile gcc &#8230; -c mod_foo.c<br />
/path/to/libtool &#8211;mode=link gcc &#8230; -o mod_foo.la mod_foo.slo<br />
apxs -i -a -n “foo” mod_foo.la<br />
/path/to/instdso.sh mod_foo.la /path/to/apache/modules<br />
/path/to/libtool &#8211;mode=install cp mod_foo.la /path/to/apache/modules &#8230; chmod 755 /path/to/apache/modules/mod_foo.so<br />
[activating module 'foo' in /path/to/apache/conf/httpd.conf]<br />
apachectl restart<br />
/path/to/apache/sbin/apachectl restart: httpd not running, trying to start<br />
[Tue Mar 31 11:27:55 1998] [debug] mod_so.c(303): loaded module foo_module<br />
/path/to/apache/sbin/apachectl restart: httpd started<br />
$ _</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年06月7号 -- <a href="http://ourapache.com/archives/251" title="apxs是Apache编译和安装扩展模块的工具">apxs是Apache编译和安装扩展模块的工具</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/apxs" title="apxs" rel="tag">apxs</a>, <a href="http://ourapache.com/archives/tag/%e6%89%a9%e5%b1%95" title="扩展" rel="tag">扩展</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/11/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apache的配置优化</title>
		<link>http://ourapache.com/archives/3</link>
		<comments>http://ourapache.com/archives/3#comments</comments>
		<pubDate>Sat, 27 Dec 2008 15:09:48 +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=3</guid>
		<description><![CDATA[我的这个网站架设在美国的VPS上,有1G的内存.但是今天发现服务器的内存被完全用光了,非常的惊险,连SSH链接都几乎无法建立.肯定是Apache吃光了我的内存,于是赶紧优化,内存占用大幅降低.一切终于流畅起来了.下面把我参考过的文章顺过来,给朋友们分享。]]></description>
			<content:encoded><![CDATA[<p><strong>【APACHE的工作方式】</strong></p>
<p>prefork模式（默认）<br />
这个多路处理模块(MPM)实现了一个非线程型的、预派生的web服务器，它的工作方式类似于Apache 1.3。它适合于没有线程安全库，需要避免线程兼容性问题的系统。它是要求将每个请求相互独立的情况下最好的MPM，这样若一个请求出现问题就不会影响到其他请求。</p>
<p>这个MPM具有很强的自我调节能力，只需要很少的配置指令调整。最重要的是将MaxClients设置为一个足够大的数值以处理潜在的请求高峰，同时又不能太大，以致需要使用的内存超出物理内存的大小。</p>
<p>worker模式<br />
此多路处理模块(MPM)使网络服务器支持混合的多线程多进程。由于使用线程来处理请求，所以可以处理海量请求，而系统资源的开销小于基于进程的MPM。但是，它也使用了多进程，每个进程又有多个线程，以获得基于进程的MPM的稳定性。</p>
<p><strong>【apache配置参数备注】</strong><br />
1、<a href="http://ourapache.com/archives/tag/keepalive" class="st_tag internal_tag" rel="tag" title="标签 KeepAlive 下的日志">KeepAlive</a> On/Off<br />
KeepAlive指的是保持连接活跃，类似于Mysql的永久连接。换一句话说，如果将KeepAlive设置为On，那么来自同一客户端的请求就不需要再一次连接，避免每次请求都要新建一个连接而加重服务器的负担。一般情况下，图片较多的网站应该把KeepAlive设为On。</p>
<p>2、KeepAliveTimeOut number<br />
如果第二次请求和第一次请求之间超过KeepAliveTimeOut的时间的话，第一次连接就会中断，再新建第二个连接。它的设置一般考虑图片或者JS等文件两次请求间隔，我的设置经验为3-5秒。</p>
<p>3、MaxKeepAliveRequests 100<br />
一次连接可以进行的HTTP请求的最大请求次数。将其值设为0将支持在一次连接内进行无限次的传输请求。事实上没有客户程序在一次连接中请求太多的页面，通常达不到这个上限就完成连接了。</p>
<p>4、StartServers        10<br />
设置服务器启动时建立的子进程数量。因为子进程数量动态的取决于负载的轻重,所有一般没有必要调整这个参数。</p>
<p>5、MinSpareServers     10<br />
设置空闲子进程的最小数量。所谓空闲子进程是指没有正在处理请求的子进程。如果当前空闲子进程数少于MinSpareServers ,那么Apache将以最大每秒一个的速度产生新的子进程。只有在非常繁忙机器上才需要调整这个参数。将此参数设的太大通常是一个坏主意。</p>
<p>6、MaxSpareThreads     75<br />
设置空闲子进程的最大数量。如果当前有超过MaxSpareServers数量的空闲子进程,那么父进程将杀死多余的子进程。只有在非常繁忙机器上才需要调整这个参数。将此参数设的太大通常是一个坏主意。如果你将该指令的值设置为比MinSpareServers小,Apache将会自动将其修改成”MinSpareServers+1″。</p>
<p>7、ServerLimit       2000<br />
服务器允许配置的进程数上限。只有在你需要将MaxClients设置成高于默认值256的时候才需要使用。要将此指令的值保持和MaxClients一样。修改此指令的值必须完全停止服务后再启动才能生效，以restart方式重启动将不会生效。</p>
<p>8、MaxClients        256<br />
用于伺服客户端请求的最大请求数量（最大子进程数），任何超过MaxClients限制的请求都将进入等候队列。默认值是256，如果要提高这个值必须同时提高ServerLimit的值。笔者建议将初始值设为(以Mb为单位的最大物理内存/2),然后根据负载情况进行动态调整。比如一台4G内存的机器，那么初始值就是4000/2=2000。</p>
<p>9、MaxRequestsPerChild  0<br />
apache.exe进程包括一个是父进程、一个是子进程，父进程接到访问请求后，将请求交由子进程处理。MaxRequestsPerChild这个指令设定一个独立的子进程将能处理的请求数量。在处理“MaxRequestsPerChild 数字”个请求之后，子进程将会被父进程终止，这时候子进程占用的内存就会释放，如果再有访问请求，父进程会重新产生子进程进行处理。 如果MaxRequestsPerChild缺省设为0(无限)或较大的数字(例如10000以上)可以使每个子进程处理更多的请求，不会因为不断终止、启动子进程降低访问效率，但MaxRequestsPerChild设置为0时，如果占用了200～300M内存，即使负载下来时占用的内存也不会减少。内存较大的服务器可以设置为0或较大的数字。内存较小的服务器不妨设置成30、50、100，以防内存溢出。所以一般情况下，如果你发现服务器的内存直线上升，建议修改该参数试试。</p>
<p> </p>
<p><strong>【apache的Rewrite】<br />
</strong>1、是否支持使用.htaccess文件来定义或者修改apache的设置,是否支持目录列表</p>
<div>
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Directory</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span>     Options indexes FollowSymLinks</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span> AllowOverride All</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span> <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">Directory</span><span style="color: #0000ff;">&gt;</span></pre>
<p> </p></div>
</div>
<p>2、rewrite <a href="http://ourapache.com/archives/tag/%e9%85%8d%e7%bd%ae" class="st_tag internal_tag" rel="tag" title="标签 配置 下的日志">配置</a></p>
<p>RewriteEngine on</p>
<p>RewriteCond $1 !^(index.php|images|robots.txt) #定义重写发生的条件</p>
<p>RewriteRule ^(.*)$ /index.php/$1 [L]</p>
<p>RewriteLog D:/lib/rewrite.log #设置rewrite日志文件，主要用来rewrite调试</p>
<p>RewriteLogLevel 3 #设置rewrite日志文件记录的等级，主要用来rewrite调试</p>
<p><strong></strong></p>
<p>【apache的</p>
<p><a onclick="pageTracker._trackPageview ('/outbound/www.php-oa.com');" href="http://www.php-oa.com/2008/08/20/gzipsquid.html"><strong><span style="color: #00abff;">Gzip</span></strong></a><strong>功能】</strong></p>
<p>gzip可以级大的加速网站.有时压缩比率高到80%,近来测试了一下,最少都有40%以上,还是相当不错的.在Apache2之后的版本，模块名不叫gzip，而叫mod_deflate</p>
<p>如果要开启gzip的话,一定要打开下面二个模块.</p>
<p>LoadModule headers_module modules/mod_headers.so</p>
<p>LoadModule deflate_module modules/<a href="http://ourapache.com/archives/tag/mod_deflate" class="st_tag internal_tag" rel="tag" title="标签 mod_deflate 下的日志">mod_deflate</a>.so</p>
<p>设置压缩比率，取值范围在 1(最低) 到 9(最高)之间,不建议设置太高，虽然有很高的压缩率，但是占用更多的CPU资源.</p>
<div>
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> DeflateCompressionLevel 3</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span> AddOutputFilter DEFLATE html xml php js css</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span> <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Location</span> <span style="color: #0000ff;">/&gt;</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span> SetOutputFilter DEFLATE</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   5:</span> BrowserMatch ^Mozilla/4 gzip-only-text/html</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   6:</span> BrowserMatch ^Mozilla/4.0[678] no-gzip</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   7:</span> BrowserMatch bMSIE !no-gzip !gzip-only-text/html</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   8:</span> SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">   9:</span> SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #606060;">  10:</span> SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary</pre>
<p> </p></div>
</div>
<p>Header append Vary User-Agent env=!dont-vary #对代理的设置</p>
<p>&lt;/Location&gt;</p>
<p>下面二个测试网站</p>
<p>http://www.whatsmyip.org/mod_gzip_test/</p>
<p>http://www.gidnetwork.com/tools/gzip-test.php</p>
<p>测试数据对css</p>
<p>Original Size: 44 KB</p>
<p>Gzipped Size: 10 KB</p>
<p>Data Savings: 77.27%</p>
<p>测试数据js</p>
<p>Original Size: 6 KB</p>
<p>Gzipped Size: 2 KB</p>
<p>Data Savings: 66.67%</p>
<p>测试数据php</p>
<p>Original Size: 62 KB</p>
<p>Gzipped Size: 15 KB</p>
<p>Data Savings: 75.81%</p>
<p>上面只是随机拿的几个数据,看的出来,使用了gzip压缩后文件小多了.</p>
<p>另外讲一下,有关squid对gzip的处理</p>
<p>在squid中，对同一个URL只保留一份缓存。对于如果不同browser(是否支持压缩)如果频繁交替访问,例如:对某个cache住的目标，一个http/1.0请求可能会导致squid强制更新其缓存。但接下来的另一个http/1.1请求又会导致squid再次更新缓存。这样那squid缓存数据就要频繁更新,这就极大的降低了cache命中率。</p>
<p>不过还好,现实环境中不支持压缩的browser毕竟是很少的情况,所以对于缓存命中率的降低很有限.</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年03月9号 -- <a href="http://ourapache.com/archives/318" title="Apache2中俩种设置PHP的异同">Apache2中俩种设置PHP的异同</a></li><li>2009年02月26号 -- <a href="http://ourapache.com/archives/184" title="Apache日志文件（配置和管理）">Apache日志文件（配置和管理）</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/123" title="Apache高级配置中文详解">Apache高级配置中文详解</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/109" title="谈谈Apache的优化">谈谈Apache的优化</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/66" title="Apache配置文件(httpd.conf)中文说明">Apache配置文件(httpd.conf)中文说明</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/9" title="apache禁止使用IP访问的实现方法">apache禁止使用IP访问的实现方法</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li><li>2008年12月25号 -- <a href="http://ourapache.com/archives/1" title="使用gzip将你的Apache速度提高十倍">使用gzip将你的Apache速度提高十倍</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/%e4%bc%98%e5%8c%96" title="优化" rel="tag">优化</a>, <a href="http://ourapache.com/archives/tag/%e9%85%8d%e7%bd%ae" title="配置" rel="tag">配置</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

