{"id":845,"date":"2018-11-17T16:09:35","date_gmt":"2018-11-17T08:09:35","guid":{"rendered":"http:\/\/www.shuran.cn\/?p=845"},"modified":"2018-11-17T16:09:35","modified_gmt":"2018-11-17T08:09:35","slug":"%e5%a4%a7%e9%87%8ftime_wait%e7%9a%84%e7%bb%88%e6%9e%81%e8%af%a6%e8%a7%a3%e5%92%8c%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/www.shuran.cn\/?p=845","title":{"rendered":"\u5927\u91cfTIME_WAIT\u7684\u7ec8\u6781\u8be6\u89e3\u548c\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"<p>\n\t<strong>1. \u67e5\u770b\u7cfb\u7edf\u7f51\u7edc\u914d\u7f6e\u548c\u5f53\u524dTCP\u72b6\u6001<\/strong>\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u5728\u5b9a\u4f4d\u5e76\u5904\u7406\u5e94\u7528\u7a0b\u5e8f\u51fa\u73b0\u7684\u7f51\u7edc\u95ee\u9898\u65f6\uff0c\u4e86\u89e3\u7cfb\u7edf\u9ed8\u8ba4\u7f51\u7edc\u914d\u7f6e\u662f\u975e\u5e38\u5fc5\u8981\u7684\u3002\u4ee5x86_64\u5e73\u53f0Linux kernelversion 2.6.9\u7684\u673a\u5668\u4e3a\u4f8b\uff0cipv4\u7f51\u7edc\u534f\u8bae\u7684\u9ed8\u8ba4\u914d\u7f6e\u53ef\u4ee5\u5728\/proc\/sys\/net\/ipv4\/\u4e0b\u67e5\u770b\uff0c\u5176\u4e2d\u4e0eTCP\u534f\u8bae\u6808\u76f8\u5173\u7684\u914d\u7f6e\u9879\u5747\u4ee5tcp_xxx\u547d\u540d\uff0c\u5173\u4e8e\u8fd9\u4e9b\u914d\u7f6e\u9879\u7684\u542b\u4e49\uff0c\u8bf7\u53c2\u8003\u8fd9\u91cc\u7684\u6587\u6863\uff0c\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u67e5\u770blinux\u6e90\u7801\u6811\u4e2d\u63d0\u4f9b\u7684\u5b98\u65b9\u6587\u6863\uff08src\/linux\/Documentation\/ip-sysctl.txt\uff09\u3002\u4e0b\u9762\u5217\u51fa\u6211\u673a\u5668\u4e0a\u51e0\u4e2a\u9700\u91cd\u70b9\u5173\u6ce8\u7684\u914d\u7f6e\u9879\u53ca\u5176\u9ed8\u8ba4\u503c\uff1a\n<\/p>\n<p>\n\t\n<\/p>\n<p>\n\tcat \/proc\/sys\/net\/ipv4\/ip_local_port_range &nbsp; &nbsp; &nbsp;32768 &nbsp; 61000\n<\/p>\n<p>\n\tcat \/proc\/sys\/net\/ipv4\/tcp_max_syn_backlog &nbsp; &nbsp; &nbsp;1024\n<\/p>\n<p>\n\tcat \/proc\/sys\/net\/ipv4\/tcp_syn_retries &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5\n<\/p>\n<p>\n\tcat \/proc\/sys\/net\/ipv4\/tcp_max_tw_buckets &nbsp; &nbsp; &nbsp; 180000\n<\/p>\n<p>\n\tcat \/proc\/sys\/net\/ipv4\/tcp_tw_recycle &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0\n<\/p>\n<p>\n\tcat \/proc\/sys\/net\/ipv4\/tcp_tw_reuse &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0\n<\/p>\n<p>\n\t\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u5176\u4e2d\uff0c\u524d3\u9879\u5206\u522b\u8bf4\u660e\u4e86local port\u7684\u5206\u914d\u8303\u56f4\uff08\u9ed8\u8ba4\u7684\u53ef\u7528\u7aef\u53e3\u6570\u4e0d\u52303w\uff09\u3001incomplete connection queue\u7684\u6700\u5927\u957f\u5ea6\u4ee5\u53ca3\u6b21\u63e1\u624b\u65f6SYN\u7684\u6700\u5927\u91cd\u8bd5\u6b21\u6570\uff0c\u8fd93\u9879\u914d\u7f6e\u7684\u542b\u4e49\uff0c\u6709\u4e2a\u6982\u5ff5\u5373\u53ef\u3002\u540e3\u9879\u914d\u7f6e\u7684\u542b\u4e49\u5219\u9700\u8981\u7406\u89e3\uff0c\u56e0\u4e3a\u5b83\u4eec\u5728\u5b9a\u4f4d\u3001\u89e3\u51b3\u95ee\u9898\u8fc7\u7a0b\u4e2d\u8981\u7528\u5230\uff0c\u4e0b\u9762\u8fdb\u884c\u91cd\u70b9\u8bf4\u660e\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;1) tcp_max_tw_buckets\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp; \u8fd9\u7bc7\u6587\u6863 \u662f\u8fd9\u6837\u63cf\u8ff0\u7684\uff1aMaximal number of time wait sockets held by system simultaneously. If this number is exceeded TIME_WAIT socket is immediately destroyed and warning is printed. This limit exists only to prevent simple DoS attacks, you must not lower the limit artificially, but rather increase it (probably, after increasing installed memory), if network conditions require more than default value (180000).\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u53ef\u89c1\uff0c\u8be5\u914d\u7f6e\u9879\u7528\u6765\u9632\u8303\u7b80\u5355\u7684DoS\u653b\u51fb \uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u9002\u5f53\u8c03\u5927\uff0c\u4f46\u7edd\u5bf9\u4e0d\u5e94\u8c03\u5c0f\uff0c\u5426\u5219\uff0c\u540e\u679c\u81ea\u8d1f\u3002\u3002\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp; 2) tcp_tw_recycle\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;Enable fast recycling of sockets in TIME-WAIT status. The defaultvalue is 0 (disabled). It should not be changed without advice\/request of technical experts.\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u8be5\u914d\u7f6e\u9879\u53ef\u7528\u4e8e\u5feb\u901f\u56de\u6536\u5904\u4e8eTIME_WAIT\u72b6\u6001\u7684socket\u4ee5\u4fbf\u91cd\u65b0\u5206\u914d\u3002\u9ed8\u8ba4\u662f\u5173\u95ed\u7684\uff0c\u5fc5\u8981\u65f6\u53ef\u4ee5\u5f00\u542f\u8be5\u914d\u7f6e\u3002\u4f46\u662f\u5f00\u542f\u8be5\u914d\u7f6e\u9879\u540e\uff0c\u6709\u4e00\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\uff0c\u672c\u6587\u540e\u9762\u4f1a\u63d0\u5230\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp; 3) tcp_tw_reuse\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp; Allow to reuse TIME-WAIT sockets for new connections when it is safe from protocol viewpoint. The default value is 0. It should not\n<\/p>\n<p>\n\tbe changed without advice\/request of technical experts.\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u5f00\u542f\u8be5\u9009\u9879\u540e\uff0ckernel\u4f1a\u590d\u7528\u5904\u4e8eTIME_WAIT\u72b6\u6001\u7684socket\uff0c\u5f53\u7136\u590d\u7528\u7684\u524d\u63d0\u662f\u201c\u4ece\u534f\u8bae\u89d2\u5ea6\u6765\u770b\uff0c\u590d\u7528\u662f\u5b89\u5168\u7684\u201d\u3002\u5173\u4e8e\u201c \u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\uff0c\u534f\u8bae\u8ba4\u4e3a\u590d\u7528\u662f\u5b89\u5168\u7684 \u201d\u8fd9\u4e2a\u95ee\u9898\uff0c\u8fd9\u7bc7\u6587\u7ae0 \u4ecelinux kernel\u6e90\u7801\u4e2d\u6316\u51fa\u4e86\u7b54\u6848\uff0c\u611f\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u67e5\u770b\u3002\n<\/p>\n<p>\n\t\n<\/p>\n<p>\n\t<strong>2. \u7f51\u7edc\u95ee\u9898\u5b9a\u4f4d\u601d\u8def<\/strong>\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u53c2\u8003\u524d\u7bc7\u7b14\u8bb0\u5f00\u59cb\u5904\u63cf\u8ff0\u7684\u7ebf\u4e0a\u5b9e\u9645\u95ee\u9898\uff0c\u6536\u5230\u67d0\u53f0\u673a\u5668\u65e0\u6cd5\u5bf9\u5916\u5efa\u7acb\u65b0\u8fde\u63a5\u7684\u62a5\u8b66\u65f6\uff0c\u6392\u67e5\u5b9a\u4f4d\u95ee\u9898\u8fc7\u7a0b\u5982\u4e0b\uff1a\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; \u7528netstat \u2013at | grep \u201cTIME_WAIT\u201d\u7edf\u8ba1\u53d1\u73b0\uff0c\u5f53\u65f6\u51fa\u95ee\u9898\u7684\u90a3\u53f0\u673a\u5668\u4e0a\u5171\u670910w+\u5904\u4e8eTIME_WAIT\u72b6\u6001\u7684TCP\u8fde\u63a5\uff0c\u8fdb\u4e00\u6b65\u5206\u6790\u53d1\u73b0\uff0c\u7531\u62a5\u8b66\u6a21\u5757\u5f15\u8d77\u7684TIME_WAIT\u8fde\u63a5\u67092w+\u3002\u5c06netstat\u8f93\u51fa\u7684\u7edf\u8ba1\u7ed3\u679c\u91cd\u5b9a\u4f4d\u5230\u6587\u4ef6\u4e2d\u7ee7\u7eed\u5206\u6790\uff0c\u4e00\u822c\u4f1a\u770b\u5230\u672c\u673a\u7684port\u88ab\u5927\u91cf\u5360\u7528\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u7531\u672c\u6587\u524d\u9762\u4ecb\u7ecd\u7684\u7cfb\u7edf\u914d\u7f6e\u9879\u53ef\u77e5\uff0ctcp_max_tw_buckets\u9ed8\u8ba4\u503c\u4e3a18w\uff0c\u800cip_local_port_range\u8303\u56f4\u4e0d\u52303w\uff0c\u5927\u91cf\u7684TIME_WAIT\u72b6\u6001\u4f7f\u5f97local port\u5728TIME_WAIT\u6301\u7eed\u671f\u95f4\u4e0d\u80fd\u88ab\u518d\u6b21\u5206\u914d\uff0c\u5373\u6ca1\u6709\u53ef\u7528\u7684local port\uff0c\u8fd9\u5c06\u662f\u5bfc\u81f4\u65b0\u5efa\u8fde\u63a5\u5931\u8d25\u7684\u6700\u5927\u539f\u56e0\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u5728\u8fd9\u91cc\u63d0\u9192\u5927\u5bb6\uff1a\u4e0a\u9762\u7684\u7ed3\u8bba\u53ea\u662f\u6211\u4eec\u7684\u521d\u6b65\u5224\u65ad\uff0c\u5177\u4f53\u539f\u56e0\u8fd8\u9700\u8981\u6839\u636e\u4ee3\u7801\u7684\u5f02\u5e38\u8fd4\u56de\u503c\uff08\u5982socket api\u7684\u8fd4\u56de\u503c\u53caerrno\u7b49\uff09\u548c\u6a21\u5757\u65e5\u5fd7\u505a\u8fdb\u4e00\u6b65\u786e\u8ba4\u3002\u65e0\u6cd5\u5efa\u7acb\u65b0\u8fde\u63a5\u7684\u539f\u56e0\u8fd8\u53ef\u80fd\u662f\u88ab\u5176\u5b83\u6a21\u5757\u5217\u5165\u9ed1\u540d\u5355\u4e86\uff0c\u672c\u4eba\u5c31\u6709\u8fc7\u8fd9\u65b9\u9762\u7684\u6559\u8bad\uff1a\u7a0b\u5e8f\u4e2d\u7528libcurl api\u8bf7\u6c42\u4e0b\u6e38\u6a21\u5757\u5931\u8d25\uff0c\u521d\u6b65\u5b9a\u4f4d\u53d1\u73b0\u673a\u5668TIME_WAIT\u72b6\u6001\u5f88\u591a\uff0c\u4e8e\u662f\u6ca1\u4ed4\u7ec6\u5206\u6790curl\u8f93\u51fa\u65e5\u5fd7\u5c31\u8ba4\u4e3a\u662fTIME_WAIT\u5f15\u8d77\u7684\u95ee\u9898\uff0c\u5bfc\u81f4\u6d6a\u8d39\u4e86\u5f88\u591a\u65f6\u95f4\uff0c\u6298\u817e\u4e86\u534a\u5929\u53d1\u73b0\u4e0d\u5bf9\u52b2\u540e\u624d\u60f3\u8d77\uff0c\u4e0b\u6e38\u6a21\u5757\u6709\u9632\u653b\u51fb\u673a\u5236\uff0c\u800c\u53d1\u8d77\u8bf7\u6c42\u7684\u673a\u5668ip\u88ab\u4e0d\u5728\u4e0b\u6e38\u6a21\u5757\u7684\u8bbf\u95ee\u767d\u540d\u5355\u5185\uff0c\u9ad8\u5cf0\u671f\u4e0a\u6e38\u6a21\u5757\u901a\u8fc7curl\u8bf7\u6c42\u4e0b\u6e38\u7684\u6b21\u6570\u592a\u8fc7\u9891\u7e41\u88ab\u5217\u5165\u9ed1\u540d\u5355\uff0c\u65b0\u5efa\u8fde\u63a5\u65f6\u88ab\u4e0b\u6e38\u6a21\u5757\u7684TCP\u5c42\u76f4\u63a5\u4ee5RST\u5305\u65ad\u5f00\u8fde\u63a5\uff0c\u5bfc\u81f4curl api\u8fd4\u56de\u201dRecv failure: Connection reset by peer\u201d\u7684\u9519\u8bef\u3002\u60e8\u75db\u7684\u6559\u8bad\u5440 =_=\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; \u53e6\u5916\uff0c\u5173\u4e8e\u4f55\u65f6\u53d1\u9001RST\u5305\uff0c\u300aUnix Network Programming Volume 1\u300b\u7b2c4.3\u8282\u505a\u4e86\u8bf4\u660e\uff0c\u4f5c\u4e3a\u7b14\u8bb0\uff0c\u6458\u51fa\u5982\u4e0b\uff1a\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; An RST is a type of TCP segment that is sent by TCP when somethingis wrong.Three conditions that generatean RST are: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;1) when a SYN arrives for a port that has no listening server;\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;2) when TCP wants to abort an existing connection;\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;3) when TCP receives a segment for a connection that does not exist. (TCPv1 [pp.246\u2013250] contains additional information.)\n<\/p>\n<p>\n\t\n<\/p>\n<p>\n\t<strong>3. \u89e3\u51b3\u65b9\u6cd5<\/strong>\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u53ef\u4ee5\u7528\u4e24\u79cd\u601d\u8def\u6765\u89e3\u51b3\u673a\u5668TIME_WAIT\u8fc7\u591a\u5bfc\u81f4\u65e0\u6cd5\u5bf9\u5916\u5efa\u7acb\u65b0TCP\u8fde\u63a5\u7684\u95ee\u9898\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;3.1 \u4fee\u6539\u7cfb\u7edf\u914d\u7f6e\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u5177\u4f53\u6765\u8bf4\uff0c\u9700\u8981\u4fee\u6539\u672c\u6587\u524d\u9762\u4ecb\u7ecd\u7684tcp_max_tw_buckets\u3001tcp_tw_recycle\u3001tcp_tw_reuse\u8fd9\u4e09\u4e2a\u914d\u7f6e\u9879\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;1\uff09\u5c06tcp_max_tw_buckets\u8c03\u5927\uff0c\u4ece\u672c\u6587\u7b2c\u4e00\u90e8\u5206\u53ef\u77e5\uff0c\u5176\u9ed8\u8ba4\u503c\u4e3a18w\uff08\u4e0d\u540c\u5185\u6838\u53ef\u80fd\u6709\u6240\u4e0d\u540c\uff0c\u9700\u4ee5\u673a\u5668\u5b9e\u9645\u914d\u7f6e\u4e3a\u51c6\uff09\uff0c\u6839\u636e\u6587\u6863\uff0c\u6211\u4eec\u53ef\u4ee5\u9002\u5f53\u8c03\u5927\uff0c\u81f3\u4e8e\u4e0a\u9650\u662f\u591a\u5c11\uff0c\u6587\u6863\u6ca1\u6709\u7ed9\u51fa\u8bf4\u660e\uff0c\u6211\u4e5f\u4e0d\u6e05\u695a\u3002\u4e2a\u4eba\u8ba4\u4e3a\u8fd9\u79cd\u65b9\u6cd5\u53ea\u80fd\u5bf9TIME_WAIT\u8fc7\u591a\u7684\u95ee\u9898\u8d77\u5230\u7f13\u89e3\u4f5c\u7528\uff0c\u968f\u7740\u8bbf\u95ee\u538b\u529b\u7684\u6301\u7eed\uff0c\u8be5\u51fa\u73b0\u7684\u95ee\u9898\u8fdf\u65e9\u8fd8\u662f\u4f1a\u51fa\u73b0\uff0c\u6cbb\u6807\u4e0d\u6cbb\u672c\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;2\uff09\u5f00\u542ftcp_tw_recycle\u9009\u9879\uff1a\u5728shell\u7ec8\u7aef\u8f93\u5165\u547d\u4ee4\u201decho 1 &gt; \/proc\/sys\/net\/ipv4\/tcp_tw_recycle\u201d\u53ef\u4ee5\u5f00\u542f\u8be5\u914d\u7f6e\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u9700\u8981\u660e\u786e\u7684\u662f\uff1a\u5176\u5b9eTIME_WAIT\u72b6\u6001\u7684socket\u662f\u5426\u88ab\u5feb\u901f\u56de\u6536\u662f\u7531tcp_tw_recycle\u548ctcp_timestamps\u4e24\u4e2a\u914d\u7f6e\u9879\u5171\u540c\u51b3\u5b9a\u7684\uff0c\u53ea\u4e0d\u8fc7\u7531\u4e8etcp_timestamps\u9ed8\u8ba4\u5c31\u662f\u5f00\u542f\u7684\uff0c\u6545\u5927\u591a\u6570\u6587\u7ae0\u53ea\u63d0\u5230\u8bbe\u7f6etcp_tw_recycle\u4e3a1\u3002\u66f4\u8be6\u7ec6\u7684\u8bf4\u660e\uff08\u5206\u6790kernel\u6e90\u7801\uff09\u53ef\u53c2\u89c1\u8fd9\u7bc7\u6587\u7ae0\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u8fd8\u9700\u8981\u7279\u522b\u6ce8\u610f\u7684\u662f\uff1a\u5f53client\u4e0eserver\u4e4b\u95f4\u6709\u5982NAT\u8fd9\u7c7b\u7f51\u7edc\u8f6c\u6362\u8bbe\u5907\u65f6\uff0c\u5f00\u542ftcp_tw_recycle\u9009\u9879\u53ef\u80fd\u4f1a\u5bfc\u81f4server\u7aefdrop\uff08\u76f4\u63a5\u53d1\u9001RST\uff09\u6765\u81eaclient\u7684SYN\u5305\u3002\u5177\u4f53\u7684\u6848\u4f8b\u53ca\u539f\u56e0\u5206\u6790\uff0c\u53ef\u4ee5\u53c2\u8003\u8fd9\u91cc\u3001\u8fd9\u91cc\u6216\u8fd9\u91cc\u4ee5\u53ca\u8fd9\u91cc\u7684\u5206\u6790\uff0c\u672c\u6587\u4e0d\u518d\u8d58\u8ff0\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;3\uff09\u5f00\u542ftcp_tw_reuse\u9009\u9879\uff1aecho1 &gt; \/proc\/sys\/net\/ipv4\/tcp_tw_reuse\u3002\u8be5\u9009\u9879\u4e5f\u662f\u4e0etcp_timestamps\u5171\u540c\u8d77\u4f5c\u7528\u7684\uff0c\u53e6\u5916socket reuse\u4e5f\u662f\u6709\u6761\u4ef6\u7684\uff0c\u5177\u4f53\u8bf4\u660e\u8bf7\u53c2\u89c1\u8fd9\u7bc7\u6587\u7ae0\u3002\u67e5\u4e86\u5f88\u591a\u8d44\u6599\uff0c\u4e0e\u5728\u7528\u5230NAT\u6216FireWall\u7684\u7f51\u7edc\u73af\u5883\u4e0b\u5f00\u542ftcp_tw_recycle\u540e\u53ef\u80fd\u5e26\u6765\u526f\u4f5c\u7528\u76f8\u6bd4\uff0c\u8c8c\u4f3c\u6ca1\u6709\u53d1\u73b0tcp_tw_reuse\u5f15\u8d77\u7684\u7f51\u7edc\u95ee\u9898\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;3.2 \u4fee\u6539\u5e94\u7528\u7a0b\u5e8f\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; \u5177\u4f53\u6765\u8bf4\uff0c\u53ef\u4ee5\u7ec6\u5206\u4e3a\u4e24\u79cd\u65b9\u5f0f\uff1a\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;1\uff09\u5c06TCP\u77ed\u8fde\u63a5\u6539\u9020\u4e3a\u957f\u8fde\u63a5\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u53d1\u8d77\u8fde\u63a5\u7684\u76ee\u6807\u4e5f\u662f\u81ea\u5df1\u53ef\u63a7\u5236\u7684\u670d\u52a1\u5668\u65f6\uff0c\u5b83\u4eec\u81ea\u5df1\u7684TCP\u901a\u4fe1\u6700\u597d\u91c7\u7528\u957f\u8fde\u63a5\uff0c\u907f\u514d\u5927\u91cfTCP\u77ed\u8fde\u63a5\u6bcf\u6b21\u5efa\u7acb\/\u91ca\u653e\u4ea7\u751f\u7684\u5404\u79cd\u5f00\u9500\uff1b\u5982\u679c\u5efa\u7acb\u8fde\u63a5\u7684\u76ee\u6807\u662f\u4e0d\u53d7\u81ea\u5df1\u63a7\u5236\u7684\u673a\u5668\u65f6\uff0c\u80fd\u5426\u4f7f\u7528\u957f\u8fde\u63a5\u5c31\u9700\u8981\u8003\u8651\u5bf9\u65b9\u673a\u5668\u662f\u5426\u652f\u6301\u957f\u8fde\u63a5\u65b9\u5f0f\u4e86\u3002\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;2\uff09\u901a\u8fc7getsockopt\/setsockoptapi\u8bbe\u7f6esocket\u7684SO_LINGER\u9009\u9879\uff0c\u5173\u4e8eSO_LINGER\u9009\u9879\u7684\u8bbe\u7f6e\u65b9\u6cd5\uff0c\u300aUNP Volume1\u300b\u4e00\u4e667.5\u8282\u7ed9\u51fa\u4e86\u8be6\u7ec6\u8bf4\u660e\uff0c\u60f3\u6df1\u5165\u7406\u89e3\u7684\u540c\u5b66\u53ef\u4ee5\u53bb\u67e5\u9605\u8be5\u6559\u6750\uff0c\u4e5f\u53ef\u4ee5\u53c2\u8003\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bb2\u7684\u8fd8\u7b97\u6e05\u695a\u3002\n<\/p>\n<p>\n\t\n<\/p>\n<p>\n\t<strong>4. \u9700\u8981\u8865\u5145\u8bf4\u660e\u7684\u95ee\u9898<\/strong>\n<\/p>\n<p>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u6211\u4eec\u8bf4TIME_WAIT\u8fc7\u591a\u53ef\u80fd\u5f15\u8d77\u65e0\u6cd5\u5bf9\u5916\u5efa\u7acb\u65b0\u8fde\u63a5\uff0c\u5176\u5b9e\u6709\u4e00\u4e2a\u4f8b\u5916\u4f46\u6bd4\u8f83\u5e38\u89c1\u7684\u60c5\u51b5\uff1aS\u6a21\u5757\u4f5c\u4e3aWebServer\u90e8\u7f72\u5728\u670d\u52a1\u5668\u4e0a\uff0c\u7ed1\u5b9a\u672c\u5730\u67d0\u4e2a\u7aef\u53e3\uff1b\u5ba2\u6237\u7aef\u4e0eS\u95f4\u4e3a\u77ed\u8fde\u63a5\uff0c\u6bcf\u6b21\u4ea4\u4e92\u5b8c\u6210\u540e\u7531S\u4e3b\u52a8\u65ad\u5f00\u8fde\u63a5\u3002\u8fd9\u6837\uff0c\u5f53\u5ba2\u6237\u7aef\u5e76\u53d1\u8bbf\u95ee\u6b21\u6570\u5f88\u9ad8\u65f6\uff0cS\u6a21\u5757\u6240\u5728\u7684\u673a\u5668\u53ef\u80fd\u4f1a\u6709\u5927\u91cf\u5904\u4e8eTIME_WAIT\u72b6\u6001\u7684TCP\u8fde\u63a5\u3002\u4f46\u7531\u4e8e\u670d\u52a1\u5668\u6a21\u5757\u7ed1\u5b9a\u4e86\u7aef\u53e3\uff0c\u6545\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5e76\u4e0d\u4f1a\u5f15\u8d77\u201c\u7531\u4e8eTIME_WAIT\u8fc7\u591a\u5bfc\u81f4\u65e0\u6cd5\u5efa\u7acb\u65b0\u8fde\u63a5\u201d\u7684\u95ee\u9898\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u672c\u6587\u8ba8\u8bba\u7684\u60c5\u51b5\uff0c\u901a\u5e38\u53ea\u4f1a\u5728\u6bcf\u6b21\u7531\u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u968f\u673a\u7aef\u53e3\u7684\u7a0b\u5e8f\u8fd0\u884c\u7684\u673a\u5668\u4e0a\u51fa\u73b0\uff08\u6bcf\u6b21\u5206\u914d\u968f\u673a\u7aef\u53e3\uff0c\u5bfc\u81f4\u540e\u9762\u65e0\u7aef\u53e3\u53ef\u7528\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u67e5\u770b\u7cfb\u7edf\u7f51\u7edc\u914d\u7f6e\u548c\u5f53\u524dTCP\u72b6\u6001 &nbsp; &nbsp; &nbsp; &nbsp;\u5728\u5b9a\u4f4d\u5e76\u5904\u7406\u5e94\u7528\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.shuran.cn\/?p=845\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-845","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts\/845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=845"}],"version-history":[{"count":1,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts\/845\/revisions"}],"predecessor-version":[{"id":846,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts\/845\/revisions\/846"}],"wp:attachment":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}