java.net.NoRouteToHostException: You can not specify the requested address

Today stress tests, the beginning there have been many exceptions, are java.net.NoRouteToHostException: Can not assign requested address.
Through the Internet to find information, because of the distribution of linux client connection port exhausted, unable to establish a socket connection caused, though socket normally closed, but the port is not released immediately, but in the TIME_WAIT state, the default wait 60s after release.
View linux support client connections port range is 28,232 ports:
CAT / proc / SYS / NET / ipv4 / ip_local_port_range
32768 - 60999

解决方法:
1. 调低端口释放后的等待时间, 默认为60s, 修改为15~30s
    echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
2. 修改tcp/ip协议配置, 通过配置/proc/sys/net/ipv4/tcp_tw_resue, 默认为0, 修改为1, 释放TIME_WAIT端口给新连接使用。
    echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
3. 修改tcp/ip协议配置,快速回收socket资源,  默认为0, 修改为1.
    echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle

Guess you like

Origin blog.csdn.net/weixin_42691754/article/details/83789320