RHEL7中nproc的取值来源于 20-nproc.conf文件

本文介绍如何在Red Hat Enterprise Linux Server 7.4上为用户设置默认的进程数量限制,防止意外的fork bomb攻击。通过编辑/etc/security/limits.conf及limits.d/20-nproc.conf文件,管理员可以设置软硬限制来控制用户可以创建的最大进程数。
[root@pgserver ~]# su - postgres
Last login: Mon Aug  7 09:44:30 EDT 2017 on pts/0
[postgres@pgserver ~]$ ulimit -u
4096
[postgres@pgserver ~]$ cat /etc/security/limits.
limits.conf  limits.d/    
[postgres@pgserver ~]$ cat /etc/security/limits.conf 
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4

# End of file
[postgres@pgserver ~]$ ulimit -u
4096
[postgres@pgserver ~]$ cat /etc/security/limits.d/20-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     4096
root       soft    nproc     unlimited
[postgres@pgserver ~]$ cd/etc/security/limits.d/
-bash: cd/etc/security/limits.d/: No such file or directory
[postgres@pgserver ~]$ cd/etc/security/limits.d/
-bash: cd/etc/security/limits.d/: No such file or directory
[postgres@pgserver ~]$ cd /etc/security/limits.d/
[postgres@pgserver limits.d]$ ls -lrt
total 4
-rw-r--r--. 1 root root 191 Jul 19  2016 20-nproc.conf
[postgres@pgserver limits.d]$ cat 20-nproc.conf 
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     4096
root       soft    nproc     unlimited
[postgres@pgserver limits.d]$ ll
total 4
-rw-r--r--. 1 root root 191 Jul 19  2016 20-nproc.conf
[postgres@pgserver limits.d]$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.4 (Maipo)
[postgres@pgserver limits.d]$ uname -a
Linux pgserver 3.10.0-693.el7.x86_64 #1 SMP Thu Jul 6 19:56:57 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
[postgres@pgserver limits.d]$ 


参考文章:
How to set or change the default soft or hard limit for the number of user's processes?
https://access.redhat.com/solutions/406663

[root@iZbp1avc1olq9krqsni6tuZ postgres]# sudo yum install -y postgis35_15 Last metadata expiration check: 2:13:26 ago on Mon 23 Jun 2025 11:07:10 AM CST. Error: Problem: cannot install the best candidate for the job - nothing provides geos313 >= 3.13.0 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides gdal310-libs >= 3.10.0 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides proj95 >= 9.5.1 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libjson-c.so.5()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libgeos_c.so.1()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libproj.so.25()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libstdc++.so.6(GLIBCXX_3.4.29)(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libjson-c.so.5(JSONC_0.14)(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides hdf5 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libSFCGAL.so.2()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides xerces-c needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libgeotiff17 needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 - nothing provides libgdal.so.36()(64bit) needed by postgis35_15-3.5.2-1PGDG.rhel9.x86_64 from pgdg15 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
最新发布
06-24
Error: Problem: package ffmpeg-devel-4.2.10-1.el8.x86_64 requires libavdevice.so.58()(64bit), but none of the providers can be installed - package ffmpeg-devel-4.2.10-1.el8.x86_64 requires libavdevice(x86-64) = 4.2.10-1.el8, but none of the providers can be installed - conflicting requests - nothing provides libGL.so.1()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libpulse.so.0()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libpulse.so.0(PULSE_0)(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libjack.so.0()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libcdio_cdda.so.2()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libcdio_paranoia.so.2()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libdrm.so.2()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libSDL2-2.0.so.0()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libxcb.so.1()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libv4l2.so.0()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libxcb-shm.so.0()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libxcb-shape.so.0()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libxcb-xfixes.so.0()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 - nothing provides libopenal.so.1()(64bit) needed by libavdevice-4.2.10-1.el8.x86_64 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
06-11
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值