【原创】如何在 Linux 下调整可打开文件/文件描述符数目

简介:
How do I increase the maximum number of open files under CentOS Linux? How do I open more file descriptors under Linux?  

The ulimit command provides control over the resources available to the shell and/or to processes started by it, on systems that allow such control. The maximum number of open file descriptors displayed with following command (login as the root user).  
ulimit 命令提供了针对 shell  和/或由该 shell 启动的进程占用资源的控制。  

Command To List Number Of Open File Descriptors  

Use the following command to display maximum number of open file descriptors:  
?
1
cat /proc/sys/fs/file-max    -- 显示单个登陆会话允许打开的 fd 数目
Output:  
?
1
75000
75000 files normal user can have open in  single login session   . To see the hard and soft values, issue the command as follows:  
?
1
2
# ulimit -Hn
# ulimit -Sn
To see the hard and soft values for httpd or oracle user, issue the command as follows:  
通过切换登陆用户,可以查看针对特定登陆用户所设置的 fd 限制数目。  
?
1
# su - username
In this example, su to oracle user, enter:  
?
1
2
3
# su - oracle
$ ulimit -Hn
$ ulimit -Sn

System-wide File Descriptors (FD) Limits  

The number of concurrently open file descriptors throughout the system can be changed via  /etc/sysctl.conf   file under Linux operating systems.  
系统范围级别的 fd 数量控制需要编辑 /etc/sysctl.conf 内核参数配置文件。  

The Number Of Maximum Files Was Reached, How Do I Fix This Problem?  

Many application such as Oracle database or Apache web server needs this range quite higher. So you can increase the maximum number of open files by setting a new value in kernel variable /proc/sys/fs/file-max as follows (login as the root):  
通过调整内核参数    /proc/sys/fs/file-max 来增加可打开 fd 数目。  
?
1
# sysctl -w fs.file-max=100000   -- 这种方式只能临时修改 fd 数目限制
Above command forces the limit to 100000 files. You need to edit /etc/sysctl.conf file and put following line so that after reboot the setting will remain as it is:  
通过修改 /etc/sysctl.conf 文件,可以在令针对 fd 的修改一直生效。  
?
1
# vi /etc/sysctl.conf
Append a config directive as follows:  
?
1
fs. file -max = 100000  -- 系统范围内修改 fd 数目
Save and close the file. Users need to log out and log back in again to changes take effect or just type the following command:  
?
1
# sysctl -p   -- 不用重启系统令修改生效的方法
Verify your settings with command:  
?
1
# cat /proc/sys/fs/file-max
OR  
?
1
# sysctl fs.file-max

User Level FD Limits  

The above procedure sets system-wide file descriptors (FD) limits. However, you can limit httpd (or any other users) user to specific limits by editing  /etc/security/limits.conf   file, enter:  
通过修改 /etc/security/limits.conf 文件可以在用户级别对 fd 进行限制。  
?
1
# vi /etc/security/limits.conf
Set httpd user soft and hard limits as follows:  
?
1
2
httpd soft nofile 4096   -- 针对 httpd 用户做 fd 限制
httpd hard nofile 10240
Save and close the file. To see limits, enter:  
?
1
2
3
# su - httpd
$ ulimit -Hn
$ ulimit -Sn
目录
相关文章
|
16天前
|
人工智能 安全 Linux
【Linux】Linux之间如何互传文件(详细讲解)
【Linux】Linux之间如何互传文件(详细讲解)
|
2天前
|
Linux Shell 开发工具
Linux文件常用操作
Linux文件常用操作(几乎覆盖所有日常使用)
51 0
|
3天前
|
Linux 内存技术 Perl
【ZYNQ】制作从 QSPI Flash 启动 Linux 的启动文件
【ZYNQ】制作从 QSPI Flash 启动 Linux 的启动文件
|
9天前
|
Linux 索引
linux 文件查找 和文件管理常用命令
linux 文件查找 和文件管理常用命令
19 0
|
11天前
|
监控 Linux
|
16天前
|
存储 Ubuntu Linux
制作一个嵌入式Linux的应用程序升级文件
制作一个嵌入式Linux的应用程序升级文件
12 2
|
17天前
|
Linux Shell
Linux脚本获取输入参数判断文件还是文件路径
Linux脚本获取输入参数判断文件还是文件路径
12 4
|
3月前
|
Linux
百度搜索:蓝易云【Linux中如何对文件进行压缩和解压缩?】
这些是在Linux中进行文件压缩和解压缩的常见方法。根据您的需求和具体情况,可能会使用其他压缩工具和选项。您可以通过查阅相应命令的帮助文档来获取更多详细信息。
53 1
|
4月前
|
NoSQL Java Linux
Linux常用命令(文件目录操作、拷贝移动、打包压缩、文本编辑、查找)
Linux常用命令(文件目录操作、拷贝移动、打包压缩、文本编辑、查找)
|
4月前
|
算法 Java Linux
Linux下文件增删改查定位压缩操作与权限所属用户
Linux下文件增删改查定位压缩操作与权限所属用户
41 0