西数超哥博客
运维经验教程分享

Linux系统内核参数file-max与ulimit的关系与差别

简单的说, max-file表示系统级别的能够打开的文件句柄的数量, 而ulimit -n控制进程级别能够打开的文件句柄的数量.
提供大量静态文件访问的web服务器,缓存服务器(如squid), 均要注意这个问题

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
或修改 /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://zhangxugg-163-com.iteye.com/blog/1108402
Linux系统级别能够打开的文件句柄的数file-max命令:http://www.cnblogs.com/hanyifeng/p/5258774.html

转载请注明:西数超哥博客www.ysidc.top» Linux系统内核参数file-max与ulimit的关系与差别

https://www.ysidc.top 西数超哥博客,数据库,西数超哥,虚拟主机,域名注册,域名,云服务器,云主机,云建站,ysidc.top

赞(0)
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除。本站原创内容未经允许不得转载:西数超哥博客 » Linux系统内核参数file-max与ulimit的关系与差别