zoukankan      html  css  js  c++  java
  • Cannot assign requested address

    解决 Cannot assign requested address 问题

    原因:
    这种情况一般发生在高并发服务器上或者压测时会出现。
    每个socket链接会占用本地一个端口,短链接使用毕后会立刻关闭,这时链接处于TIME_WAIT状态,本地的端口仍然被占用着。本地端口最多为6W个,如果在短时间内建立的大量的TCP短链接,本地端口会被TIME_WAIT迅速耗光,导致Cannot assign requested address

    解决方法:开启端口快速回收
    切换到root用户

    1、vim /etc/sysctl.conf
    2、添加或者修改
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 1
    3、保存
    4、运行 sysctl -p

     https://blog.csdn.net/weixin_30507481/article/details/97637914

    connect 失败

    • TCP 客户端程序发起大量 TCP 连接,但是当超过一定数量后,connect 失败,使用 strace 跟踪程序系统调用,发现如下信息

        socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 28232
        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)
      
    • 可以看出 connect 时,发生了 EADDRNOTAVAIL 错误

    原因

    • 经过分析,发生该错误的原因是该机器上的系统本地可用端口范围值(ip_local_port_range)限制了连接的数量,查看该值如下

        [root@localhost ~]# cat /proc/sys/net/ipv4/ip_local_port_range
        32768	61000
      
    • 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.

    • 可以计数得出,该配置下本地端口最多支持 28232 多个连接,当连接数已到达这个值,再 connect 的话就会发生 EADDRNOTAVAIL

    解决方法

    • 修改 ip_local_port_range 值, 在 /etc/sysctl.conf 中加入如下行

        net.ipv4.ip_local_port_range = 1024 65535
      
    • 然后执行如下命令使修改生效

        [root@localhost ~]# sysctl -p

    onnct端:

    [root@~]# netstat -apn |grep 27017 |wc -l
    28987
    [root@~]# cat /proc/sys/net/ipv4/ip_local_port_range
    32768 60999

    server端:


    [root@~]# netstat -apn |grep 27017 |wc -l
    28989

    kill掉 mongodb重启后,已启动立马是这样:

    [root@host]# netstat -apn |grep 27017 |wc -l
    741
    [root@host]# netstat -apn |grep 27017 |wc -l
    14480
    [root@host]# netstat -apn |grep 27017 |wc -l
    18358
    [root@host]# netstat -apn |grep 27017 |wc -l
    18769
    [root@host]# netstat -apn |grep 27017 |wc -l
    21736
    [root@host]# netstat -apn |grep 27017 |wc -l
    28232
    [root@host]# netstat -apn |grep 27017 |wc -l
    28232
    [root@host]# netstat -apn |grep 27017 |wc -l
    28232
    [root@host]# netstat -apn |grep 27017 |wc -l
    28232

  • 相关阅读:
    解决中文环境下zabbix监控图形注释乱码
    SSIS CDC(Change Data Capture)组件在数据库中启用报错。 The error returned was 14234: 'The specified '@server' is invalid
    Tableau 群集部署
    访问Tableau自带的PostgreSQL数据库
    [译]Stairway to Integration Services Level 18 – 部署和执行
    [译]Stairway to Integration Services Level 16 – Flexible Source Locations (多文件导入)
    [译]Stairway to Integration Services Level 15 – SSIS 参数回顾
    [译]Stairway to Integration Services Level 14
    [译]Stairway to Integration Services Level 13
    [译]Stairway to Integration Services Level 12
  • 原文地址:https://www.cnblogs.com/youxin/p/14589106.html
Copyright © 2011-2022 走看看