当前位置:   article > 正文

[nginx] too many open files_nginx: [emerg] socket() 0.0.0.0:41013 failed (24:

nginx: [emerg] socket() 0.0.0.0:41013 failed (24: too many open files)

错误log

2020/12/24 06:39:09 [alert] 8315#0: *4128715829 socket() failed (24: Too many open files) while connecting to upstream, client: xxxx, server: xxxx, request: "GET /client/v3/wallpaper_4k/wallpaperList.json?sign=9939e1fa528ec5b4b1145e2045483929&packageName=com.depth.visual.wallpaper4d&versionCode=22&tm=1608791954296&page=1&pageSize=20 HTTP/1.1", upstream: "http://10.0.0.103:8301/client/v3/wallpaper_4k/wallpaperList.json?sign=9939e1fa528ec5b4b1145e2045483929&packageName=com.depth.visual.wallpaper4d&versionCode=22&tm=1608791954296&page=1&pageSize=20", host: "xxxx"
  • 1

解决方法

原因很明显Too many open files, Google解决方法,对比多个,尝试最靠谱的;

  1. ps aux | grep nginx 查看nginx worker的pid; cat /proc/pid/limits 查看限制
    在这里插入图片描述

    如图,soft open files的只只有1024

  2. 调大soft open files

    # /etc/security/limits.conf 文件中添加 * soft nofile 65535
    # 运行命令生效
    sysctl -p
    nginx -s reload
    
    # 再去查看nginx进程的limits, 并没有变化
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

在这里插入图片描述

# vim /usr/local/nginx/conf/nginx.conf  
  
worker_rlimit_nofile 65535;  //添加

events {
  use epoll;
  worker_connections  65535; //足够大了,不用改
}

root@ip-10-0-0-18:/home/logs/api# nginx  -t 
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
root@ip-10-0-0-18:/home/logs/api# nginx  -s reload

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

在这里插入图片描述

查看limits已生效,check error_log 没有再报错了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/660219
推荐阅读
相关标签
  

闽ICP备14008679号