Linux Open files 1024 limitations of the principles and solutions

Source: Internet
Author: User

/proc/sys/fs/file-max

This file specifies the maximum number of file handles that can be allocated.

To view the maximum value:

[Email protected] home]# Cat/proc/sys/fs/file-max 100977[[email protected] home]#

This indicates that the Linux system is allowed to open at most (that is, the total number of open files for all users) 100,977 files, is the Linux system-level hard limit, all user-level open files limit should not exceed this number. Typically, this system-level hard limit is the best maximum number of simultaneous open file limits that Linux systems will calculate at startup, based on the state of the system's hardware resources, and should not be modified unless you want to set a value that exceeds this limit for the user-level open files limit. the default value of this parameter is related to the size of the memory, which increases when physical memory is added to restart the machine. A linear relationship of approximately 1G memory 100,000 handles.

To modify a value:

If the user gets the error message declared, similar to "Too many open files", this is because the maximum number of open files has been reached so that they cannot open more files, you may need to increase this value.

[[email protected] home]# vim /etc/rc.local #!/ bin/sh## this script will be executed *after* all the other  init scripts.# you can put your own initialization stuff in  Here if you don ' T# want to do the full sys v style  init stuff.echo 222158 > /proc/sys/fs/file-max    ; Add this item, Modify the File-max value touch /var/lock/subsys/local[[email protected] home]# reboot[[email  protected] ~]# cat /proc/sys/fs/file-max 222158[[email protected] ~]# 

The way to modify this hard limit is to modify the/etc/rc.local script to add the following line to the script:
echo 22158 >/proc/sys/fs/file-max
This is the hard limit for Linux to force the number of system-level open files to 22158 after boot is complete. Save this file when you are finished modifying it.

/proc/sys/fs/file-nr

This file is related to File-max and it has three values:
Number of allocated file handles the maximum number of file handles that have been used with a file handle
The file is read-only and is used only to display information.

[Email protected] ~]# cat/proc/sys/fs/file-nr 21120222158[[email protected] ~]#

/etc/security/limits.conf

The limits.conf format is as follows:

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

<domain>: You can specify a single user name, @ Group name, all users (*)

type: Soft (refers to the current system The setting value that is in effect), hard (indicates the maximum value that can be set in the system) and-(indicates that both soft and hard values are set)

[[email protected] ~]# vim/etc/security/limits.conf; Add the following two items at the end of the article * hard nofile 4096 * Soft Nofile 4096:WQ

My is RedHat5.4 changes need to re-login, some system may need to restart the effective,

To make the limits.conf file configuration effective, you must make sure that the pam_limits.so file is added to the startup file. See if the following options are available in the/etc/pam.d/login file:

[Email protected] ~]# cat/etc/pam.d/login |grep "pam_limits.so" Session Required/lib/security/pam_limits.so[[email Protected] ~]#

This is to tell Linux that after the user completes the system login, the Pam_limits.so module should be called to set the system's maximum limit on the number of resources that the user can use, including the maximum number of files a user can open, and the pam_limits.so module from/etc/ The security/limits.conf file reads the configuration to set these throttling values.

when deploying applications under Linux, sometimes you encounter problems with Socket/file:can ' t open so many files, in fact Linux is there a file handle limit (like WinXP?). ), and the default is not very high, is generally 1024, as a production server, in fact, it is easy to reach this amount, so we need to modify the above file to change this value a bit larger.

[[email protected] ~]# cat /proc/sys/fs/file-max 100977[[email protected] ~ ]# cat /proc/sys/fs/file-nr 21120100977[[email protected] ~]# ulimit -a     ; display the current resource limit settings core file size            (blocks, -c)  0   data seg size             (kbytes, -d)  unlimited  scheduling priority               (-E)  0file size                 (blocks, -f)  unlimited   pending signals                   (-i)  7922max locked memory        ( KBYTES,&NBSP;-L)  64max memory size          (kbytes, -m)   unlimitedopen files                        (-N)  1024pipe size              (512 bytes, -p)  8POSIX message queues       (BYTES,&NBSP;-Q)  819200real-time priority                (-R)  0stack size                (kbytes, -s)  10240cpu time                 (SECONDS,&NBSP;-T)   unlimitedmax user processes                (-u)  7922virtual memory           (KBYTES,&NBSP;-V)  unlimitedfile  locks                        (-X)  unlimited[[email protected] ~]# ulimit -n1024[[ email protected] ~]#

If you need to temporarily modify the number of file handles, you can use the following actions:

[[email protected] ~]# ULIMIT-HSN 4096[[email protected] ~]# Ulimit-n4096[[email protected] ~]#

h Specifies a hard size, s specifies a soft size, n indicates the maximum number of open file handles for a single process set

How to view the program with the highest number of open files currently in the system:

lsof (list open files) is a tool that lists open files for the current system. Enter lsof at the terminal to display the file opened by the system, because lsof needs to access core memory and various files, so it must be run as root to fully perform its functions. Each row displays an open file, and all files opened by all processes are displayed by default if no criteria are specified

Lsof-n does not convert IP to hostname, the default is not to add the-n parameter eg:# lsof/gtes11/

Lsof-i to show the condition of the process eg:# Lsof-i: 22

[[email protected] ~]# Lsof-n|awk ' {print $} ' |sort-nr|uniq-c|sort-nr|head-5 162 1812 149 1827 126 1591 1 1823 1826[[email protected] ~]#

How to view the number of open files for a program: Lsof-p PID

[Email protected] ~]# lsof-p 1812|wc-l163[[email protected] ~]# lsof-p 1827|wc-l150[[email protected] ~]#


This article is from "I am not a rookie" blog, please be sure to keep this source http://pvbutler.blog.51cto.com/7662323/1558092

Linux Open files 1024 limitations of the principles and solutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.