limits.conf文件_Limits.conf文件限制用户,在Linux中通过示例进行处理

limits.conf文件

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 .

限制时有两种限制实现方式。 这些被称为hardsoft

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 size

    fsize指定最大文件大小

  • nofile specifies maximum number of file size

    nofile指定最大文件大小

  • cpu specifies maximum CPU time

    cpu指定最大CPU时间

  • nproc specifies maximum number of process

    nproc指定最大进程数

  • maxlogins specifies maximum number of logins

    maxlogins指定最大登录数

  • maxsyslogins specifies maximum number of logins for all users

    maxsyslogins指定所有用户的最大登录数

LEARN MORE  Linux hosts.allow and hosts.deny To Control Network Access
了解更多Linux hosts.allow和hosts.deny来控制网络访问

指定用户限制(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

在此示例中,我们为用户名ismail1000000设置了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在10001010之间的用户。 :运算符用于指定范围。

LEARN MORE  Linux Bash Environment Variables
了解更多Linux Bash环境变量

指定限制的组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.

在此示例中,规则将应用于500510之间的组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

LEARN MORE  Best Tools To Monitor Linux
了解更多监视Linux的最佳工具

限制系统登录数(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文件

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Node-limits 是一个简单的连接间件,能够简单限制上传大小,设置请求超时等功能。完全禁止上传,配置时使用: { file_uploads: false }限制上传大小,配置时使用: { post_max_size: [bytes] }, if 0, this functionality is disabled限制 uri 长度大小,配置时使用: { uri_max_length: [number] }, if 0 this functionality is disabled在配置设置全局超时,使用: { global_timeout: [millis] }, if 0  - no timeout is set在配置只设置传入连接的全局超时,使用: { inc_req_timeout: [millis] }, if 0  - no timeout is set在配置只设置传出连接的全局超时,使用: { out_req_timeout: [millis] }, if 0  - no timeout is set在配置传入连接设置空闲时间超时,使用: { idle_timeout: [millis] }, if 0  - no timeout is set为整个应用程序配置 http.Agent.defaultMaxSockets,使用: { max_sockets: [number] }, if 0  - nothing will be set.在 noDelay 套接字使用: { socket_no_delay: [boolean] }, if false  - nothing will be set.代码示例:var express = require('express'),     limits = require('limits'); var app = express(); var limits_config = {     enable: true,     file_uploads: true,     post_max_size: 2000000 } app.use(limits(limits_config)); app.listen(8000); 标签:Nodelimits 分享 window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "2", "bdMiniList": [], "bdPic": "", "bdStyle": "1", "bdSize": "24" }, "share": {} }; with (document)0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' ~(-new Date() / 36e5)];\r\n \r\n \r\n \r\n \r\n \u8f6f\u4ef6\u9996\u9875\r\n \u8f6f\u4ef6\u4e0b\u8f7d\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\nwindow.changyan.api.config({\r\nappid: 'cysXjLKDf', conf: 'prod_33c27aefa42004c9b2c12a759c851039' });

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值