nginx報錯socket() failed (24: Too many open files)【轉】


nginx 錯誤日志:

1
2
2016/02/28 21:07:36 [alert] 11569#0: *41512 socket() failed (24: Too many open files)  while  connecting to upstream, client: 192.168.1.110, server: localhost, request:  "GET / HTTP/1.1" , upstream:  "http://127.0.0.1:8080/" , host:  "192.168.1.218"
2016/02/28 21:07:36 [alert] 11569#0: *41512 socket() failed (24: Too many open files)  while  connecting to upstream, client: 192.168.1.110, server: localhost, request:  "GET / HTTP/1.1" , upstream:  "http://127.0.0.1:8080/" , host:  "192.168.1.218"
1
解決辦法:

一、Linux打開文件最大數設置

查看打開文件最大數

ulimit -a

設置一

ulimit -HSn 102400 #只是當前shell有效

設置二

(1)ulimit -HSn 102400

(2)將ulimit -HSn 102400寫到/etc/profile中,因為每次登錄終端時,都會自動執行/etc/profile。

(3)令修改open files的數值永久生效,則必須修改配置文件:vi /etc/security/limits.conf. 在這個文件后加上:

* soft nofile 102400

* hard nofile 102400

這種方法需要重啟機器才能生效。

另一個,查看下nginx的配置文件。

查看 worker_rlimit_nofile 配置項

worker_rlimit_nofile 655350;

二、nginx打開文件最大數設置

nginx worker_rlimit_nofile Option (在nginx級別上提高打開的文件句柄限制)

nginx也有同樣的限制,可以通過worker_rlimit_nofile來增加此限制數量。 來設置被nginx進程最大文件打開的數量,編輯nginx.conf文件,鍵入:

vi /usr/local/nginx/conf/nginx.conf (視你的配置文件的位置而定)

追加或者編輯:

worker_rlimit_nofile   30000;

保存並關閉文件,重新加載nginx配置,並重新執行開始查看軟硬限制的命令:

su - nginx

ulimit -Hn

ulimit -Sn

輸入示例:

30000

10000

其實在國內的網站是上搜到的內容大都講的差不多了,原先我也如此,但一直沒有解決,最后發現最關鍵的參數沒設置,故一直不能超過1024個active conntions. 通過設置此參數即可解決:

worker_rlimit_nofile   30000;

三、Linux操作系統中打開文件數量的查看方法

ulimit -n 4096

也就是限制用戶的最大文件打開數為4096個

 

在網上查了關於怎么查看文件打開數的文章大致有兩種說法

 

/proc/sys/fs/file-nr

該文件與 file-max 相關,它有三個值:

 

已分配文件句柄的數目

已使用文件句柄的數目

文件句柄的最大數目

該文件是只讀的,僅用於顯示信息。

 

查看所有進程的文件打開數

lsof |wc -l

 

查看某個進程打開的文件數

lsof -p pid |wc -l

 

英文原文:
Syntax: worker_rlimit_nofile number;
Default:    —
Context:    main
Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes. Used to increase the limit without restarting the main process.

中文翻譯:
為nginx工作進程改變打開最多文件描述符數目的限制。用來在不重啟主進程的情況下增加限制。

例如:
worker_rlimit_nofile 204800;
理論上這個值是最多打開文件數(ulimit -n)與nginx工作進程相除。

 

 

轉自

nginx socket() failed (24: Too many open files) - 王恆志 - 博客園
https://www.cnblogs.com/xzlive/p/14973823.html

Nginx: 24: Too Many Open Files 錯誤和解決方案 - 房客 - 博客園
https://www.cnblogs.com/sxlfybb/archive/2011/09/15/2177983.html

Linux操作系統中打開文件數量的查看方法 - 心靈捕手 - 博客園 https://www.cnblogs.com/Dennis-mi/articles/6084581.html

(24條消息) nginx學習隨筆--worker_rlimit_nofile_zhxuewu的專欄-CSDN博客_worker_rlimit_nofile

https://blog.csdn.net/zhxuewu/article/details/77932441

  • 英文原文:
Syntax: worker_rlimit_nofile number;
Default: 
Context:  main
  • 1
  • 2
  • 3

Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes. Used to increase the limit without restarting the main process.

  • 中文翻譯:

    為nginx工作進程改變打開最多文件描述符數目的限制。用來在不重啟主進程的情況下增加限制。
    
    • 1

例如:

worker_rlimit_nofile 204800;
  • 1

理論上這個值是最多打開文件數(ulimit -n)與nginx工作進程相除。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM