`

修改Linux下最大open files 数

阅读更多

Redhat 帮助文档[http://kbase.redhat.com/faq/FAQ_80_1540.shtm]
Issue:
How do I set the maximum number of files allowed to be open on a system
Resolution:
The current setting for maximum number of open files can be viewed with the command:

    ulimit -n

This number indicates the maximum number of files normal users (i.e. non-root) can have open in a single session. Note that for the root user, ulimit -n will sometimes output 1024 even after following the procedure to increase the maximum number of open files. This won't effect root's ability to open large numbers of files, as only normal users are bound by this value.

To increase the maximum number of open files beyond the default of 1024, two changes to the system may be necessary. In these examples, we will increase the maximum number of open files to the arbitrary value of 2048. All changes need to be made by the root user and users will need to log out and log back in before the changes will take effect.

   1. Configure the system to accept the desired value for maximum number of open files Check the value in /proc/sys/fs/file-max to see if it is larger than the value needed for the maximum number of open files:

      # cat /proc/sys/fs/file-max

      If the value isn't large enough, echo an appropriate number into the variable and add the change to /etc/sysctl.conf to make it persistent across reboots. If the number is already larger than the value you wish to use, skip to step 2.

      # echo 2048 > /proc/sys/fs/file-max

      and edit /etc/sysctl.conf to include the line:

      fs.file-max = 2048

   2. Set the value for maximum number of open files In the file /etc/security/limits.conf, below the commented line that reads

      #<domain>      <type>  <item>         <value>

      add this line:

      * - nofile 2048

      This line sets the default number of open file descriptors for every user on the system to 2048. Note that the "nofile" item has two possible limit values under the <type> header: hard and soft. Both types of limits must be set before the change in the maximum number of open files will take effect. By using the "-" character, both hard and soft limits are set simultaneously.

      The hard limit represents the maximum value a soft limit may have and the soft limit represents the limit being actively enforced on the system at that time. Hard limits can be lowered by normal users, but not raised and soft limits cannot be set higher than hard limits. Only root may raise hard limits.

When increasing file limit descriptors, you may want to simply double the value. For example, if you need to increase the default value of 1024, increase the value to 2048 first. If you need to increase it again, try 4096, etc.


==================================================================
1。ulimit -a 查看系统目前资源限制的设定。
[root@test security]# ulimit -a
core file size        (blocks, -c) 0
data seg size         (kbytes, -d) unlimited
file size             (blocks, -f) unlimited
max locked memory     (kbytes, -l) unlimited
max memory size       (kbytes, -m) unlimited
open files                    (-n) 1024
pipe size          (512 bytes, -p) 8
stack size            (kbytes, -s) 8192
cpu time             (seconds, -t) unlimited
max user processes            (-u) 7168
virtual memory        (kbytes, -v) unlimited
[root@test security]#
通过以上命令,我们可以看到open files 的最大数为1024
那么我们可以通过一下命令修改该参数的最大值
2. ulimit -n 4096
[root@test security]# ulimit -n 4096
[root@test security]# ulimit -a
core file size        (blocks, -c) 0
data seg size         (kbytes, -d) unlimited
file size             (blocks, -f) unlimited
max locked memory     (kbytes, -l) unlimited
max memory size       (kbytes, -m) unlimited
open files                    (-n) 4096
pipe size          (512 bytes, -p) 8
stack size            (kbytes, -s) 8192
cpu time             (seconds, -t) unlimited
max user processes            (-u) 7168
virtual memory        (kbytes, -v) unlimited

这样我们就修改了系统在同一时间打开文件资源的最大数,基本解决以上问题。

另外我们可以通过lsof  -p [进程的 pid]来查看系统当前打开的文件资源,可以了解不同时期系统的文件资源的使用情况,可根据情况进行系统资源的配置。
===================================================================
从这里学到的linux的命令
查看进程所占的文件描述符  lsof -p 390 | wc -l
查看系统的各种资源限制或者更改这个限制    ulimit -a

分享到:
评论

相关推荐

    修改linux进程可打开的文件数的限制open files

    修改linux进程可打开的文件数的限制open files linux中一切都是文件 默认linux一个进程可打开1024个文件 大并发需要达到5万个文件描述符FD,你必须修改该参数值才行

    Linux下应用程序大打开文件数的理解和修改

    运行在Linux系统上的Java程序运行了一段时间后出现Too many open files的异常情况。  这种情况常见于高并发访问文件系统,多线程网络连接等场景。程序经常访问的文件、socket在Linux中都是文件file,系统需要记录...

    Linux下ftp命令详解

    Linux下ftp命令详解 FTP&gt; ! 从 ftp 子系统退出到外壳。 FTP&gt; ? 显示 ftp 命令说明。? 与 help 相同。 格式:? [command] 说明:[command]指定需要帮助的命令名称。如果没有指定 command,ftp 将显示全部命令的列表...

    Linux下查看进程打开的文件句柄数和如何修改方法

    修改文件句柄数在Linux下,我们使用ulimit -n 命令可以看到单个进程能够打开的最大文件句柄数量(socket连接也算在里面)。系统默认值1024。 对于一般的应用来说(象Apache、系统进程)1024完全足够使用。但是如何象...

    Hadoop集群(第12期副刊)_Hbase性能优化

    Linux系统最大可打开文件数一般默认的参数值是1024,如果你不进行修改并发量上来的时候会出现“Too Many Open Files”的错误,导致整个HBase不可运行,你可以用ulimit -n 命令进行修改,或者修改/etc/security/...

    Linux FTP服务配置

    vsftp的含义就是Very Security Ftp,下面就简要的说一下它的配置和使用方法,通过本文的介绍也希望您能了解在Linux下配置一个网络服务的基本过程  1.相关配置文件  /etc/vsftpd.conf,vsftpd.ftpuser,vsftpd.user_...

    [Fedora.Linux.宝典.2010版.PDF].Fedora.Bible.2010.Edition-Featuring.Fedora.Linux.12.pdf

    As a free, open source Linux operating system sponsored by Red Hat, Fedora can either be a stepping stone to Enterprise or used as a viable operating system for those looking for frequent updates....

    lichee_20170502_1607_全志R16的linux系统编译需要改动的文件_使用parrotv1.1的内核_没有外层目录.7z

    rootroot@cm-System-Product-Name:/home/wwt/linux_r16$ tar zxvf lichee_parrotv1.1_20161202.tar.gz rootroot@cm-System-Product-Name:/home/wwt/linux_r16$ rootroot@cm-System-Product-Name:/home/wwt/linux_...

    Tengine(Nginx)配置参考

    #更改worker进程的最大打开文件数限制。如果没设置的话,这个值为操作系统的限制。设置后你的操作系统和Nginx可以处理比“ulimit -a”更多的文件,所以把这个值设高,这样nginx就不会有“too many open files”问题...

    cmd操作命令和linux命令大全收集

    dir 查看文件,参数:/Q显示文件及目录属系统哪个用户,/T:C显示文件创建时间,/T:A显示文件上次被访问时间,/T:W上次被修改时间 date /t 、 time /t 使用此参数即“DATE/T”、“TIME/T”将只显示当前日期和时间,...

    linux全志R16的linux系统编译的资料_20170502_1655.7z

    全志R16平台编译linux系统V1.0.txt 2017/4/11 13:36 (编译请使用编译android的lichee的选项编译生成的.config文件,不然直接编译会报错!!!!) rootroot@cm-System-Product-Name:/home/wwt/linux_r16$ tar...

    mmf4j:MemoryMappedFiles4Java

    MemoryMappedFiles4Java 描述 该库旨在将内存映射文件引入Java。 与已经存在的MappedByteBuffer相比,目标是更好地控制创建,修改和销毁。 它试图统一在不同操作系统上使用此类映射的接口,这意味着许多细节无法实现...

    Loadrunner报错日志

    需要监控weblogic的连接等待情况,此时需要增加acceptBacklog,每次增加25%来提高看是否解决,同时还需要增加连接池和调整执行线程数,(连接池数*Statement Cache Size)的值应该小于等于oracle数据库连接数最大值...

    ap6212a0_a33_sc3817r_神舟验证版本_借用nvram_ap6210这个配置文件_20170626_1834没有外层目录.7z

    调通sina33下的AP6212A0(WIFI+BT) 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 wb4916 AT qq.com 完成时间:2017/6/26 11:01 版本:V1.1 本文参照: 《A33 wifi移植说明书.pdf》 还有就是全志R16的parrotv1.1的...

    softap_ap6212a0_tinav2.1_验证通过_旧版本的系统_20170915_1223没有外层目录.7z

    HOST_OS_EXTRA=Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14.04-trusty HOST_BUILD_TYPE=release BUILD_ID=57513AA3 OUT_DIR= ============================================ rootroot@cm-System-Product...

    在PDF查看器「Open in PDF Viewer」-crx插件

    在Windows 10中,Adobe Acrobat的默认位置为“ C:\ Program Files(x86)\ Adob​​e \ Acrobat Reader DC \ Reader \ AcroRd32.exe”。如果您使用其他操作系统,或者在其他文件夹中安装了Adobe Acrobat,请相应地...

    rtl8188eu_r16m_20161208_服务器再次验证最终完成版本_20170531_1559没有外层目录.7z

    全志R16平台的android6.0.1系统下的RTL8188EU的配置V1.0 2017/5/31 10:30 1、R:\wyb\rtl8188eu_r16m_20161208\android\device\softwinner\astar-evb30\overlay\frameworks\base\core\res\res\values\config.xml ...

    gc2145_tinav2.1验证完成20170523_1648.7z

    UNICODE 全志R16平台TINAV2.1下的CSI接口摄像头ov5640的配置v1.2.txt R16_Camera模块开发说明文档_V1.8.pdf 所有步骤请按照这个说明书执行 1、驱动的编译配置: R:\wyb\gc2145_tinav2.1\lichee\linux-3.4\...

    atom-todo-show:显示项目中待办事项列表的Atom包

    使用命令调色板打开待办事项列表Todo Show: Find In Workspace Todo Show: Find In Project或Todo Show: Find In Open Files 。 键盘快捷键在Mac OSX中为CTRL + SHIFT + T ,在Windows和Linux中为ALT + SHIFT + T ...

    糖果的软件

    重新启动系统后,在命令提示符下执行不带参数的“Openfiles”,即可 看到各个进程打开文件的清单。 原因二:文件系统损坏 磁盘上的坏区、 其他硬件故障或者软件错误都可能会损坏文件系统, 使文 件出现问题...

Global site tag (gtag.js) - Google Analytics