linux最大允許的文件描述符open files數nofile修改


open file resource limit 是linux中process可以打開的文件句柄數量。增加這個數值需要調整兩個配置:


第一步,
修改系統最大允許的文件描述符


查看當前的設置:


$
cat /proc/sys/fs/file-max


2390251


或者


$
sysctl -a


fs.file-max
= 2390251


該系統是CentOS
5.x x64版本,安裝好后沒有做過優化設定, 2390251是其默認值


$
ulimit -n


1024


如果
/proc/sys/fs/file-max小於我們要設定的句柄數量,可以通過:


$echo
"2390251" > /proc/sys/fs/file-max


或者修改
/etc/sysctl.conf,在文件中修改fs.file-max的值(沒有就創建一條)


修改完后可以通過


$
sysctl -p


使設置生效


2.
文件描述符修改后,需要調整針對用戶或者組(user/group)的限制


/etc/security/limits.conf,文件格式為


<domain>
<type>  <item>  <value>


其中<type>為
soft或者hard,有些應用會自動把soft限制提升到hard限制,如java,至於nginx,沒有看到相關的文檔。


如:


*
- nofile  8192


表示對所有的用戶,文件描述符可以用到
8192, 或者


user_abc
- nofile  8192


表示對用戶
user_abc,文件描述符可以用到 8192


3.
有些情況 /etc/security/limits.conf並不會發生作用,如在 init.d 中啟用的進程,或者daemons運行的進程。


此時比較有效的辦法是在init的script中,明確命令
ulimit -n xxxxx


除了在系統中進行設定 nofile(fs.file-max) 值外,可以在 nginx.conf
中指定worker_process可以使用的nofile值,如:


#user  nobody;

worker_processes  3;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

error_log  logs/error.log  info;

pid        /var/run/nginx.pid;

worker_rlimit_nofile    8192;

events {

      use epoll;

      worker_connections  8192;

}

重新加載nginx配置,使新設定生效。


免責聲明!

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



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