如何使用fs.file-max和ulimit配置linux文件描述符限制

Linux上运行的服务器应用程序通常需要大量的打开文件处理程序,例如. HBase ulimit,Hadoop epoll limit

此Wiki条目应作为Linux文件限制配置的纪录片.

>什么是软限制与硬限制?
>如何控制硬限制?
>如何控制软限制?
>内核fs.file-max和用户ulimit -n是否相关?

请描述您的配置有效的Linux发行版,因为各个供应商以不同的方式配置内容.

根据lstvan回复更新:

对于希望自动执行此操作的人,至少在ubuntu服务器上,您可以将其放入计算机安装脚本中:

echo 'fs.file-max = 65000' > /etc/sysctl.d/60-file-max.conf
echo '* soft nofile 65000' > /etc/security/limits.d/60-nofile-limit.conf
echo '* hard nofile 65000' >> /etc/security/limits.d/60-nofile-limit.conf
echo 'root soft nofile 65000' >> /etc/security/limits.d/60-nofile-limit.conf
echo 'root hard nofile 65000' >> /etc/security/limits.d/60-nofile-limit.conf

解决方法

您的操作系统设置了主机上任何正在运行的应用程序可以打开的文件数量限制.您可以通过修改2个配置文件轻松扩展基本值1024(通常为1024):
# vi /etc/sysctl.conf

fs.file-max = 32000

# vi /etc/security/limits.conf

youruser       soft    nofile   10000
youruser       hard    nofile   30000

硬和软的限制:

man 5 limits.conf

hard
for enforcing hard resource limits. These limits are set by the superuser and 
enforced by the Kernel. The user cannot raise his requirement of system resources
above such values.

soft
for enforcing soft resource limits. These limits are ones that the user
can move up or down within the permitted range by any pre-exisiting hard 
limits. The values specified with this token can be thought of as default values,for normal system usage.

HTH

相关文章

在Linux上编写运行C语言程序,经常会遇到程序崩溃、卡死等异...
git使用小结很多人可能和我一样,起初对git是一无所知的。我...
1. 操作系统环境、安装包准备 宿主机:Max OSX 10.10.5 虚拟...
因为业务系统需求,需要对web服务作nginx代理,在不断的尝试...
Linux模块机制浅析 Linux允许用户通过插入模块,实现干预内核...
一、Hadoop HA的Web页面访问 Hadoop开启HA后,会同时存在两个...