<?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"
	>

<channel>
	<title>BLOG家园 &#187; 学习笔记</title>
	<atom:link href="http://shunz.net/category/tech/feed" rel="self" type="application/rss+xml" />
	<link>http://shunz.net</link>
	<description>知识的积累与共享！</description>
	<pubDate>Wed, 05 Nov 2008 13:55:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>加速yum</title>
		<link>http://shunz.net/2008/10/fast_yum.html</link>
		<comments>http://shunz.net/2008/10/fast_yum.html#comments</comments>
		<pubDate>Fri, 17 Oct 2008 13:05:55 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[axel]]></category>

		<category><![CDATA[axelget]]></category>

		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://shunz.net/?p=569</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2008/10/fast_yum.html用yum更新系统是一件很痛苦的... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2008/10/fast_yum.html">http://shunz.net/2008/10/fast_yum.html</a></p><p>用yum更新系统是一件很痛苦的事情，缓慢的进度都让你想把鼠标扔出去。不过我们通过两个办法就能极大地提高yum安装软件的速度。</p>
<p>首先，安装yum-fastestmirror插件</p>
<blockquote><p>
yum -y install yum-fastestmirror
</p></blockquote>
<p>然后，安装多线程下载工具axel</p>
<blockquote><p>
wget http://alioth.debian.org/frs/download.php/2621/axel-2.2.tar.bz2<br />
bzip2 -d axel-2.2.tar.bz2<br />
tar xvf axel-2.2.tar<br />
cd axel<br />
./configure<br />
make &#038;&#038; make install
</p></blockquote>
<p>最后，安装yum的axelget插件</p>
<blockquote><p>
svn co http://cnfreesoft.googlecode.com/svn/trunk/axelget/ /etc/yum/axelget<br />
cd /etc/yum/pluginconf.d/<br />
ln -s /etc/yum/axelget/axelget.conf .<br />
cd /usr/lib/yum-plugins/<br />
ln -s /etc/yum/axelget/axelget.py .
</p></blockquote>
<p>修改/etc/yum.conf，设置plugins=1，一切搞定，运行yum -y update，享受一下高速的感觉吧。最后，感谢wesley写的<a href="http://wesleywang.cn/blog/?page_id=34" target="_blank">axelget插件</a>。</p>
<h3>随机网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2005/06/224.html" title="《疯狂青蛙》Crazy Frog - Axel F">《疯狂青蛙》Crazy Frog - Axel F</a></li>
<li><a href="http://shunz.net/2006/02/google%e5%bc%80%e9%80%9a%e4%b8%ad%e6%96%87blog.html" title="Google开通中文BLOG">Google开通中文BLOG</a></li>
<li><a href="http://shunz.net/2008/10/kaixin.html" title="真假开心网大PK">真假开心网大PK</a></li>
<li><a href="http://shunz.net/2007/12/system_nanfang.html" title="系统——南方周末被和谐的特稿">系统——南方周末被和谐的特稿</a></li>
<li><a href="http://shunz.net/2005/03/144.html" title="我们应该怎样看待中药">我们应该怎样看待中药</a></li>
<li><a href="http://shunz.net/2006/02/qiannvyouhun.html" title="倩女幽魂◎七世怨侣和七世姻缘的故事[转载]">倩女幽魂◎七世怨侣和七世姻缘的故事[转载]</a></li>
<li><a href="http://shunz.net/2005/03/152.html" title="Yahoo!360°试用小记">Yahoo!360°试用小记</a></li>
<li><a href="http://shunz.net/2004/12/59.html" title=" 一个人无法两次踏入同一条河 &#8212; 也谈克隆"> 一个人无法两次踏入同一条河 &#8212; 也谈克隆</a></li>
<li><a href="http://shunz.net/2006/08/spirulina.html" title="螺旋藻是健康食品吗？">螺旋藻是健康食品吗？</a></li>
<li><a href="http://shunz.net/2005/01/63.html" title="搜索引擎不收录网站内容的常见原因">搜索引擎不收录网站内容的常见原因</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2008 |
	  <a href="http://shunz.net/2008/10/fast_yum.html">加速yum</a> |
	  <a href="http://shunz.net/2008/10/fast_yum.html#comments">2条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2008/10/fast_yum.html&amp;title=加速yum">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2008/10/fast_yum.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2008/10/fast_yum.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>KB951748补丁引起的网络连接故障解决</title>
		<link>http://shunz.net/2008/08/kb951748.html</link>
		<comments>http://shunz.net/2008/08/kb951748.html#comments</comments>
		<pubDate>Sun, 03 Aug 2008 00:54:21 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[KB951748]]></category>

		<category><![CDATA[win]]></category>

		<category><![CDATA[windows]]></category>

		<category><![CDATA[winxp]]></category>

		<guid isPermaLink="false">http://shunz.net/?p=542</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2008/08/kb951748.html最近碰到一件怪事，单位的多... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2008/08/kb951748.html">http://shunz.net/2008/08/kb951748.html</a></p><p>最近碰到一件怪事，单位的多台电脑都无法上网了，查看网络连接发现连接状态全部是空的，将网卡驱动删除重新安装也没有任何作用，百思不得其解之际，突然想到最近的DNS漏洞问题，难道是因为这个漏洞补丁的问题？<br />
<span id="more-542"></span><br />
查看了一下360安全卫士的漏洞补丁记录，发现KB951748补丁安装失败，看来是瑞星阻止了这个补丁的安装，将瑞星监控停止，重新安装补丁，这次成功安装上了，但是故障依旧。</p>
<p>在控制面板将KB951748更新卸载，重启后，故障消失，很明显，是这个补丁造成的故障。但是为什么补丁更新后就出现网络故障呢？难道这个补丁有问题？可是我自己的笔记本也打过这个补丁，却没有任何问题。</p>
<p>看来应该是这个补丁和什么东西有冲突，我发现有故障的这台电脑还装了360安全卫士的antiarp防火墙，难道是这个的问题？将AntiARP防火墙关掉，重新安装KB951748，重启后，故障解除，搞定！</p>
<h3>随机网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2004/03/26.html" title="上传哈耶克大作《致命的自负》">上传哈耶克大作《致命的自负》</a></li>
<li><a href="http://shunz.net/2008/09/im-back.html" title="I&#8217;m Back!">I&#8217;m Back!</a></li>
<li><a href="http://shunz.net/2006/06/26_steps_seo.html" title="26步获得网站流量">26步获得网站流量</a></li>
<li><a href="http://shunz.net/2004/12/59.html" title=" 一个人无法两次踏入同一条河 &#8212; 也谈克隆"> 一个人无法两次踏入同一条河 &#8212; 也谈克隆</a></li>
<li><a href="http://shunz.net/2005/01/97.html" title="顺子(shunza) - 回家 - music - mp3">顺子(shunza) - 回家 - music - mp3</a></li>
<li><a href="http://shunz.net/2005/05/188.html" title="欧盟要求取消转基因玉米禁令">欧盟要求取消转基因玉米禁令</a></li>
<li><a href="http://shunz.net/2005/01/94.html" title="2004中国十大科技骗局">2004中国十大科技骗局</a></li>
<li><a href="http://shunz.net/2005/06/239.html" title="我对awTags模块的修改">我对awTags模块的修改</a></li>
<li><a href="http://shunz.net/2005/02/128.html" title="北京市住房贷款担保中心提供担保方式的办理程序">北京市住房贷款担保中心提供担保方式的办理程序</a></li>
<li><a href="http://shunz.net/2006/01/%e5%91%a8%e6%81%a9%e6%9d%a5.html" title="纪念一位三十年前逝世的伟人">纪念一位三十年前逝世的伟人</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2008 |
	  <a href="http://shunz.net/2008/08/kb951748.html">KB951748补丁引起的网络连接故障解决</a> |
	  <a href="http://shunz.net/2008/08/kb951748.html#comments">4条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2008/08/kb951748.html&amp;title=KB951748补丁引起的网络连接故障解决">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2008/08/kb951748.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2008/08/kb951748.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>使用Siege进行WEB压力测试</title>
		<link>http://shunz.net/2008/07/siege.html</link>
		<comments>http://shunz.net/2008/07/siege.html#comments</comments>
		<pubDate>Sat, 26 Jul 2008 08:22:31 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[siege]]></category>

		<category><![CDATA[web]]></category>

		<category><![CDATA[web压力测试]]></category>

		<category><![CDATA[压力测试]]></category>

		<guid isPermaLink="false">http://shunz.net/?p=540</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2008/07/siege.html虽然Apache自带一个压力测试工具a... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2008/07/siege.html">http://shunz.net/2008/07/siege.html</a></p><p>虽然Apache自带一个压力测试工具ab，但是ab的功能太简单了，无法模拟真实的web访问，所以我们要用到更加强大的web压力测试工具——Siege（英文原意：围攻）。</p>
<p>首先，进行安装：</p>
<pre class="prettyprint">wget ftp://ftp.joedog.org/pub/siege/siege-latest.tar.gz
tar zxvf siege-latest.tar.gz
cd siege-2.67
./configure
make &amp;&amp; make install</pre>
<p><span id="more-540"></span></p>
<p>安装完成后，就可以开始进行压力测试了<br />
修改siege配置<br />
vi ~/.siegerc<br />
调整：</p>
<pre class="prettyprint">verbose = false
concurrent = 50
delay = 1
internet = true
benchmark = true</pre>
<p>siege参数介绍：</p>
<p>* -cNUM</p>
<p>设置并发的用户（连接）数量，比如-c10,设置并发10个连接。默认的连接数量可以到~/.siegerc中查看，指令为concurrent = x，前面咱们已经调整了默认并发连接为50。</p>
<p>* -rNUM</p>
<p>（repetitions），重复数量，即每个连接发出的请求数量，设置这个的话，就不需要设置-t了。对应.siegerc配置文件中的reps = x指令</p>
<p>* -tNUM</p>
<p>（time），持续时间，即测试持续时间，在NUM时间后结束，单位默认为分，比如-t10，那么测试时间为10分钟，-t10s，则测试时间为10秒钟。对应.siegerc中的指令为time = x指令</p>
<p>* -b</p>
<p>(benchmark),基准测试，如果设置这个参数的话，那么delay时间为0。在.siegerc中咱们修改为默认开启。</p>
<p>* -f url.txt</p>
<p>(file),这是url列表文件。对应.siegerc配置文件中的file = x指令</p>
<p>测试结果分析：</p>
<pre class="prettyprint">[root@bbs ~]# siege -c 500 -r 50 -f shunz.net.url
** SIEGE 2.67
** Preparing 500 concurrent users for battle.
The server is now under siege..      done.
Transactions:                  25000 hits
Availability:                 100.00 %
Elapsed time:                  65.52 secs
Data transferred:              83.65 MB
Response time:                  0.57 secs
Transaction rate:             381.56 trans/sec
Throughput:                     1.28 MB/sec
Concurrency:                  216.02
Successful transactions:       21707
Failed transactions:               0
Longest transaction:            5.83
Shortest transaction:           0.00</pre>
<p>上面是用500并发重复测试50次shunz.net.url里的url列表的结果，下面一条一条地分析测试结果：<br />
Transactions:                  25000 hits<br />
意思是总共完成了25000次测试<br />
Availability:                 100.00 %<br />
测试的有效性100%<br />
Elapsed time:                  65.52 secs<br />
用时65.52秒<br />
Data transferred:              83.65 MB<br />
传输了83.65MB数据<br />
Response time:                  0.57 secs<br />
响应时间<br />
Transaction rate:             381.56 trans/sec<br />
每秒传输381.56次<br />
Throughput:                     1.28 MB/sec<br />
数据吞吐量每秒1.28MB<br />
Concurrency:                  216.02<br />
实际并发访问<br />
Successful transactions:       21707<br />
成功的传输<br />
Failed transactions:               0<br />
失败的传输<br />
Longest transaction:            5.83<br />
每次传输所花最长时间<br />
Shortest transaction:           0.00<br />
每次传输所花最短时间</p>
<p>另外，提醒一句，如果你的WEB服务器用的是Apache，请不要将并发数设为大于200。<br />
<h3>相关网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2008/07/nginx_log_rotation.html" title="Nginx的日志回滚">Nginx的日志回滚</a></li>
<li><a href="http://shunz.net/2008/07/nginx_rewrite.html" title="Nginx的Rewrite设置及示例">Nginx的Rewrite设置及示例</a></li>
<li><a href="http://shunz.net/2008/06/mysql_discuz_.html" title="百万记录级MySQL数据库及Discuz!论坛优化">百万记录级MySQL数据库及Discuz!论坛优化</a></li>
<li><a href="http://shunz.net/2007/02/apache-mod_ssl.html" title="apache+mod_ssl中证书生成方法">apache+mod_ssl中证书生成方法</a></li>
<li><a href="http://shunz.net/2007/02/apache-mysql-subversion.html" title="Apache+Subversion安装笔记">Apache+Subversion安装笔记</a></li>
<li><a href="http://shunz.net/2006/06/find_css_master_hand.html" title="寻找css高手">寻找css高手</a></li>
<li><a href="http://shunz.net/2005/12/firefox.html" title="今天为Firefox抓狂！">今天为Firefox抓狂！</a></li>
<li><a href="http://shunz.net/2004/12/45.html" title="apache 2.0 中文手册学习">apache 2.0 中文手册学习</a></li>
<li><a href="http://shunz.net/2004/12/44.html" title="apache的静态/动态编译在apache+php+mysql+gd中的应用">apache的静态/动态编译在apache+php+mysql+gd中的应用</a></li>
<li><a href="http://shunz.net/2004/03/7.html" title="关于apache的rewrite应用">关于apache的rewrite应用</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2008 |
	  <a href="http://shunz.net/2008/07/siege.html">使用Siege进行WEB压力测试</a> |
	  <a href="http://shunz.net/2008/07/siege.html#comments">5条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2008/07/siege.html&amp;title=使用Siege进行WEB压力测试">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2008/07/siege.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2008/07/siege.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>如何让Firefox扩展支持兼容更高版本</title>
		<link>http://shunz.net/2008/07/firefox_plugin_compatibility.html</link>
		<comments>http://shunz.net/2008/07/firefox_plugin_compatibility.html#comments</comments>
		<pubDate>Fri, 18 Jul 2008 08:38:30 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[软件测评]]></category>

		<category><![CDATA[extensions]]></category>

		<category><![CDATA[firefox]]></category>

		<category><![CDATA[扩展]]></category>

		<guid isPermaLink="false">http://shunz.net/?p=537</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2008/07/firefox_plugin_compatibility.htmlFirefox刚刚升级... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2008/07/firefox_plugin_compatibility.html">http://shunz.net/2008/07/firefox_plugin_compatibility.html</a></p><p>Firefox刚刚升级到了3.0.1，Tab Mix Plus扩展在firefox版本升级后又被禁用了，作者目前还没有新的版本出来，没办法，只好自己想办法了，其实要想让已经安装的扩展支持更高版本的Firefox，办法很简单：</p>
<blockquote><p>
直接修改extensions目录下相应扩展目录下的install.rdf文件（用记事本打开），将maxVersion值调高一些即可。
</p></blockquote>
<h3>相关网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2008/03/firefox3.html" title="如何在保留现有扩展和配置的前提下升级到Firefox3 b4">如何在保留现有扩展和配置的前提下升级到Firefox3 b4</a></li>
<li><a href="http://shunz.net/2007/08/firefox_sina.html" title="Firefox无法打开新浪的原因">Firefox无法打开新浪的原因</a></li>
<li><a href="http://shunz.net/2006/12/firefox-2.html" title="Firefox升级到2.0.0.1">Firefox升级到2.0.0.1</a></li>
<li><a href="http://shunz.net/2006/11/firefox_gift.html" title="收到Yupoo寄来Firefox的T-shirt">收到Yupoo寄来Firefox的T-shirt</a></li>
<li><a href="http://shunz.net/2006/10/firefox_20.html" title="Firefox 2.0 Release!">Firefox 2.0 Release!</a></li>
<li><a href="http://shunz.net/2006/01/firefox15.html" title="用上了FireFox1.5">用上了FireFox1.5</a></li>
<li><a href="http://shunz.net/2005/10/313.html" title="如何将Firefox配置文件转移到其他机器上？">如何将Firefox配置文件转移到其他机器上？</a></li>
<li><a href="http://shunz.net/2005/05/202.html" title="回到firefox的阵营兼谈我使用的firefox插件">回到firefox的阵营兼谈我使用的firefox插件</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2008 |
	  <a href="http://shunz.net/2008/07/firefox_plugin_compatibility.html">如何让Firefox扩展支持兼容更高版本</a> |
	  <a href="http://shunz.net/2008/07/firefox_plugin_compatibility.html#comments">8条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2008/07/firefox_plugin_compatibility.html&amp;title=如何让Firefox扩展支持兼容更高版本">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2008/07/firefox_plugin_compatibility.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>,  <a href="http://shunz.net/category/software" title="View all posts in 软件测评" rel="category tag">软件测评</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2008/07/firefox_plugin_compatibility.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>在Nginx环境下用Perl FastCGI支持Awstats</title>
		<link>http://shunz.net/2008/07/nginx_perl_fastcgi.html</link>
		<comments>http://shunz.net/2008/07/nginx_perl_fastcgi.html#comments</comments>
		<pubDate>Sun, 13 Jul 2008 07:19:21 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[awstats]]></category>

		<category><![CDATA[cgi]]></category>

		<category><![CDATA[fastcgi]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[nginx]]></category>

		<category><![CDATA[perl]]></category>

		<category><![CDATA[perl_fastcgi]]></category>

		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://shunz.net/?p=533</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2008/07/nginx_perl_fastcgi.html日志统计分析软件Awstat... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2008/07/nginx_perl_fastcgi.html">http://shunz.net/2008/07/nginx_perl_fastcgi.html</a></p><p>日志统计分析软件Awstats需要Perl支持，但是Nginx内建的Perl模块目前还并不稳定，经常会出问题，所以还是用FastCGI模式运行Perl比较可靠。下面就谈谈如何在Nginx下配置Perl的FastCGI模式：</p>
<p>首先，安装Perl的FastCGI模块：</p>
<pre class="prettyprint">
wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.tar.gz
tar zxvf FCGI-0.67.tar.gz
cd FCGI-0.67
perl Makefile.PL
make &amp;&amp; make install
</pre>
<p>其实也可以用这种方法：#perl -MCPAN -e &#8216;install FCGI&#8217;<br />
<span id="more-533"></span><br />
然后，配置Perl的FastCGI脚本（从网上找到的，未找到原始出处）：</p>
<pre class="prettyprint">
#!/usr/bin/perl
use FCGI;
use Socket;
use POSIX qw(setsid);
require 'syscall.ph';
&daemonize;
END() { } BEGIN() { }
*CORE::GLOBAL::exit = sub { die "fakeexit\nrc=".shift()."\n"; };
eval q{exit};
if ($@) {
        exit unless $@ =~ /^fakeexit/;
};
&main;
sub daemonize() {
    chdir '/' or die "Can't chdir to /: $!";
    defined(my $pid = fork) or die "Can't fork: $!";
    exit if $pid;
    setsid or die "Can't start a new session: $!";
    umask 0;
}
sub main {
        $socket = FCGI::OpenSocket( "/tmp/perl_fastcgi.sock", 10 );
        $request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket );
        if ($request) { request_loop()};
            FCGI::CloseSocket( $socket );
}
sub request_loop {
        while( $request->Accept() >= 0 ) {
           $stdin_passthrough ='';
           $req_len = 0 + $req_params{'CONTENT_LENGTH'};
           if (($req_params{'REQUEST_METHOD'} eq 'POST') &#038;&#038; ($req_len != 0) ){
                my $bytes_read = 0;
                while ($bytes_read < $req_len) {
                        my $data = '';
                        my $bytes = read(STDIN, $data, ($req_len - $bytes_read));
                        last if ($bytes == 0 || !defined($bytes));
                        $stdin_passthrough .= $data;
                        $bytes_read += $bytes;
                }
            }
            if ( (-x $req_params{SCRIPT_FILENAME}) &#038;&#038;
                 (-s $req_params{SCRIPT_FILENAME}) &#038;&#038;
                 (-r $req_params{SCRIPT_FILENAME})
            ){
                pipe(CHILD_RD, PARENT_WR);
                my $pid = open(KID_TO_READ, "-|");
                unless(defined($pid)) {
                        print("Content-type: text/plain\r\n\r\n");
                        print "Error: CGI app returned no output - Executing $req_params{SCRIPT_FILENAME} failed !\n";
                        next;
                }
                if ($pid > 0) {
                        close(CHILD_RD);
                        print PARENT_WR $stdin_passthrough;
                        close(PARENT_WR);
                        while(my $s = <KID_TO_READ>) { print $s; }
                        close KID_TO_READ;
                        waitpid($pid, 0);
                } else {
                        foreach $key ( keys %req_params){
                           $ENV{$key} = $req_params{$key};
                        }
                        if ($req_params{SCRIPT_FILENAME} =~ /^(.*)\/[^\/]+$/) {
                                chdir $1;
                        }
                        close(PARENT_WR);
                        close(STDIN);
                        syscall(&#038;SYS_dup2, fileno(CHILD_RD), 0);
                        exec($req_params{SCRIPT_FILENAME});
                        die("exec failed");
                }
            }
            else {
                print("Content-type: text/plain\r\n\r\n");
                print "Error: No such CGI app - $req_params{SCRIPT_FILENAME} may not exist or is not executable by this process.\n";
            }

        }
}
</pre>
<p>将权限改为可执行，并执行之。</p>
<p>配置nginx.conf，使之支持perl脚本：</p>
<pre class="prettyprint">
location ~* .*\.pl$
{
       include awstats.conf;
}
</pre>
<p>编辑awstats.conf</p>
<pre  class="prettyprint">
fastcgi_pass  unix:/tmp/perl_fastcgi.sock;
fastcgi_index awstats.pl;
fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING     $query_string;
fastcgi_param REQUEST_METHOD   $request_method;
fastcgi_param CONTENT_TYPE     $content_type;
fastcgi_param CONTENT_LENGTH   $content_length;
fastcgi_param GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param SERVER_SOFTWARE    nginx;
fastcgi_param SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param REQUEST_URI        $request_uri;
fastcgi_param DOCUMENT_URI       $document_uri;
fastcgi_param DOCUMENT_ROOT      $document_root;
fastcgi_param SERVER_PROTOCOL    $server_protocol;
fastcgi_param REMOTE_ADDR        $remote_addr;
fastcgi_param REMOTE_PORT        $remote_port;
fastcgi_param SERVER_ADDR        $server_addr;
fastcgi_param SERVER_PORT        $server_port;
fastcgi_param SERVER_NAME        $server_name;
fastcgi_read_timeout 60;
</pre>
<p>然后重启nginx：<br />
#service nginx restart</p>
<h3>相关网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2008/07/nginx_rewrite.html" title="Nginx的Rewrite设置及示例">Nginx的Rewrite设置及示例</a></li>
<li><a href="http://shunz.net/2008/06/mysql_discuz_.html" title="百万记录级MySQL数据库及Discuz!论坛优化">百万记录级MySQL数据库及Discuz!论坛优化</a></li>
<li><a href="http://shunz.net/2008/07/nginx_log_rotation.html" title="Nginx的日志回滚">Nginx的日志回滚</a></li>
<li><a href="http://shunz.net/2007/02/apache-mysql-subversion.html" title="Apache+Subversion安装笔记">Apache+Subversion安装笔记</a></li>
<li><a href="http://shunz.net/2006/12/add_swap_partition_size.html" title="SWAP分区太小的补救措施">SWAP分区太小的补救措施</a></li>
<li><a href="http://shunz.net/2006/07/how_to_install_livecd_into_hdd.html" title="将Gentoo LiveCD系统复制到硬盘HOWTO">将Gentoo LiveCD系统复制到硬盘HOWTO</a></li>
<li><a href="http://shunz.net/2006/07/how_to_select_linux_distribution.html" title="根据需求选择合适的Linux发行版本">根据需求选择合适的Linux发行版本</a></li>
<li><a href="http://shunz.net/2006/06/linux_muti_ip.html" title="Linux单网卡绑定多IP与多网卡共用单IP的实现方法">Linux单网卡绑定多IP与多网卡共用单IP的实现方法</a></li>
<li><a href="http://shunz.net/2006/06/gentoo_upgrade.html" title="升级gentoo碰到的几个问题及解决办法">升级gentoo碰到的几个问题及解决办法</a></li>
<li><a href="http://shunz.net/2005/12/freebsd_change_to_gentoo.html" title="服务器系统从Freebsd更换到Gentoo">服务器系统从Freebsd更换到Gentoo</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2008 |
	  <a href="http://shunz.net/2008/07/nginx_perl_fastcgi.html">在Nginx环境下用Perl FastCGI支持Awstats</a> |
	  <a href="http://shunz.net/2008/07/nginx_perl_fastcgi.html#comments">1条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2008/07/nginx_perl_fastcgi.html&amp;title=在Nginx环境下用Perl FastCGI支持Awstats">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2008/07/nginx_perl_fastcgi.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2008/07/nginx_perl_fastcgi.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Nginx的日志回滚</title>
		<link>http://shunz.net/2008/07/nginx_log_rotation.html</link>
		<comments>http://shunz.net/2008/07/nginx_log_rotation.html#comments</comments>
		<pubDate>Thu, 10 Jul 2008 01:04:36 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[c10k]]></category>

		<category><![CDATA[epoll]]></category>

		<category><![CDATA[nginx]]></category>

		<category><![CDATA[Rotation]]></category>

		<category><![CDATA[日志]]></category>

		<category><![CDATA[日志回滚]]></category>

		<guid isPermaLink="false">http://shunz.net/?p=532</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2008/07/nginx_log_rotation.htmlNginx是一款采用Linux 2.6... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2008/07/nginx_log_rotation.html">http://shunz.net/2008/07/nginx_log_rotation.html</a></p><p>Nginx是一款采用Linux 2.6内核epoll新机制开发的Web服务器软件，能极大地提高Web访问特别是小文件访问的I/O性能，是<a title="c10k" href="http://www.google.com/search?hl=en&amp;q=c10k" target="_blank">c10k</a>问题的一个解决方案。有测试称Nginx比Apache效率提高10倍，而从<a href="http://shunz.net/2008/06/mysql_discuz_.html">我自己上次的测试</a>来看，其并发性能确实比Apache强不少。Nginx以短小精悍著称，所以虽然一些web核心功能他都支持得挺好，但是一些扩展功能却还不能支持，比如Nginx目前就还不支持通过pipe输出log，所以就不支持利用cronolog来按时间进行日志截断回滚。下面提供一种替代解决方案：<br />
<span id="more-532"></span></p>
<pre class="prettyprint">
#!/bin/sh
log_dir="/var/log/httpd"
yesterday=`date +%Y%m%d -d '-1 day'`
lastday =`date +%Y%m%d -d '-1 month'`
/bin/rm ${log_dir}/access.${lastday}.log
/bin/rm ${log_dir}/error.${lastday}.log
/bin/mv ${log_dir}/access.log ${log_dir}/access.${yesterday}.log
/bin/mv ${log_dir}/error.log ${log_dir}/error.${yesterday}.log
kill -USR1 `cat /var/run/nginx.pid`
/bin/gzip ${log_dir}/access.${yesterday}.log &amp;
/bin/gzip ${log_dir}/error.${yesterday}.log &amp;</pre>
<p>然后将该脚本保存在/etc/cron.daily目录里，或者在crontab里每日0点时运行。<br />
另外，还可以结合awstats进行日志分析，这里就不详细说了，可以参考<a href="http://www.chedong.com/tech/awstats.html" target="_blank">车东的相关文章</a>。<br />
<h3>相关网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2008/07/siege.html" title="使用Siege进行WEB压力测试">使用Siege进行WEB压力测试</a></li>
<li><a href="http://shunz.net/2008/07/nginx_perl_fastcgi.html" title="在Nginx环境下用Perl FastCGI支持Awstats">在Nginx环境下用Perl FastCGI支持Awstats</a></li>
<li><a href="http://shunz.net/2008/07/nginx_rewrite.html" title="Nginx的Rewrite设置及示例">Nginx的Rewrite设置及示例</a></li>
<li><a href="http://shunz.net/2008/06/mysql_discuz_.html" title="百万记录级MySQL数据库及Discuz!论坛优化">百万记录级MySQL数据库及Discuz!论坛优化</a></li>
<li><a href="http://shunz.net/2007/02/apache-mod_ssl.html" title="apache+mod_ssl中证书生成方法">apache+mod_ssl中证书生成方法</a></li>
<li><a href="http://shunz.net/2007/02/apache-mysql-subversion.html" title="Apache+Subversion安装笔记">Apache+Subversion安装笔记</a></li>
<li><a href="http://shunz.net/2006/11/baiduspider.html" title="匿名盗抓的Baidu Spider">匿名盗抓的Baidu Spider</a></li>
<li><a href="http://shunz.net/2005/12/firefox.html" title="今天为Firefox抓狂！">今天为Firefox抓狂！</a></li>
<li><a href="http://shunz.net/2004/12/45.html" title="apache 2.0 中文手册学习">apache 2.0 中文手册学习</a></li>
<li><a href="http://shunz.net/2004/12/44.html" title="apache的静态/动态编译在apache+php+mysql+gd中的应用">apache的静态/动态编译在apache+php+mysql+gd中的应用</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2008 |
	  <a href="http://shunz.net/2008/07/nginx_log_rotation.html">Nginx的日志回滚</a> |
	  <a href="http://shunz.net/2008/07/nginx_log_rotation.html#comments">5条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2008/07/nginx_log_rotation.html&amp;title=Nginx的日志回滚">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2008/07/nginx_log_rotation.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2008/07/nginx_log_rotation.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Nginx的Rewrite设置及示例</title>
		<link>http://shunz.net/2008/07/nginx_rewrite.html</link>
		<comments>http://shunz.net/2008/07/nginx_rewrite.html#comments</comments>
		<pubDate>Sat, 05 Jul 2008 14:57:54 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[nginx]]></category>

		<category><![CDATA[rewrite]]></category>

		<category><![CDATA[server]]></category>

		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://shunz.net/?p=531</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2008/07/nginx_rewrite.htmlNginx以其良好的并发性能，... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2008/07/nginx_rewrite.html">http://shunz.net/2008/07/nginx_rewrite.html</a></p><p>Nginx以其良好的并发性能，目前正在逐渐取代Apache成为大家的Web server首选，但是Nginx目前的中文资料很少，需要大家努力贡献。</p>
<p>下面我介绍一下Nginx的Rewrite模块设置及Wordpress和Discuz的示例。Nginx的Rewrite规则比Apache的简单灵活多了，从下面介绍可见一斑。</p>
<p><span id="more-531"></span>首先，Nginx可以用if进行条件匹配，语法规则类似C，举例如下：</p>
<pre class="prettyprint">
if ($http_user_agent ~ MSIE) {
rewrite  ^(.*)$  /msie/$1  break;
}
</pre>
<p>1、正则表达式匹配，其中：</p>
<ul>
<li> ~  为区分大小写匹配</li>
<li> ~* 为不区分大小写匹配</li>
<li> !~和!~*分别为区分大小写不匹配及不区分大小写不匹配</li>
</ul>
<p>2、文件及目录匹配，其中：</p>
<ul>
<li> -f和!-f用来判断是否存在文件</li>
<li> -d和!-d用来判断是否存在目录</li>
<li> -e和!-e用来判断是否存在文件或目录</li>
<li> -x和!-x用来判断文件是否可执行</li>
</ul>
<p>如：</p>
<pre class="prettyprint">
if (!-f $request_filename) {
proxy_pass  http://127.0.0.1;
}
</pre>
<p>其次，Nginx的Rewrite规则与Apache几乎完全一致，所不同的是最后的flag标记，举例如下：</p>
<blockquote><p>rewrite ^/feed/$ http://feed.shunz.net last;</p></blockquote>
<p>flag标记有：</p>
<ul>
<li>last 相当于Apache里的[L]标记，表示完成rewrite，不再匹配后面的规则</li>
<li>break 与last类似</li>
<li>redirect 返回302临时重定向</li>
<li>permanent 返回301永久重定向</li>
</ul>
<p>Wordpress的重定向规则：</p>
<pre class="prettyprint">
if (!-e $request_filename) {
rewrite ^/(index|atom|rsd)\.xml$ http://feed.shunz.net last;
rewrite ^([_0-9a-zA-Z-]+)?(/wp-.*) $2 last;
rewrite ^([_0-9a-zA-Z-]+)?(/.*\.php)$ $2 last;
rewrite ^ /index.php last;
}
</pre>
<p>Discuz!的重定向规则：</p>
<pre class="prettyprint">
if (!-f $request_filename) {
rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$   /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$   /forumdisplay.php?fid=$1&amp;page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$  /viewthread.php?tid=$1&amp;extra=page%3D$3&amp;page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$   /space.php?$1=$2 last;
rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
}
</pre>
<h3>相关网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2008/06/mysql_discuz_.html" title="百万记录级MySQL数据库及Discuz!论坛优化">百万记录级MySQL数据库及Discuz!论坛优化</a></li>
<li><a href="http://shunz.net/2008/07/nginx_perl_fastcgi.html" title="在Nginx环境下用Perl FastCGI支持Awstats">在Nginx环境下用Perl FastCGI支持Awstats</a></li>
<li><a href="http://shunz.net/2006/07/how_to_select_linux_distribution.html" title="根据需求选择合适的Linux发行版本">根据需求选择合适的Linux发行版本</a></li>
<li><a href="http://shunz.net/2008/07/siege.html" title="使用Siege进行WEB压力测试">使用Siege进行WEB压力测试</a></li>
<li><a href="http://shunz.net/2008/07/nginx_log_rotation.html" title="Nginx的日志回滚">Nginx的日志回滚</a></li>
<li><a href="http://shunz.net/2007/02/apache-mysql-subversion.html" title="Apache+Subversion安装笔记">Apache+Subversion安装笔记</a></li>
<li><a href="http://shunz.net/2006/12/add_swap_partition_size.html" title="SWAP分区太小的补救措施">SWAP分区太小的补救措施</a></li>
<li><a href="http://shunz.net/2006/08/amd_server.html" title="再次组装一台AMD双核64位服务器">再次组装一台AMD双核64位服务器</a></li>
<li><a href="http://shunz.net/2006/07/how_to_install_livecd_into_hdd.html" title="将Gentoo LiveCD系统复制到硬盘HOWTO">将Gentoo LiveCD系统复制到硬盘HOWTO</a></li>
<li><a href="http://shunz.net/2006/06/linux_muti_ip.html" title="Linux单网卡绑定多IP与多网卡共用单IP的实现方法">Linux单网卡绑定多IP与多网卡共用单IP的实现方法</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2008 |
	  <a href="http://shunz.net/2008/07/nginx_rewrite.html">Nginx的Rewrite设置及示例</a> |
	  <a href="http://shunz.net/2008/07/nginx_rewrite.html#comments">5条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2008/07/nginx_rewrite.html&amp;title=Nginx的Rewrite设置及示例">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2008/07/nginx_rewrite.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2008/07/nginx_rewrite.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>百万记录级MySQL数据库及Discuz!论坛优化</title>
		<link>http://shunz.net/2008/06/mysql_discuz_.html</link>
		<comments>http://shunz.net/2008/06/mysql_discuz_.html#comments</comments>
		<pubDate>Tue, 24 Jun 2008 03:19:45 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[Discuz]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[nginx]]></category>

		<category><![CDATA[optimization]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[php-fpm]]></category>

		<category><![CDATA[server]]></category>

		<category><![CDATA[siege]]></category>

		<category><![CDATA[Web服务器]]></category>

		<category><![CDATA[优化]]></category>

		<category><![CDATA[数据库优化]]></category>

		<category><![CDATA[网站]]></category>

		<category><![CDATA[网站优化]]></category>

		<category><![CDATA[论坛优化]]></category>

		<guid isPermaLink="false">http://shunz.net/?p=530</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2008/06/mysql_discuz_.html最近，帮一个朋友优化一... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2008/06/mysql_discuz_.html">http://shunz.net/2008/06/mysql_discuz_.html</a></p><p>最近，帮一个朋友优化一个拥有20万主题，100万帖子，3万多会员，平均在线人数2000人的Discuz!论坛，采用Linux2.6+Apache2+mod_php5+MySQL5，服务器配置为双至强+4G内存，优化前，系统平均负载（load average）基本维持在10以上，MySQL的CPU占用率基本在90%以上，优化后，系统平均负载降到0.5以下，MySQL的CPU占用率很少有超过10%的时候。优化前YSlow得分只有35分，优化后YSlow得分86分。现将优化的过程和经验做一个记录：</p>
<p><span id="more-530"></span>首先，对Apache进行优化，编辑httpd.conf，设置HostnameLookups、KeepAlive、MaxKeepAliveRequests以及KeepAliveTimeout四个参数，调整MaxSpareServers、ServerLimit、MaxClients以及MaxRequestsPerChild参数，还可以考虑弃用prefork而采用worker MPM。设置mod_deflate及mod_expires模块，不过注意Discuz!不能对PHP文件开启Expires，否则会出现问题。另外还可以考虑开启mod_cache和mod_mem_cache模块。另外利用cronolog按天对日志进行轮循截断，如果日志特别大，也可以按小时截断。另外再加上Awstats对日志进行分析，并用gzip对日志进行压缩，自动删除1个月前的日志。</p>
<p>其次，对PHP进行优化，编辑php.ini，调整output_buffering、zlib.output_compression及max_execution_time、max_input_time、memory_limit等参数，并安装Xcache和Zend Optimizer。</p>
<p>然后对MySQL进行优化。首先重新静态编译MySQL，使其只支持MyISAM和Memory两种引擎，并按Discuz!编码选择只支持UTF-8或者GBK字符集。编辑my.cnf，设置skip-locking、skip-external-locking、skip-networking和skip-name-resolve，根据内存和数据库状态具体调整key_buffer_size、query_cache_size、query_cache_limit、max_allowed_packet、table_cache、thread_cache_size、sort_buffer_size、read_buffer_size、read_rnd_buffer_size、join_buffer_size、tmp_table_size、max_tmp_tables、back_log、max_connections、wait_timeout的参数。</p>
<p>对数据库进行优化，将threads和posts表中部分未索引的字段增加索引，并将supersite数据库表从bbs数据库独立出去。修改discuz!配置文件，设置开启pconnect。</p>
<p>对Discuz！设置进行优化。进入Discuz!系统设置，修改页面缓存设置中的缓存有效期和缓存系数，修改服务器优化中的禁止浏览器缓冲和页面Gzip压缩，修改防盗链设置中下载附件来路检查，用JSMin自动对js文件进行缩减（Discuz! 6.1的common.js原文件29.3k，经JSMin缩减后为24.1k，再经deflate后为7.3k），修改attachments.php文件，将：</p>
<pre class="prettyprint">
//dheader('Cache-control: max-age=31536000');
//dheader('Expires: '.gmdate('D, d M Y H:i:s', $timestamp + 31536000).' GMT');
</pre>
<p>前的注释去掉。修改模板目录下adv.htm，去掉与Insenz有关的代码。</p>
<p>通过查看MySQL的status，可以看出优化后，长时间运行的Key_read_ratio基本保持在0.05%以下，Threads_cache_hitrate保持在99.9%以上。个人感觉，Discuz!将Session保存在数据库中，极大地降低了Query Cache的命中率，如果需要进一步优化，可以考虑修改Discuz!源码，将Session保存到Memcache中。</p>
<p>优化之后用Siege做并发压力测试，在200并发下，基本没有任何错误。如果将来人数更多，可以考虑将平台迁移到Ngix+PHP FastCGI上。</p>
<p>下面是用Siege在300并发下的测试结果：</p>
<blockquote><p>
#siege -c 300 -b -r 35 -f bbs.url<br />
** SIEGE 2.67<br />
** Preparing 300 concurrent users for battle.<br />
The server is now under siege..      done.<br />
Transactions:                  10500 hits<br />
Availability:                 100.00 %<br />
Elapsed time:                  52.68 secs<br />
Data transferred:              65.67 MB<br />
Response time:                  1.27 secs<br />
Transaction rate:             199.32 trans/sec<br />
Throughput:                     1.25 MB/sec<br />
Concurrency:                  253.07<br />
Successful transactions:       10500<br />
Failed transactions:               0<br />
Longest transaction:           24.88<br />
Shortest transaction:           0.00
</p></blockquote>
<p>500并发下的测试结果：</p>
<blockquote><p>
#siege -c 500 -b -r 20 -f bbs.url<br />
** SIEGE 2.67<br />
** Preparing 300 concurrent users for battle.<br />
The server is now under siege..      done.<br />
Transactions:                   9979 hits<br />
Availability:                  99.79 %<br />
Elapsed time:                  86.52 secs<br />
Data transferred:              82.66 MB<br />
Response time:                  3.30 secs<br />
Transaction rate:             115.34 trans/sec<br />
Throughput:                     0.96 MB/sec<br />
Concurrency:                  381.07<br />
Successful transactions:        9979<br />
Failed transactions:              21<br />
Longest transaction:           34.80<br />
Shortest transaction:           0.00
</p></blockquote>
<p>昨天，将服务器迁移到了Nginx+php-fpm，以下是迁移后测试，相差真的很明显，回头再写Nginx+php-fpm的经验：</p>
<blockquote><p>
[root@bbs ~]# siege -c 300 -r 50 -f bbs.url<br />
** SIEGE 2.67<br />
** Preparing 300 concurrent users for battle.<br />
The server is now under siege..      done.<br />
Transactions:                  15000 hits<br />
Availability:                 100.00 %<br />
Elapsed time:                  64.12 secs<br />
Data transferred:              67.79 MB<br />
Response time:                  0.55 secs<br />
Transaction rate:             233.94 trans/sec<br />
Throughput:                     1.06 MB/sec<br />
Concurrency:                  128.95<br />
Successful transactions:       14976<br />
Failed transactions:               0<br />
Longest transaction:            3.96<br />
Shortest transaction:           0.00</p>
<p>[root@bbs ~]# siege -c 500 -r 50 -f bbs.url<br />
** SIEGE 2.67<br />
** Preparing 500 concurrent users for battle.<br />
The server is now under siege..      done.<br />
Transactions:                  25000 hits<br />
Availability:                 100.00 %<br />
Elapsed time:                  65.52 secs<br />
Data transferred:              83.65 MB<br />
Response time:                  0.57 secs<br />
Transaction rate:             381.56 trans/sec<br />
Throughput:                     1.28 MB/sec<br />
Concurrency:                  216.02<br />
Successful transactions:       21707<br />
Failed transactions:               0<br />
Longest transaction:            5.83<br />
Shortest transaction:           0.00
</p></blockquote>
<p>=======</p>
<p><strong>BTW：做个小广告，有偿提供各种Apache、MySQL或Discuz!优化。</strong><br />
<h3>相关网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2008/07/nginx_rewrite.html" title="Nginx的Rewrite设置及示例">Nginx的Rewrite设置及示例</a></li>
<li><a href="http://shunz.net/2008/07/nginx_perl_fastcgi.html" title="在Nginx环境下用Perl FastCGI支持Awstats">在Nginx环境下用Perl FastCGI支持Awstats</a></li>
<li><a href="http://shunz.net/2006/07/how_to_select_linux_distribution.html" title="根据需求选择合适的Linux发行版本">根据需求选择合适的Linux发行版本</a></li>
<li><a href="http://shunz.net/2004/12/44.html" title="apache的静态/动态编译在apache+php+mysql+gd中的应用">apache的静态/动态编译在apache+php+mysql+gd中的应用</a></li>
<li><a href="http://shunz.net/2008/07/siege.html" title="使用Siege进行WEB压力测试">使用Siege进行WEB压力测试</a></li>
<li><a href="http://shunz.net/2008/07/nginx_log_rotation.html" title="Nginx的日志回滚">Nginx的日志回滚</a></li>
<li><a href="http://shunz.net/2007/02/pearson.html" title="Pearson线性相关系数计算公式">Pearson线性相关系数计算公式</a></li>
<li><a href="http://shunz.net/2007/02/apache-mysql-subversion.html" title="Apache+Subversion安装笔记">Apache+Subversion安装笔记</a></li>
<li><a href="http://shunz.net/2006/12/add_swap_partition_size.html" title="SWAP分区太小的补救措施">SWAP分区太小的补救措施</a></li>
<li><a href="http://shunz.net/2006/11/adsense-2.html" title="怎样进一步提高Google Adsense收入？">怎样进一步提高Google Adsense收入？</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2008 |
	  <a href="http://shunz.net/2008/06/mysql_discuz_.html">百万记录级MySQL数据库及Discuz!论坛优化</a> |
	  <a href="http://shunz.net/2008/06/mysql_discuz_.html#comments">26条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2008/06/mysql_discuz_.html&amp;title=百万记录级MySQL数据库及Discuz!论坛优化">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2008/06/mysql_discuz_.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2008/06/mysql_discuz_.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>如何在保留现有扩展和配置的前提下升级到Firefox3 b4</title>
		<link>http://shunz.net/2008/03/firefox3.html</link>
		<comments>http://shunz.net/2008/03/firefox3.html#comments</comments>
		<pubDate>Thu, 27 Mar 2008 01:57:58 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[firefox]]></category>

		<category><![CDATA[upgrade]]></category>

		<category><![CDATA[升级]]></category>

		<guid isPermaLink="false">http://www.shunz.net/2008/03/firefox3.html</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2008/03/firefox3.htmlFirefox3 b4出来后，反响还不错... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2008/03/firefox3.html">http://shunz.net/2008/03/firefox3.html</a></p><p>Firefox3 b4出来后，反响还不错，很多人建议升级，但是因为firefox3与firefox2的不兼容，很多扩展都无法使用，有些人于是又回到了firefox2。下面介绍我如何在保留原有配置的情况下，升级到firefox3，并且是绿色版:)</p>
<p><span id="more-525"></span>首先，第一步也是非常重要的一步，就是备份原有firefox2。如果你的firefox不是按我原来那样自己制作的绿色版，则还需要备份一下：</p>
<blockquote><p>C:\Documents and Settings\你的用户名\Application Data\Mozilla\Firefox\Profiles</p></blockquote>
<p>这个目录下的“随机字符.default”文件夹。</p>
<p>然后，安装Firefox3，最好是安装目录与firefox2一致（某些扩展会记录firefox安装目录）</p>
<p>先不要运行firefox3，将前面备份的profile文件夹，即：“随机字符.default”文件夹拷贝到安装目录下，并将文件夹改名为：profile</p>
<p>编辑profile目录下的prefs.js文件，增加下面两行：</p>
<blockquote><p>user_pref(&#8221;extensions.checkCompatibility&#8221;, false);<br />
user_pref(&#8221;extensions.checkUpdateSecurity&#8221;, false);</p></blockquote>
<p>然后新建一个快捷方式：firefox.exe -profile &#8220;profile&#8221;，利用这个快捷方式运行firefox</p>
<p>如果你需要tab mix plus插件，请在升级完成后，安装最新的dev build版tab mix plus：<a href="http://tinyurl.com/m5vl5" target="_blank">http://tinyurl.com/m5vl5</a> （感谢number5告知）</p>
<p>ok，到此全部搞定，我所用到的扩展在firefox3下运行都没有任何问题。浏览一下网页，速度果然比firefox2提高了很多。。。。</p>
<p>Update：感谢<span class="author"><a href="http://michaels.blogbus.com/" target="_blank">勒色</a>的提醒——可以使用 <a href="http://addons.mozine.cn/firefox/35/" target="_blank">Nightly Tester Tools</a> 扩展来达到兼容的目的。</span><br />
<h3>相关网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2008/07/firefox_plugin_compatibility.html" title="如何让Firefox扩展支持兼容更高版本">如何让Firefox扩展支持兼容更高版本</a></li>
<li><a href="http://shunz.net/2007/08/firefox_sina.html" title="Firefox无法打开新浪的原因">Firefox无法打开新浪的原因</a></li>
<li><a href="http://shunz.net/2006/12/firefox-2.html" title="Firefox升级到2.0.0.1">Firefox升级到2.0.0.1</a></li>
<li><a href="http://shunz.net/2006/11/firefox_gift.html" title="收到Yupoo寄来Firefox的T-shirt">收到Yupoo寄来Firefox的T-shirt</a></li>
<li><a href="http://shunz.net/2006/10/firefox_20.html" title="Firefox 2.0 Release!">Firefox 2.0 Release!</a></li>
<li><a href="http://shunz.net/2006/06/gentoo_upgrade.html" title="升级gentoo碰到的几个问题及解决办法">升级gentoo碰到的几个问题及解决办法</a></li>
<li><a href="http://shunz.net/2006/01/firefox15.html" title="用上了FireFox1.5">用上了FireFox1.5</a></li>
<li><a href="http://shunz.net/2005/10/313.html" title="如何将Firefox配置文件转移到其他机器上？">如何将Firefox配置文件转移到其他机器上？</a></li>
<li><a href="http://shunz.net/2005/07/261.html" title="本站升级到drupal 4.6.2">本站升级到drupal 4.6.2</a></li>
<li><a href="http://shunz.net/2005/05/202.html" title="回到firefox的阵营兼谈我使用的firefox插件">回到firefox的阵营兼谈我使用的firefox插件</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2008 |
	  <a href="http://shunz.net/2008/03/firefox3.html">如何在保留现有扩展和配置的前提下升级到Firefox3 b4</a> |
	  <a href="http://shunz.net/2008/03/firefox3.html#comments">10条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2008/03/firefox3.html&amp;title=如何在保留现有扩展和配置的前提下升级到Firefox3 b4">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2008/03/firefox3.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2008/03/firefox3.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Firefox无法打开新浪的原因</title>
		<link>http://shunz.net/2007/08/firefox_sina.html</link>
		<comments>http://shunz.net/2007/08/firefox_sina.html#comments</comments>
		<pubDate>Mon, 27 Aug 2007 09:33:32 +0000</pubDate>
		<dc:creator>shunz</dc:creator>
		
		<category><![CDATA[学习笔记]]></category>

		<category><![CDATA[firefox]]></category>

		<category><![CDATA[kaspersky]]></category>

		<category><![CDATA[sina]]></category>

		<category><![CDATA[卡巴斯基]]></category>

		<category><![CDATA[新浪]]></category>

		<guid isPermaLink="false">http://www.shunz.net/2007/08/firefox_sina.html</guid>
		<description><![CDATA[	版权声明：可以在网上任意转载，转载时请务必以超链接形式标明文章原始出处和作者信息及本声明文字。
作者：shunz，原文链接：http://shunz.net/2007/08/firefox_sina.html今天碰到一个奇怪的问题，... ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/deed.zh" target="_blank">版权声明</a>：可以在网上任意转载，转载时请务必以<b>超链接形式</b>标明文章原始出处和作者信息及本声明文字。<img src="http://www.feedsky.com/feed/shunz/sc/gif" /><img src="http://img.tongji.cn.yahoo.com/709296/ystat.gif"/><br />
作者：<a href="http://shunz.net">shunz</a>，原文链接：<a href="http://shunz.net/2007/08/firefox_sina.html">http://shunz.net/2007/08/firefox_sina.html</a></p><p>今天碰到一个奇怪的问题，使用Firefox始终无法打开sina的任何网页，状态一直是加载中，而换用IE的话就没有任何问题，怀疑是firefox的设置有问题，使用safe模式启动firefox无效，重新安装firefox还是无效，真是个奇怪的问题。</p>
<p>后来偶尔发现，把卡巴斯基关闭后浏览sina就没有任何问题了，看来问题出在卡巴斯基上了，仔细研究后得知，卡巴斯基的web保护里的缓冲区扫描与sina有兼容性bug，将卡巴斯基的web保护改为协议流扫描后，一切ok！</p>
<p><strong>UPDATE：</strong>又有一个新办法，不需要修改web保护，解决办法是打开卡巴斯基->设置-> 保护->信任区域->信任程序->添加->将firefox添加进来->不扫描网络通信量，确定就ok了。<br />
<h3>相关网志</h3>
<ul class="related_post">
<li><a href="http://shunz.net/2008/07/firefox_plugin_compatibility.html" title="如何让Firefox扩展支持兼容更高版本">如何让Firefox扩展支持兼容更高版本</a></li>
<li><a href="http://shunz.net/2008/03/firefox3.html" title="如何在保留现有扩展和配置的前提下升级到Firefox3 b4">如何在保留现有扩展和配置的前提下升级到Firefox3 b4</a></li>
<li><a href="http://shunz.net/2006/12/firefox-2.html" title="Firefox升级到2.0.0.1">Firefox升级到2.0.0.1</a></li>
<li><a href="http://shunz.net/2006/11/firefox_gift.html" title="收到Yupoo寄来Firefox的T-shirt">收到Yupoo寄来Firefox的T-shirt</a></li>
<li><a href="http://shunz.net/2006/10/firefox_20.html" title="Firefox 2.0 Release!">Firefox 2.0 Release!</a></li>
<li><a href="http://shunz.net/2006/01/firefox15.html" title="用上了FireFox1.5">用上了FireFox1.5</a></li>
<li><a href="http://shunz.net/2005/10/313.html" title="如何将Firefox配置文件转移到其他机器上？">如何将Firefox配置文件转移到其他机器上？</a></li>
<li><a href="http://shunz.net/2005/05/202.html" title="回到firefox的阵营兼谈我使用的firefox插件">回到firefox的阵营兼谈我使用的firefox插件</a></li>
</ul>
<p>( 全文完 )</p>	<hr noshade style="margin:0;height:1px" />
	<p>&copy; <a href="http://shunz.net">shunz</a> , <a href="http://shunz.net">BLOG家园</a> , 2007 |
	  <a href="http://shunz.net/2007/08/firefox_sina.html">Firefox无法打开新浪的原因</a> |
	  <a href="http://shunz.net/2007/08/firefox_sina.html#comments">8条留言</a>
	</p>
	<p>添加到 <a href="http://del.icio.us/post?url=http://shunz.net/2007/08/firefox_sina.html&amp;title=Firefox无法打开新浪的原因">del.icio.us</a> |
	<a href="http://technorati.com/search/http://shunz.net/2007/08/firefox_sina.html" title="Search on Technorati">Technorati</a> 反向链接 |
	阅读更多【<a href="http://shunz.net/category/tech" title="View all posts in 学习笔记" rel="category tag">学习笔记</a>】</p>]]></content:encoded>
			<wfw:commentRss>http://shunz.net/2007/08/firefox_sina.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
