首页 > 其他 > 详细

file-max与ulimit的关系与差别

时间:2016-06-16 21:38:32      阅读:184      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!