转 Cannot assign requested address出现的原因及解决方案
Posted python-xiakaibi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了转 Cannot assign requested address出现的原因及解决方案相关的知识,希望对你有一定的参考价值。
客户端(linux服务器)jmeter压测服务端,出现Cannot assign requested address错误
网上找了下原因,大致上是由于客户端频繁的连服务器,由于每次连接都在很短的时间内结束,导致很多的TIME_WAIT,以至于用光了可用的端 口号,所以新的连接没办法绑定端口,即“Cannot assign requested address”。是客户端的问题不是服务器端的问题。通过netstat,的确看到很多TIME_WAIT状态的连接。
client端频繁建立连接,而端口释放较慢,导致建立新连接时无可用端口
netstat -a|grep TIME_WAIT
tcp 0 0 e100069210180.zmf:49477 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49481 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49469 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49505 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49547 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49513 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49543 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49571 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49488 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49582 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49476 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49462 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49561 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49259 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49371 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49455 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49572 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49509 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49546 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49539 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49468 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49496 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49313 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49479 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49486 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49452 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49500 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49447 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49580 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49565 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49454 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49499 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49494 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49591 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49566 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49557 e100069202104.zmf.tbs:websm TIME_WAIT
tcp 0 0 e100069210180.zmf:49495 e100069202104.zmf.tbs:websm TIME_WAIT
————————————————
版权声明:本文为CSDN博主「fzhqcjc」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/fzhqcjc/article/details/84924724
解决办法
执行命令修改如下内核参数 (需要root权限)
调低端口释放后的等待时间,默认为60s,修改为15~30s:
sysctl -w net.ipv4.tcp_fin_timeout=30
sysctl -w net.ipv4.tcp_timestamps=1
修改tcp/ip协议配置,快速回收socket资源,默认为0,修改为1:
sysctl -w net.ipv4.tcp_tw_recycle=1
允许端口重用:
sysctl -w net.ipv4.tcp_tw_reuse = 1
(修改tcp/ip协议配置, 通过配置/proc/sys/net/ipv4/tcp_tw_resue, 默认为0,修改为1,释放TIME_WAIT端口给新连接使用)
以上是关于转 Cannot assign requested address出现的原因及解决方案的主要内容,如果未能解决你的问题,请参考以下文章
[译]Python - socket.error: Cannot assign requested address
Cannot assign requested address 问题
Irssi Error [Cannot assign requested address: x.x.x.x]
etcd bind: cannot assign requeste d address