
limits.conf文件
limits.conf
configuration file is used to limit user, domain, process related metrics. Limits.conf is related with pam_limits
module.
limits.conf
配置文件用于限制用户,域,进程相关指标。 Limits.conf与pam_limits
模块相关。
配置文件 (Configuration File)
There is configuration file named limits.conf
and located at /etc/security/
. The default content of this file is like below.
在/etc/security/
有一个名为limits.conf
配置文件。 该文件的默认内容如下。
#<domain> <type> <item> <value>
#
#* soft core 0
#root hard core 100000
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#ftp - chroot /ftp
#@student - maxlogins 4
As we can see all configurations are commented so they are not effective. There is also a directory which is use to store configuration files in a separate files to maintain easily. This location is /etc/security/limits.d/
. It is by default empty but we can create rules in this directory easily.
如我们所见,所有配置均已注释,因此它们无效。 还有一个目录,用于将配置文件存储在单独的文件中,以便于维护。 该位置是/etc/security/limits.d/
。 默认情况下为空,但是我们可以在此目录中轻松创建规则。
句法 (Syntax)
Limits.conf file have a simple and reliable syntax. This syntax is defined to easily set context, type, limits and related values. We will look all of this terms below.
Limits.conf文件具有简单可靠的语法。 定义此语法可轻松设置上下文,类型,限制和相关值。 我们将在下面查找所有这些术语。
<domain> <type> <item> <value>
域 (Domain)
While limits configuration we need to specify context. This content can be defined in various ways and various parameters. The first column of the rule is the domain. Domain can be following
在限制配置的同时,我们需要指定上下文。 可以以各种方式和各种参数定义此内容。 规则的第一列是域。 域可以是
- username用户名
- groupname组的名字
*
specifies all*
指定全部- userid用户身份
- groupid组号
类型(Type)
While limiting there is two type of limit implementation. These are called hard
and soft
.
限制时有两种限制实现方式。 这些被称为hard
和soft
。
Hard limits are set by root and enforced by kernel
硬限制由root设置并由内核执行
Soft limits have some range overload.
软限制具有一定范围的过载。
项目 (Item)
Items are the core of limits. Items are used to specify the item the limit will be applied. For example if we want to limit the maximum process number we will use nproc
numbers. Here are some of the items those can be used to for limit operation
项目是限制的核心。 项目用于指定将应用限制的项目。 例如,如果我们想限制最大进程数,我们将使用nproc
数。 以下是一些可用于极限操作的项目
fsize
specifies maximum file sizefsize
指定最大文件大小nofile
specifies maximum number of file sizenofile
指定最大文件大小cpu
specifies maximum CPU timecpu
指定最大CPU时间nproc
specifies maximum number of processnproc
指定最大进程数maxlogins
specifies maximum number of loginsmaxlogins
指定最大登录数maxsyslogins
specifies maximum number of logins for all usersmaxsyslogins
指定所有用户的最大登录数
指定用户限制(Specify User For Limit)
Now we can start examples. As we stated we can limit relevant items according to user name. In the following rule we will specify a limit for username ismail
where we specify the user name in the first column.
现在我们可以开始例子。 如前所述,我们可以根据用户名限制相关项目。 在以下规则中,我们将为用户名ismail
指定一个限制,我们在第一列中指定用户名。
ismail hard core 100000
In this example we set core
or CPU limit for value 1000000
for username ismail
as hard
在此示例中,我们为用户名ismail
值1000000
设置了core
或CPU限制为hard
指定限制组 (Specify Group For Limit)
In this example we can specify limit for a user group name. This type of limitation can be useful if we want to restrict some user group names.
在此示例中,我们可以为用户组名称指定限制。 如果我们要限制某些用户组名称,则这种类型的限制会很有用。
@apache hard nproc 20
In this example we specify apache
group name to limit process
number as maximum 20
在此示例中,我们指定apache
组名称以将process
号限制为最大20
使用通配符限制 (Use Wildcard For Limit)
While specifying the domain or the users and groups we may need to set limit for all users and groups in a system. Here we will use *
or wildcard for this.
在指定域或用户和组时,我们可能需要为系统中的所有用户和组设置限制。 在这里,我们将使用*
或通配符。
* hard rss 10000
In this example we set rss
limit for all users and groups in this systems.
在此示例中,我们为该系统中的所有用户和组设置了rss
限制。
指定限制的用户ID范围 (Specify User ID Range For Limit)
We want to specify limit some users. But they are not in a user group and we do not want or can create group for these groups. Specifying limits one by one is a problem. We can specify multiple users like below. But the restriction is that we will specify range
我们要指定限制一些用户。 但是它们不在用户组中,我们不希望或不能为这些组创建组。 一个一个地指定限制是一个问题。 我们可以指定多个用户,如下所示。 但限制是我们将指定范围
1000:1010 hard rss 10000
The rule above will be applied to the users those User ID’s are between 1000
and 1010
. The :
operator used to specify range.
上面的规则将应用于用户ID在1000
到1010
之间的用户。 :
运算符用于指定范围。
指定限制的组ID范围(Specify Group ID Range For Limit)
The similar definition like previous user range is group range. We will specify group ID range like below.
类似于先前的用户范围的定义是组范围。 我们将如下指定组ID范围。
@500:510 hard rss 10000
In this example the rules will be applied for the group ID’s between 500
and 510
. We use @
operator to specify ID’s as group and :
for range.
在此示例中,规则将应用于500
到510
之间的组ID。 我们使用@
运算符将ID指定为组,将:
指定范围。
限制工序数 (Limit Number of Process)
Now we will start to look different item types to use. There are more items than described here but these are most popular ones. First example is limiting number of processes for a user.
现在,我们将开始寻找要使用的不同项目类型。 有比这里描述更多的项目,但这些是最受欢迎的项目。 第一个示例是限制用户的进程数。
ismail hard nproc 20
In the example we limit process number with nproc
item. The user the rule will apply is ismail
and the maximum number of process for this user can own is 20
在示例中,我们将进程号限制为nproc
项目。 规则将应用的用户是ismail
,该用户可以拥有的最大进程数为20
限制CPU时间 (Limit CPU Time)
Another useful item to limit is CPU time. We can set limits about the CPU time .
要限制的另一个有用项是CPU时间。 我们可以设置有关CPU时间的限制。
ismail soft cpu 10000
In this example we applied maximum 10000
cycles for user ismail
by using cpu
item.
在此示例中,我们使用cpu
项目为用户ismail
应用了最多10000
个周期。
限制打开文件数 (Limit Number Of Open File)
We can limit the numbers of file a user can open in time. This can be useful to prevent disk bottlenecks if the system have a lot of users those access files.
我们可以限制用户可以及时打开的文件数。 如果系统有许多访问文件的用户,这对于防止磁盘瓶颈很有用。
ismail hard nofile 512
In this example we specify that the user ismail
can only open 512
files or file descriptors with nofile
item.
在此示例中,我们指定用户ismail
只能打开512
文件或带有nofile
项的文件描述符。
限制登录数量 (Limit Number Of Logins)
By default a user can have infinite numbers of connections, sessions or logins in a system. This may create some security or performance problems for the systems. We can set some limits about this.
默认情况下,用户在系统中可以具有无限数量的连接,会话或登录名。 这可能会给系统带来一些安全性或性能问题。 我们可以对此设置一些限制。
@student - maxlogins 4
In this examples we limit student
groups users login count. We use maxlogins
for each users in student group. The maximum number of login can not be more than 4
.
在此示例中,我们限制student
团体用户的登录次数。 我们为学生组中的每个用户使用maxlogins
。 登录的最大数量不能超过4
。
限制系统登录数(Limit Number Of System Logins)
In previous example we have restricted maximum logins as user base. we can also specify total number of logins in system wide. This restriction will be effective in general manner.
在前面的示例中,我们限制了最大登录名作为用户群。 我们还可以指定系统范围内的登录总数。 该限制将以一般方式生效。
* - maxsyslogins 40
In this example we restrict for all users and groups but actually this is not a user or group based restriction. We set this rule system wide and use maxsyslogin
item as 40
在此示例中,我们限制所有用户和组,但实际上这不是基于用户或组的限制。 我们在整个系统范围内设置此规则,并将maxsyslogin
项设置为40
限制最大文件大小 (Limit Maximum File Size)
We may want to restrict file size. This restriction can be useful in temp or similar usage type files.
我们可能要限制文件大小。 此限制在临时文件或类似用法类型文件中很有用。
@student - fsize 4000000
In this example we limit the students single file size as 4000000
. This is presentation of KB
or kilobyte. So the example means 4 GB
. We use fsize
as item type.
在此示例中,我们将学生的单个文件大小限制为4000000
。 这是KB
或千字节的表示。 因此该示例意味着4 GB
。 我们使用fsize
作为项目类型。
翻译自: https://www.poftut.com/limits-conf-file-limit-users-process-linux-examples/
limits.conf文件