ulimit修改文件打开数
Linux kernel provides some configuration about system related limits and maximums. These are like maximum file handler count, maximum file locks, maximum process count etc. These limits are used to stay in safe area and do not bottleneck system performance. But sometimes these limits should be decreased or increased. ulimit
is used to change these limits and maximums.
Linux内核提供了一些与系统相关的限制和最大值的配置。 这些就像最大文件处理程序数,最大文件锁,最大进程数等。这些限制用于保持安全区域,并且不影响系统性能。 但是有时这些限制应降低或增加。 ulimit
用于更改这些限制和最大值。
列出所有限制 (List All Limits)
There are different types of limits and maximum values used in Linux configuration. We can list all existing limits with -a
option like below.
Linux配置中使用了不同类型的限制和最大值。 我们可以使用-a
选项列出所有现有的限制,如下所示。
$ ulimit -a
We can see that some information about limits are provided.
我们可以看到提供了一些有关限制的信息。
- Limit name provided which is useful the limit topic 提供的限制名称对限制主题很有用
- Limit metrics are provided what kind of metrics used限制指标提供了什么样的指标
- Limit option provided to set or list limit value提供限制选项以设置或列出限制值
- Current limit values are provided提供电流极限值
列表特定限制(List Specific Limit)
We have seen in previous example that we can access specific limit configuration with its option. This will only list given limit. In this example we will list file locks with -x
.
我们在前面的示例中看到,我们可以使用其选项访问特定的限制配置。 这只会列出给定的限制。 在此示例中,我们将使用-x
列出文件锁。
$ ulimit -x
Limits.conf(Limits.conf)
limits.conf
file is used store limit related configuration. It can be accessed from /etc/security/limits.conf
. There s also /etc/security/limits.d
directory which can hold multiple configurations files. For more detailed information about limits.conf
read following tutorial.
limits.conf
文件用于存储限制相关的配置。 可以从/etc/security/limits.conf
访问它。 还有/etc/security/limits.d
目录,该目录可以包含多个配置文件。 有关limits.conf
更多详细信息,请阅读以下教程。
limits.conf File To Limit Users, Process In Linux With Examples
Limits.conf文件限制用户,在Linux中通过示例进行处理
设定极限(Set Limit)
We can set limits to the given metric by providing the limit value after the limit option. In this example we will set core file size unlimited
with the following command.
我们可以通过在limit选项之后提供限制值来为给定指标设置限制。 在此示例中,我们将使用以下命令设置核心文件大小unlimited
。
$ ulimit -c unlimited
We can check new value by listing the limit which is explained previous steps.
我们可以通过列出限制来检查新值,该限制已在前面的步骤中进行了说明。
打开文件描述符的最大数量 (Maximum Number Of Open Files Descriptors)
Maximum number of open files descriptors are used to limit concurrent open file count. A lot of files open concurrently will hurt disk and system performance. But in some systems like SIEM higher values may be more suitable.In this example we set maximum number of open files descriptors to 10000
. Changing these ulimit values will require root privileges
打开文件描述符的最大数量用于限制并发打开文件数。 同时打开许多文件会损害磁盘和系统性能。 但是在像SIEM这样的系统中,更高的值可能更合适。在此示例中,我们将打开文件描述符的最大数量设置为10000
。 更改这些ulimit值将需要root特权
$ sudo ulimit -n 10000
用户的最大处理数量 (Maximum Number Of Process For User)
Maximum number of process for user will limit process count owner by a single user. Default value is 7900 . In this example we will decrease this value to the 500.
用户的最大进程数将限制单个用户的进程数所有者。 默认值为7900。 在此示例中,我们将该值减小为500。
$ sudo ulimit -n 500
翻译自: https://www.poftut.com/linux-ulimit-command-tutorial-examples-increase-open-file-limit/
ulimit修改文件打开数