<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[张宴的博客]]></title> 
<link>http://zyan.cc/index.php</link> 
<description><![CDATA[Web系统架构与底层研发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[张宴的博客]]></copyright>
<item>
<link>http://zyan.cc/post/271/</link>
<title><![CDATA[修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[Web服务器]]></category>
<pubDate>Tue, 24 Jul 2007 04:17:18 +0000</pubDate> 
<guid>http://zyan.cc/post/271/</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.0 最后修改：2007.07.24 转载请注明出处：<a href="http://blog.zyan.cc" target="_blank">http://blog.zyan.cc</a>]<br/><br/>　　新增的一组Apache服务器上线以来，我用netstat -an命令发现服务器中有大量状态为TIME-WAIT的TCP连接，于是用/sbin/sysctl -a查看了一下Linux的各项内核参数，并翻阅有关资料，决定修改其中的两项参数，以达到减少TCP连接中TIME-WAIT sockets的目的。<br/><br/>　　<span style="color: #008000;">vi /etc/sysctl.conf</span><br/>　　编辑/etc/sysctl.conf文件，增加三行：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">net.ipv4.tcp_syncookies = 1<br/>net.ipv4.tcp_tw_reuse = 1<br/>net.ipv4.tcp_tw_recycle = 1</div></div><br/>　　说明：<br/>　　net.ipv4.tcp_syncookies = 1 表示开启SYN Cookies。当出现SYN等待队列溢出时，启用cookies来处理，可防范少量SYN攻击，默认为0，表示关闭；<br/>　　net.ipv4.tcp_tw_reuse = 1 表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接，默认为0，表示关闭；<br/>　　net.ipv4.tcp_tw_recycle = 1 表示开启TCP连接中TIME-WAIT sockets的快速回收，默认为0，表示关闭。<br/> <br/>　　再执行以下命令，让修改结果立即生效：<br/>　　<span style="color: #008000;">/sbin/sysctl -p</span><br/> <br/>　　用以下语句看了一下服务器的TCP状态：<br/>　　<span style="color: #008000;">netstat -n &#124; awk '/^tcp/ &#123;++S[$NF]&#125; END &#123;for(a in S) print a, S[a]&#125;'</span><br/>　　返回结果如下：<br/>　　ESTABLISHED 1423<br/>　　FIN_WAIT1 1<br/>　　FIN_WAIT2 262<br/>　　SYN_SENT 1<br/>　　TIME_WAIT 962<br/> <br/>　　效果：处于TIME_WAIT状态的sockets从原来的10000多减少到1000左右。处于SYN_RECV等待处理状态的sockets为0，原来的为50～300。<br/><br/>　　附：TCP状态变迁图，见我的另一篇文章《<a href="http://blog.zyan.cc/read.php/269.htm" target="_blank">查看Apache并发请求数及其TCP连接状态</a>》<br/>Tags - <a href="http://zyan.cc/tags/linux/" rel="tag">linux</a> , <a href="http://zyan.cc/tags/tcp/" rel="tag">tcp</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment205</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>民大学弟 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 24 Jul 2007 11:49:08 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment205</guid> 
<description>
<![CDATA[ 
	张宴大哥不仅在计算机方面颇有造诣，写作水平也不错嘛，加油啊，在新浪干上几年后就可以出书了……呵呵，又一位百万新贵将要诞生！
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment206</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>民大学弟 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 24 Jul 2007 12:08:01 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment206</guid> 
<description>
<![CDATA[ 
	呵呵,如法炮制……不是病毒！<br/><a href="http://learning.sohu.com/s2007/07tzs/?stra=%u5F20%u5BB4" target="_blank">http://learning.sohu.com/s2007/07tzs/?stra=%u5F20%u5BB4</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment207</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>民大学弟 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 24 Jul 2007 16:02:25 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment207</guid> 
<description>
<![CDATA[ 
	张宴大哥，我这几天一直在用纯CSS做二级导航菜单，但老做不成功……呵呵，你那个中南民族大学就业信息网的导航菜单是怎么做的啊，能否在你的博客上专门写一篇文章讲讲制作的过程，讲详细些……或者以word文档的形式将制作的过程写给我，我的邮箱是 &nbsp;be_ok@163.com &nbsp;写详细些哈，我很笨的，拜托了……你有时间的时候就做，一两个星期内给我答复，我不急……<br/>谢谢你了哈，下次回武汉的话我请客哦
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment243</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>zhangluoer &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 16 Aug 2007 05:49:14 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment243</guid> 
<description>
<![CDATA[ 
	呵，你上面写的三个参数都已经改过了，也没有出现太大的变化，TIME_WAIT一般是ESTABLISHED的１０倍左右，甚至更高。<br/>像你上面写的很少见过。<br/>还有什么地方需要优化吗？
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment244</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>zhangluoer &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 16 Aug 2007 07:28:06 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment244</guid> 
<description>
<![CDATA[ 
	我是直接修改的#echo 1 &gt; /proc/sys/net/ipv4/tcp_syncookies的<br/>所以不存在改完后执行/sbin/sysctl -p<br/>另外发现有大量的对：3306端口的访问都处于time_wait状态。<br/>能否确定一下问题的原因，是PHP编程的问题，在链接数据库后没有关系链接，导致大量的链接，还是其它什么原因<br/>3ks
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment278</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>jackbillow &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 31 Aug 2007 10:10:14 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment278</guid> 
<description>
<![CDATA[ 
	张兄，写的不错。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment279</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>jackbillow &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 31 Aug 2007 10:10:33 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment279</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment292</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>大宇 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 03 Sep 2007 14:26:50 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment292</guid> 
<description>
<![CDATA[ 
	不错，照着修改了的确有效的减少了time_wait状态的线程数量<br/><br/>还有个问题，我用top查看，load average: 17.39, 17.10, 16.71<br/>服务器上只有一个httpd服务在跑，怎么负载这么高。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment696</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>sx &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 21 Feb 2008 07:39:53 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment696</guid> 
<description>
<![CDATA[ 
	关于TCP_TIMEWAIT的问题由来已久，在此补充一下原因吧。都知道tcp的三次握手后建立连接，连接建立后，如果client主动关闭连接，则此连接会被内核回收，而很多时候，比如上面的兄台的PHP程序没有关闭数据库连接，这个时候，server端就无法知道此连接是否还继续有效，也就是，cilent是在组装数据还是已经掉线了呢？那么就进入timewait了。<br/>另外，对于张兄的修改，也补充一下：<br/>net.ipv4.tcp_syncookies = 1，这句是可以的，不提<br/>net.ipv4.tcp_tw_reuse = 1 ，这句对于有些时候，客户端没有真的关闭连接而是在等待发送数据的时候，重用接口会导致数据出错，所以，只是针对HTTP类型可以开启，对于其他长时间连接处理类型，就关上比较稳妥<br/>net.ipv4.tcp_tw_recycle = 1 这句基本上来说用处不大，开启快速回收后，系统还是会一样取系统等待时间，故，要想真的减少timewait时间的话，将内核中的等待时间参数修改为一个合适的值比较妥当，尤其是对于内网机器来说。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment1106</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>goter &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 01 Jun 2008 08:49:46 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment1106</guid> 
<description>
<![CDATA[ 
	张大哥，别人老连不上我的BT服务器，用netstat查看，有很多都是close wait<br/>这个是BT服务器配置的问题吗？
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment4339</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>storysky &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 03 Nov 2009 02:19:45 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment4339</guid> 
<description>
<![CDATA[ 
	你好张老师，我刚接手一台服务器，发现他的time-wait非常多，用了您上面的方法以后发现time-wait少了一些(以前是7000多现在是6000左右)，还是很多！<br/>而且ESTABLISHED 一直在600左右，我想问一下有什么好办法解决一下，我的mail 是redsky818@yahoo.com.cn<br/>下面是我的sysctl.conf 的配置和连接状态<br/>net.ipv4.ip_forward = 0<br/>net.ipv4.conf.default.rp_filter = 1<br/>net.ipv4.conf.default.accept_source_route = 0<br/>kernel.sysrq = 0<br/>kernel.core_uses_pid = 1<br/>net.ipv4.tcp_syncookies = 1<br/>kernel.msgmnb = 65536<br/>kernel.msgmax = 65536<br/>kernel.shmmax = 68719476736<br/>kernel.shmall = 4294967296<br/>net.ipv4.tcp_max_syn_backlog = 65536<br/>net.core.netdev_max_backlog =&nbsp;&nbsp;8192<br/>net.ipv4.tcp_max_tw_buckets = 8192<br/>net.core.somaxconn = 32768<br/>net.core.wmem_default = 8388608<br/>net.core.rmem_default = 8388608<br/>net.core.rmem_max = 16777216<br/>net.core.wmem_max = 16777216<br/>net.ipv4.tcp_timestamps = 0<br/>net.ipv4.tcp_synack_retries = 2<br/>net.ipv4.tcp_syn_retries = 2<br/>net.ipv4.tcp_tw_recycle = 1<br/>net.ipv4.tcp_tw_reuse = 1<br/>net.ipv4.tcp_mem = 94500000 915000000 927000000<br/>net.ipv4.tcp_max_orphans = 3276800<br/>net.ipv4.tcp_fin_timeout = 30<br/>net.ipv4.tcp_keepalive_time = 30<br/>net.ipv4.ip_local_port_range = 1024&nbsp;&nbsp;65535<br/>kernel.msgmni = 1024<br/>kernel.sem = 250 256000 32 1024<br/>##################################<br/> netstat -n &#124; awk &#039;/^tcp/ &#123;++S[$NF]&#125; END &#123;for(a in S) print a, S[a]&#125;&#039;<br/>TIME_WAIT 6221<br/>FIN_WAIT1 4<br/>ESTABLISHED 615<br/>SYN_RECV 2
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment14160</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>louis vuitton uk &lt;fsf@fdg.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 23 Nov 2011 00:47:26 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment14160</guid> 
<description>
<![CDATA[ 
	This <a href="http://www.louisvuittonoutlets.org.uk" target="_blank">louis vuitton uk</a> for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this <a href="http://www.coachoutletstoreonlinefree.com" target="_blank">coach outlet store online</a>. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine <a href="http://www.christian-louboutinsale.org.uk" target="_blank">christian louboutin sale</a>. Purse the elegance in bridal wedding. Enjoy the fashion.
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment17323</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>chanel uk &lt;xiang1234xiangxiang@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 13 Apr 2012 09:15:00 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment17323</guid> 
<description>
<![CDATA[ 
	<a href="http://www.chanelukoutlets.org.uk" target="_blank">chanel uk</a><br/><a href="http://www.burberryukoutletuk.org" target="_blank">burberry uk</a><br/><a href="http://www.poloralphlaurenuks.org" target="_blank">ralph lauren uk</a><br/>Q
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment17343</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>chanel uk &lt;xiang1234xiangxiang@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 13 Apr 2012 09:20:28 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment17343</guid> 
<description>
<![CDATA[ 
	<a href="http://www.christianlouboutinukuk.org" target="_blank">christian louboutin</a><br/><a href="http://www.tiffanyuksuk.org" target="_blank">tiffanys</a><br/><a href="http://www.gucciukbeltuk.org" target="_blank">gucci uk</a><br/><a href="http://www.frsaclouisvuittonsac.com" target="_blank">louis vuitton sac</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/271/#blogcomment18698</link>
<title><![CDATA[[评论] 修改Linux内核参数，减少TCP连接中的TIME-WAIT sockets[原创]]]></title> 
<author>coach factory outlet &lt;fgf@hotmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 17 May 2012 02:53:31 +0000</pubDate> 
<guid>http://zyan.cc/post/271/#blogcomment18698</guid> 
<description>
<![CDATA[ 
	Today, following half a century, mentor leather-bases <a href="http://www.coachfactoryoutletao.net" target="_blank">coach factory outlet</a> continues to be the delicate craft of leather-based master is accountable for,Would you like to meet more friends, or go with the times? If yes, <a href="http://www.coachfactoryoutletao.net" target="_blank">coach factory online</a> is opening welcome doors to you.in the market you definitely can find various colorways that are designed in as well as the high quality that applied in. For most of you would like to come. So just come to our <a href="http://www.coachfactoryoutletao.net" target="_blank">coach factory outlet online</a> store to choose one.
]]>
</description>
</item>
</channel>
</rss>