{"id":1547,"date":"2023-03-25T16:41:29","date_gmt":"2023-03-25T08:41:29","guid":{"rendered":"http:\/\/175.24.184.226\/?p=1547"},"modified":"2023-03-25T16:41:29","modified_gmt":"2023-03-25T08:41:29","slug":"%e8%a7%a3%e5%86%b3-cannot-assign-requested-address-%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"\/?p=1547","title":{"rendered":"\u89e3\u51b3 Cannot assign requested address \u95ee\u9898"},"content":{"rendered":"<h1>\u89e3\u51b3 Cannot assign requested address \u95ee\u9898<\/h1>\n<p>\u539f\u56e0\uff1a<br \/>\n\u8fd9\u79cd\u60c5\u51b5\u4e00\u822c\u53d1\u751f\u5728\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u4e0a\u6216\u8005\u538b\u6d4b\u65f6\u4f1a\u51fa\u73b0\u3002<br \/>\n\u6bcf\u4e2asocket\u94fe\u63a5\u4f1a\u5360\u7528\u672c\u5730\u4e00\u4e2a\u7aef\u53e3\uff0c\u77ed\u94fe\u63a5\u4f7f\u7528\u6bd5\u540e\u4f1a\u7acb\u523b\u5173\u95ed\uff0c\u8fd9\u65f6\u94fe\u63a5\u5904\u4e8eTIME_WAIT\u72b6\u6001\uff0c\u672c\u5730\u7684\u7aef\u53e3\u4ecd\u7136\u88ab\u5360\u7528\u7740\u3002\u672c\u5730\u7aef\u53e3\u6700\u591a\u4e3a6W\u4e2a\uff0c\u5982\u679c\u5728\u77ed\u65f6\u95f4\u5185\u5efa\u7acb\u7684\u5927\u91cf\u7684TCP\u77ed\u94fe\u63a5\uff0c\u672c\u5730\u7aef\u53e3\u4f1a\u88abTIME_WAIT\u8fc5\u901f\u8017\u5149\uff0c\u5bfc\u81f4Cannot assign requested address<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a\u5f00\u542f\u7aef\u53e3\u5feb\u901f\u56de\u6536<br \/>\n\u5207\u6362\u5230root\u7528\u6237<\/p>\n<p>1\u3001vim \/etc\/sysctl.conf<br \/>\n2\u3001\u6dfb\u52a0\u6216\u8005\u4fee\u6539<br \/>\nnet.ipv4.tcp_tw_reuse = 1<br \/>\nnet.ipv4.tcp_tw_recycle = 1<br \/>\n3\u3001\u4fdd\u5b58<br \/>\n4\u3001\u8fd0\u884c sysctl -p<\/p>\n<p><a href=\"https:\/\/blog.csdn.net\/weixin\\_30507481\/article\/details\/97637914\">https:\/\/blog.csdn.net\/weixin\\_30507481\/article\/details\/97637914<\/a><\/p>\n<p>\\<\/p>\n<h4>connect \u5931\u8d25<\/h4>\n<ul>\n<li>\n<p>TCP \u5ba2\u6237\u7aef\u7a0b\u5e8f\u53d1\u8d77\u5927\u91cf TCP \u8fde\u63a5\uff0c\u4f46\u662f\u5f53\u8d85\u8fc7\u4e00\u5b9a\u6570\u91cf\u540e\uff0cconnect \u5931\u8d25\uff0c\u4f7f\u7528 strace \u8ddf\u8e2a\u7a0b\u5e8f\u7cfb\u7edf\u8c03\u7528\uff0c\u53d1\u73b0\u5982\u4e0b\u4fe1\u606f<\/p>\n<pre><code>  socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 28232\n  connect(28232, {sa_family=AF_INET, sin_port=htons(26800), sin_addr=inet_addr(\"192.168.154.201\")}, 16) = -1 EADDRNOTAVAIL (Cannot assign requested address)\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u53ef\u4ee5\u770b\u51fa connect \u65f6\uff0c\u53d1\u751f\u4e86 EADDRNOTAVAIL \u9519\u8bef<\/p>\n<\/li>\n<\/ul>\n<h4>\u539f\u56e0<\/h4>\n<ul>\n<li>\n<p>\u7ecf\u8fc7\u5206\u6790\uff0c\u53d1\u751f\u8be5\u9519\u8bef\u7684\u539f\u56e0\u662f\u8be5\u673a\u5668\u4e0a\u7684\u7cfb\u7edf\u672c\u5730\u53ef\u7528\u7aef\u53e3\u8303\u56f4\u503c(ip_local_port_range)\u9650\u5236\u4e86\u8fde\u63a5\u7684\u6570\u91cf\uff0c\u67e5\u770b\u8be5\u503c\u5982\u4e0b<\/p>\n<pre><code>  [root@localhost ~]# cat \/proc\/sys\/net\/ipv4\/ip_local_port_range\n  32768 61000\n<\/code><\/pre>\n<\/li>\n<li>\n<p>The \/proc\/sys\/net\/ipv4\/ip_local_port_range defines the local port range that is used by TCP and UDP traffic to choose the local port. You will see in the parameters of this file two numbers: The first number is the first local port allowed for TCP and UDP traffic on the server, the second is the last local port number. For high-usage systems you may change its default parameters to 32768-61000 -first-last.<\/p>\n<\/li>\n<li>\n<p>\u53ef\u4ee5\u8ba1\u6570\u5f97\u51fa\uff0c<strong>\u8be5\u914d\u7f6e\u4e0b\u672c\u5730\u7aef\u53e3\u6700\u591a\u652f\u6301 28232 \u591a\u4e2a\u8fde\u63a5\uff0c\u5f53\u8fde\u63a5\u6570\u5df2\u5230\u8fbe\u8fd9\u4e2a\u503c\uff0c\u518d connect \u7684\u8bdd\u5c31\u4f1a\u53d1\u751f EADDRNOTAVAIL<\/strong><\/p>\n<\/li>\n<\/ul>\n<h4>\u89e3\u51b3\u65b9\u6cd5<\/h4>\n<ul>\n<li>\n<p>\u4fee\u6539 ip_local_port_range \u503c\uff0c \u5728 \/etc\/sysctl.conf \u4e2d\u52a0\u5165\u5982\u4e0b\u884c<\/p>\n<pre><code>  net.ipv4.ip_local_port_range = 1024 65535\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u7136\u540e\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u4f7f\u4fee\u6539\u751f\u6548<\/p>\n<pre><code>  [root@localhost ~]# sysctl -p<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>onnct\u7aef:<\/p>\n<p>[root@~]# netstat -apn |grep 27017 |wc -l<br \/>\n28987<br \/>\n[root@~]# cat \/proc\/sys\/net\/ipv4\/ip_local_port_range<br \/>\n32768 60999<\/p>\n<p>server\u7aef:<\/p>\n<p>[root@~]# netstat -apn |grep 27017 |wc -l<br \/>\n28989<\/p>\n<p>kill\u6389 mongodb\u91cd\u542f\u540e\uff0c\u5df2\u542f\u52a8\u7acb\u9a6c\u662f\u8fd9\u6837:<\/p>\n<p>[root@host]# netstat -apn |grep 27017 |wc -l<br \/>\n741<br \/>\n[root@host]# netstat -apn |grep 27017 |wc -l<br \/>\n14480<br \/>\n[root@host]# netstat -apn |grep 27017 |wc -l<br \/>\n18358<br \/>\n[root@host]# netstat -apn |grep 27017 |wc -l<br \/>\n18769<br \/>\n[root@host]# netstat -apn |grep 27017 |wc -l<br \/>\n21736<br \/>\n[root@host]# netstat -apn |grep 27017 |wc -l<br \/>\n28232<br \/>\n[root@host]# netstat -apn |grep 27017 |wc -l<br \/>\n28232<br \/>\n[root@host]# netstat -apn |grep 27017 |wc -l<br \/>\n28232<br \/>\n[root@host]# netstat -apn |grep 27017 |wc -l<br \/>\n28232<\/p>\n<p>\u672c\u6587\u8f6c\u81ea <a href=\"https:\/\/www.cnblogs.com\/youxin\/p\/14589106.html\">https:\/\/www.cnblogs.com\/youxin\/p\/14589106.html<\/a>\uff0c\u5982\u6709\u4fb5\u6743\uff0c\u8bf7\u8054\u7cfb\u5220\u9664\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u51b3 Cannot assign requested address \u95ee\u9898 \u539f\u56e0\uff1a \u8fd9\u79cd\u60c5\u51b5\u4e00\u822c\u53d1\u751f\u5728\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u4e0a\u6216\u8005\u538b\u6d4b\u65f6\u4f1a\u51fa\u73b0\u3002    \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[14],"tags":[],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1547"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1547"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1547\/revisions"}],"predecessor-version":[{"id":1548,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1547\/revisions\/1548"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1547"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}