码迷,mamicode.com
首页 > 其他好文 > 详细

file-max与ulimit的关系与差别

时间:2016-06-16 21:39:23      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

 1. file-max的含义

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

/proc/sys/fs/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.

 

即设置当前shell以及由它启动的进程的资源限制。

 

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

 

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

fs.file-max = 6553560

 

2.系统默认的ulimit对文件打开数量的限制是1024,修改/etc/security/limits.conf并加入以下配置,永久生效

* soft nofile 65535 
* hard nofile 65535

 

修改完之后,重启即可生效

file-max与ulimit的关系与差别

标签:

原文地址:http://www.cnblogs.com/zengkefu/p/5592117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!