nginx socket() failed (24: Too many open files)

访问量的增大,相应nginx连接数,以及打开的文件数,是需要调整的,不然就会报以下错误

2019/10/10 16:04:37 [alert] 364127#0: *11935302 socket() failed (24: Too many open files) while connecting to upstream, client: 220.195.66.66, server:。。。。。。。。。。。。。。。。。

 

说正文前,先看一下,流量图

最近一周平均2000多万,一台nginx反代了四台

1,查看打开文件的限制

[root@namenode1 nginx]# ulimit -Hn  //硬  
10240  
[root@namenode1 nginx]# ulimit -Sn  //软  
10240 

这个配置已不够,要加大

2,加大可打文件的上限

[root@namenode1 nginx]# vim /etc/security/limits.conf  //尾部追回  
  
* soft nofile 65535  
* hard nofile 65535  
  
[root@namenode1 nginx]# sysctl -p  //配置生效  

*的意思是所有用户,也可以nginx soft nofile 65535,表示只调整nginx用户的打开文件上限。

重新登录或者重新ssh,ulimit -Hn才能看到变化

[root@namenode1 ~]# ulimit -Hn  
65535  
[root@namenode1 ~]# ulimit -Sn  
65535  

3,配置nginx

# vim /etc/nginx/nginx.conf  
  
worker_rlimit_nofile 65535;  //添加  
  
events {  
    worker_connections 20480;   //修改  
}  
  
[root@namenode1 nginx]# nginx -t  
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
nginx: configuration file /etc/nginx/nginx.conf test is successful  
  
[root@namenode1 nginx]# systemctl reload nginx  

worker_connections这个参数,建议逐步加大。

重载后,error.log就没有报这个错误了

 
posted @ 2022-11-25 23:44  MR__Wang  阅读(471)  评论(0编辑  收藏  举报