1. NR_OPEN is the maximum number of files that can be opened by process




    A process cannot use more than NR_OPEN file descriptors.




The kernel also enforces a dynamic bound on the maximum number of file descriptors in the signal->rlim[RLIMIT_NOFILE] structure of the process descriptor; this value is usually 1,024, but it can be raised if the process has root privileges.




2. NR_FILE is the limit on total number of files in the system at any given point in time


    NR_FILE 是系统在某一给定时刻,限制的文件总数


在linux kernel 2.6.25之前通过ulimit -n(setrlimit(RLIMIT_NOFILE))设置每个进程的最大打开文件句柄数不能超过NR_OPEN (1024*1024),也就是100多w(除非重新编译内核),而在25之后,内核导出了一个sys接口可以修改这个最大值(/proc/sys/fs /nr_open).具体的changelog在这里


1. file-max的含义

man proc,可得到file-max的描述:

              This  file defines a system-wide limit on the number of open files for all processes.  (See
              also setrlimit(2),  which  can  be  used  by  a  process  to  set  the  per-process  limit,
              RLIMIT_NOFILE,  on  the  number  of  files it may open.)  If you get lots of error messages
              about running out of file handles, try increasing this value:

即file-max是设置 系统所有进程一共可以打开的文件数量 。同时一些程序可以通过setrlimit调用,设置每个进程的限制。如果得到大量使用完文件句柄的错误信息,是应该增加这个值。




echo  6553560 > /proc/sys/fs/file-max            //因为是在/proc文件系统中,重起失效

或修改 /etc/sysctl.conf, 加入                           // 永久生效

fs.file-max = 6553560 重启生效


2. ulimit的   //暂时生效

Provides control over the resources available to the shell and to processes started by it, on systems that allow  such control.




显然,对服务器来说,file-max, ulimit都需要设置,否则就可能出现文件描述符用尽的问题,为了让机器在重启之后仍然有效,强烈建立作以下配置,以确保file-max, ulimit的值正确无误:


1. 修改/etc/sysctl.conf, 加入             

fs.file-max = 6553560



* soft nofile 65535 
* hard nofile 65535





3./proc/sys/fs /nr_open





posted @ 2016-06-16 20:35  zengkefu  阅读(...)  评论(...编辑  收藏