Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370490
  • 博文数量: 50
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 41
  • 用 户 组: 普通用户
  • 注册时间: 2016-10-25 14:59
文章分类

全部博文(50)

文章存档

2019年(1)

2015年(14)

2014年(1)

2013年(6)

2012年(18)

2011年(10)

分类: iOS平台

2015-07-06 09:59:45

<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">&nbsp;</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;">&nbsp; 加入<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;">&nbsp;</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) |
给主人留下些什么吧!~~