<span style="font:16px/26px NSimSun;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">场景:一台服务器上运行了多个程序各个程序有自己固定的端口,程序会对外发起连接,所以程序除占用自身的固定端口还用占用其他随机端口。</span><br style="font:12px/26px 宋体, Arial;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;" />
<span style="font:16px/26px NSimSun;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"></span><span style="font:16px/26px NSimSun;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">如果应用程序对外tcp连接占用的是其他应用程序的固定端口,就会造成这个应用程序不能启动,提示端口已经被占用。</span><br style="font:12px/26px 宋体, Arial;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;" />
<span style="font:16px/26px NSimSun;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"></span><br style="font:12px/26px 宋体, Arial;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;" />
<span style="font:16px/26px NSimSun;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">解决方法:定义系统对外发起的tcp连接占用的端口范围。</span><br style="font:12px/26px 宋体, Arial;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;" />
<span style="font:16px/26px NSimSun;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"></span><br style="font:12px/26px 宋体, Arial;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;" />
<span style="font:16px/26px NSimSun;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">具体方法:</span><br style="font:12px/26px 宋体, Arial;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;" />
<span style="font:16px/26px NSimSun;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"></span><span style="font:12px/26px 宋体, Arial;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;display:inline !important;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"></span>
<p style="font:12px/26px 宋体, Arial;margin:5px 0px 5px 18pt;padding:0px;text-align:left;color:#666666;text-transform:none;text-indent:-18pt;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">
<span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">1、<span class="Apple-converted-space"> </span></span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;background-color:#CCCCCC;">vim /etc/sysctl.conf</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;"> 加入<br style="-ms-word-wrap:break-word;" />
</span><span style="line-height:1.5;text-indent:0cm;font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;"> </span>
</p>
<p style="font:12px/26px 宋体, Arial;margin:5px 0px 5px 18pt;padding:0px;text-align:left;color:#666666;text-transform:none;text-indent:-18pt;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">
<span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">2、 定义对外访问端口范围</span><span style="-ms-word-wrap:break-word;"></span>
</p>
<p style="font:12px/26px 宋体, Arial;margin:5px 0px;padding:0px;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">
<span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;"><span style="-ms-word-wrap:break-word;background-color:#CCCCCC;">net.ipv4.ip_local_port_range = 起始端口 终止端口</span>(例如</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">net.ipv4.ip_local_port_range = 5000 6550</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">)</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">,linux</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">的端口范围是</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">1-65535;</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">默认<br style="-ms-word-wrap:break-word;" />
对外的端口</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">范围:</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;"></span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">32768-61000;</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">1-1024</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">是系统端口;可设置的端口范围是</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">1024-65535。</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">保证设置的端口范围中不包括应用程序的端口,端口范围尽<br style="-ms-word-wrap:break-word;" />
可能的大。<br style="-ms-word-wrap:break-word;" />
</span><br style="-ms-word-wrap:break-word;" />
<span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;"></span>
</p>
<p style="font:12px/26px 宋体, Arial;margin:5px 0px 5px 18pt;padding:0px;text-align:left;color:#666666;text-transform:none;text-indent:-18pt;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">
<span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">3、 打开</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">linux</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">快速释放</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">TIME_WAIT</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">的功能(尽量避免端口不够用的现象)</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">:</span>
</p>
<p style="font:12px/26px 宋体, Arial;margin:5px 0px;padding:0px;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">
<span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;background-color:#CCCCCC;">net.ipv4.tcp_tw_recycle = 1</span>
</p>
<p style="font:12px/26px 宋体, Arial;margin:5px 0px;padding:0px;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">
<span style="-ms-word-wrap:break-word;background-color:#CCCCCC;"><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">net.ipv4.tcp_timestamps = 1</span><br style="-ms-word-wrap:break-word;" />
<span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;"></span></span>
</p>
<p style="font:12px/26px 宋体, Arial;margin:5px 0px;padding:0px;text-align:left;color:#666666;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;-ms-word-wrap:break-word;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;background-color:#FFFFFF;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">
<span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;">4、运行</span><span style="font-family:NSimSun;font-size:16px;-ms-word-wrap:break-word;background-color:#CCCCCC;">sysctl -p</span>
</p>
阅读(2158) | 评论(0) | 转发(0) |