`
雨过天晴0521
  • 浏览: 155559 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

(转) Linux Increase The Maximum Number Of Open Files

 
阅读更多
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
分享到:
评论

相关推荐

    Taking the Human Out of the Loop- A Review of Bayesian Optimization.pdf

    The construction of such systems involves many distributed design choices. The end products (e.g., recommendation systems, medical analysis tools, real-time game engines, speech recognizers) thus ...

    The Psychology of Money

    Discover the Ideal Investment Strategy ... A step-by-step guide to enhancing management performance to increase returns."- Abbie Smith, PhD, Professor of Accounting.University of Chicago Business School

    pv_boost.rar_High Voltage!_converter_matlab_matlab PV_paper

    This paper proposes that how to increase the efficiency of a solar PV energy system by the advancement in conventional DC to DC Boost converter. This paper also proposes the study of open loop ...

    Prentice.Hall.PTR.Building.Applications.with.the.Linux.Standard.Base.chm

    An initiative of the Free Standards Group, the Linux Standard Base (LSB) is a set of standards designed to increase compatibility among Linux distributions and enable applications to run on any LSB-...

    Self.Service.Linux.Mastering.the.Art.of.Problem.Determination

    &lt;br/&gt;If you use Linux professionally, this book can dramatically increase your efficiency, productivity, and marketability. If you're involved with deploying or managing Linux in the enterprise, ...

    Under the Hood of a Multiphase Synchronous Rectified Boost Converter

    Selecting a number of phases can increase component counts and costs, which begs the question, how many phases are needed? What benefit do a given number of phases for a certain power requirement ...

    2014-博士论文-The Influence of Social Capital

    Recent years have seen an increase in the use of Interest-based social networks such as Pinterest, ChimeIn and Twitter. While classic online social networks like Facebook or LinkedIn offer a social ...

    UE(官方下载)

    Use copied and selected text in macros to dramatically increase the power and flexibility of UltraEdit macros Run a macro or script from the command line We are often asked if it is possible to run an...

    The Internet of Things_Foundation for Smart Cities, eHealth-CRC(2018).pdf

    With the advent of IoT, there has been a humongous increase in the amount of data gen- erated by the devices. However, this gives more power to the systems, as the more these data are analyzed, deeper...

    人口模型的处理,二胎影响

    In response to the current problems of aging in China, unbalanced labor ...has a positive effect on China’s economic development, the alleviation of aging, and the increase in the number of laborers.

    Linear Algebra with Applications 9th ed - Steven J. Leon (Pearson, 2015)

    number of applications, and many revisions in the various sections of the book. I have been fortunate to have had outstanding reviewers and their suggestions have led to many important improvements in...

    Linux Filesystem Hierarchy

    It is meant to be accessible to all members of the Linux community, be distribution independent and is intended discuss the impact of the FSSTND and how it has managed to increase the efficiency of ...

    Advances in Cryptology - CRYPTO 2013

    significantly increase the number of papers in the program from last year’s 48 papers at the price of making the program longer and keeping the paper presentations short 20 minutes per paper ...

    The Implementation of Functional Programming Languages

    full laziness and SK combinators., Finally, the third part describes the G-machine, a sophisticated implementation of graph reduction, which provides a dramatic increase in performance over the ...

    USB短信猫驱动

    ResetPipeRequestRetryCount controls the maximum number of times that FTDIBUS tries to reset a pipe on which an error has occurred. ResetPipeRequestRetryCount defaults to 50. It may be necessary to ...

    建表语句+题目+答案+表.zip

    Q:Find the number of tuples in the customer relation. Q:Find the number of depositors in the bank. Q:Find the number of depositors for each branch. Q:Find all customers who have a loan at the bank but...

    微软内部资料-SQL性能优化2

    Paging is represented by a number of counters including page faults/sec, page input/sec and page output/sec. Page faults/sec include soft and hard page faults where as the page input/output counters ...

    AI画图软件DreamTime版本1.6.4 Windows安装包

    Create the body of your dreams, increase or decrease the size of the body parts or leave everything to random. Don't just stay with static photos, you can also create GIFs, MP4 and WEBM videos! Open ...

    计算机网络第六版答案

    An ISP earns its money by charging each of the the ISPs that connect to the IXP a relatively small fee, which may depend on the amount of traffic sent to or received from the IXP. 15. Google's ...

    Practical LPIC-1 Linux Certification Study Guide(Apress,2016)

    And with the ongoing explosive growth of the cloud computing world – the vast majority of which is being built with Linux – the scope of the opportunities will only increase. Whether or not you end...

Global site tag (gtag.js) - Google Analytics