欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

/etc/security/limits.conf詳解與配置過程

 更新時間:2024年10月08日 14:19:28   作者:自由早晚亂余生  
在Linux系統(tǒng)中,通過/etc/security/limits.conf文件和/etc/security/limits.d/目錄下的配置文件,可以設(shè)置用戶或用戶組的資源限制,配置文件中的soft和hard限制分別代表警告級別和硬性限制,它們需要匹配才能生效

/etc/security/limits.conf 文件實(shí)際是 Linux PAM(插入式認(rèn)證模塊,Pluggable Authentication Modules)中 pam_limits.so 的配置文件,而且只針對于單個會話。

該設(shè)置不會影響系統(tǒng)服務(wù)的資源限制。

還要注意 /etc/security/limits.d/ 的這個目錄.

一、 /etc/security/limits.conf詳解

/etc/security/limits.conf 配置解析

# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
該文件為通過PAM登錄的用戶設(shè)置資源限制。
#It does not affect resource limits of the system services.
#它不影響系統(tǒng)服務(wù)的資源限制。
#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.
請注意/etc/security/limits.d下按照字母順序排列的配置文件會覆蓋 /etc/security/limits.conf中的
domain相同的的配置
#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.
這意味著,例如使用通配符的domain會被子目錄中相同的通配符配置所覆蓋,但是某一用戶的特定配置
只能被字母路中用戶的配置所覆蓋。其實(shí)就是某一用戶A如果在/etc/security/limits.conf有配置,當(dāng)
/etc/security/limits.d子目錄下配置文件也有用戶A的配置時,那么A中某些配置會被覆蓋。最終取的值是 /etc/security/limits.d 下的配置文件的配置。

#
#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    用戶組格式為@GROUP_NAME
# - the wildcard *, for default entry    默認(rèn)配置為*,代表所有用戶
# - 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
有soft,hard和-,soft指的是當(dāng)前系統(tǒng)生效的設(shè)置值,軟限制也可以理解為警告值。
hard表名系統(tǒng)中所能設(shè)定的最大值。soft的限制不能比hard限制高,用-表名同時設(shè)置了soft和hard的值。
#<item> can be one of the following:    <item>可以使以下選項中的一個
# - core - limits the core file size (KB)    限制內(nèi)核文件的大小。
# - data - max data size (KB)    最大數(shù)據(jù)大小
# - fsize - maximum filesize (KB)    最大文件大小
# - memlock - max locked-in-memory address space (KB)    最大鎖定內(nèi)存地址空間
# - nofile - max number of open file descriptors 最大打開的文件數(shù)(以文件描敘符,file descripter計數(shù)) 
# - rss - max resident set size (KB) 最大持久設(shè)置大小
# - stack - max stack size (KB) 最大棧大小
# - cpu - max CPU time (MIN)    最多CPU占用時間,單位為MIN分鐘
# - nproc - max number of processes 進(jìn)程的最大數(shù)目
# - as - address space limit (KB) 地址空間限制 
# - maxlogins - max number of logins for this user    此用戶允許登錄的最大數(shù)目
# - maxsyslogins - max number of logins on the system    系統(tǒng)最大同時在線用戶數(shù)
# - priority - the priority to run user process with    運(yùn)行用戶進(jìn)程的優(yōu)先級
# - locks - max number of file locks the user can hold    用戶可以持有的文件鎖的最大數(shù)量
# - 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] max nice優(yōu)先級允許提升到值
# - rtprio - max realtime pr iority
#
#<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
#@st

/etc/security/limits.d/目錄

/etc/security/limits.d/ 目錄

該目錄下默認(rèn)有 *-nproc.conf 文件,該文件是用于限制用戶的線程限制。我們也可以在該目錄創(chuàng)建配置文件在 /etc/security/limits.d/ 下,以 .conf 結(jié)尾。

centos 7

在CentOS 7版本中為/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 # 所有的用戶默認(rèn)可以打開最大的進(jìn)程數(shù)為 4096
root soft    nproc     unlimited # root 用戶默認(rèn)可以打開最大的進(jìn)程數(shù) 無限制的。
  • CentOS 6

CentOS 6版本中為/etc/security/limits.d/90-nproc.conf

二、 ulimit 如何配置

配置注意事項

注意不能設(shè)置 nofile不能設(shè)置 unlimited,noproc可以.

當(dāng)我們設(shè)置了 nofile不能設(shè)置 unlimited 后,我們進(jìn)行 ssh 登錄,是登錄不了的,并且報錯下面的內(nèi)容。

一般我們需要配置的 /etc/security/limits.d/20-nofile.conf 為。

root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535

/etc/security/limits.d/20-nproc.conf設(shè)置為

*    -     nproc   65535
root soft  nproc  unlimited
root hard  nproc  unlimited

注意覆蓋點(diǎn)的問題

示例一

當(dāng) /etc/security/limits.conf配置了:

root soft nofile 65538
root hard nofile 65538
* soft nofile 65539
* hard nofile 65539

這個root 用戶的 默認(rèn)取值是 65538 ,* 統(tǒng)配符雖然在 root 配置后面,但是 root 的配置只能被 root 進(jìn)行覆蓋。

我們看下這個配置,當(dāng)這樣配置的時候

root soft nofile 65538
root hard nofile 65538
* soft nofile 65539
* hard nofile 65539
root soft nofile 65539

這個的 root 用戶的取值還是 65538,因為雖然 root soft nofile 65539 會覆蓋我們之前的配置,但是這個配置是不生效的。

因為 root soft nofile 65539 配置的值大于root hard nofile 65538 , soft 配置的值不能大于 hard.

示例二

當(dāng)我們在 /etc/security/limits.conf 配置了:

root soft nofile 65538
root hard nofile 65538
* soft nofile 65539
* hard nofile 65539

然后我們在 /etc/security/limits.d/20-nofile.conf配置了:

root soft nofile 65536
root hard nofile 65536
* soft nofile 65540
* hard nofile 65540

最后的取值是會取 /etc/security/limits.d/20-nofile.conf里面的值。

  • 配置,只能被特定覆蓋。
  • /etc/security/limits.d/ 下文件的相同配置可以覆蓋 /etc/security/limits.conf
  • soft和hard需要都進(jìn)行設(shè)置,才能生效。
  • nofile不能設(shè)置 unlimited
  • nofile可以設(shè)置的最大值為 1048576(2**20),設(shè)置的值大于該數(shù),就會進(jìn)行登錄不了。
  • soft 設(shè)置的值 一定要小于或等于 hard 的值。
  • 具體詳細(xì)配置根據(jù)應(yīng)用情況進(jìn)行配置。

三、ulimit 配置后生效

臨時配置

設(shè)置可以打開文件的最大數(shù)為 65536

ulimit  -SHn  65536

重啟后失效。

永久配置

配置到配置文件/etc/security/limits.conf或者 /etc/security/limits.d/ 中。

然后退出當(dāng)前會話,重新登錄。 即可生效,重啟配置也會保留。

配置不生效的問題

四、ulimit 常用命令

      -S	use the `soft` resource limit # 設(shè)置軟限制
      -H	use the `hard` resource limit # 設(shè)置硬限制
      -a	all current limits are reported# 顯示所有的配置。
      -b	the socket buffer size # 設(shè)置socket buffer 的最大值。
      -c	the maximum size of core files created # 設(shè)置core文件的最大值.
      -d	the maximum size of a process's data segment  # 設(shè)置線程數(shù)據(jù)段的最大值
      -e	the maximum scheduling priority (`nice') # 設(shè)置最大調(diào)度優(yōu)先級
      -f	the maximum size of files written by the shell and its children # 創(chuàng)建文件的最大值。
      -i	the maximum number of pending signals # 設(shè)置最大的等待信號
      -l	the maximum size a process may lock into memory #設(shè)置在內(nèi)存中鎖定進(jìn)程的最大值
      -m	the maximum resident set size 
      -n	the maximum number of open file descriptors # 設(shè)置最大可以的打開文件描述符。
      -p	the pipe buffer size
      -q	the maximum number of bytes in POSIX message queues
      -r	the maximum real-time scheduling priority
      -s	the maximum stack size
      -t	the maximum amount of cpu time in seconds
      -u	the maximum number of user processes  # 設(shè)置用戶可以創(chuàng)建的最大進(jìn)程數(shù)。
      -v	the size of virtual memory  # 設(shè)置虛擬內(nèi)存的最大值
      -x	the maximum number of file locks

查看配置

  • 查看所有的配置
ulimit  -a
  • 查看配置的最大打開文件數(shù)
ulimit  -n
  • 更改配置
ulimit  -SHn  65536

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Centos7.2 系統(tǒng)上yum安裝lamp環(huán)境

    Centos7.2 系統(tǒng)上yum安裝lamp環(huán)境

    這篇文章主要介紹了centos7.2 系統(tǒng)上yum安裝lamp環(huán)境的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下
    2016-11-11
  • Linux 常用命令掛載命令詳解

    Linux 常用命令掛載命令詳解

    這篇文章主要介紹了Linux 常用命令掛載命令詳解的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • Apache NameVirtualHost *:80 has no VirtualHosts問題解決辦法

    Apache NameVirtualHost *:80 has no VirtualHosts問題解決辦法

    這篇文章主要介紹了Apache NameVirtualHost *:80 has no VirtualHosts問題解決辦法,一個很簡單的配置性錯誤,需要的朋友可以參考下
    2014-08-08
  • Linux下修改hostname的三種實(shí)現(xiàn)方式

    Linux下修改hostname的三種實(shí)現(xiàn)方式

    這篇文章主要介紹了Linux下修改hostname的三種實(shí)現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-03-03
  • Ubuntu17.04配置更換國內(nèi)源的方法

    Ubuntu17.04配置更換國內(nèi)源的方法

    本篇文章主要介紹了Ubuntu17.04配置國內(nèi)源的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • Centos7的apache網(wǎng)站環(huán)境搭建wordpress

    Centos7的apache網(wǎng)站環(huán)境搭建wordpress

    本篇文章給大家詳細(xì)分析了在Centos7的apache網(wǎng)站環(huán)境搭建wordpress的詳細(xì)操作方法,有興趣的朋友參考下。
    2018-02-02
  • Linux通過設(shè)備號找到設(shè)備的方法

    Linux通過設(shè)備號找到設(shè)備的方法

    所有的Linux設(shè)備文件均位于/dev目錄下,是根(/)文件系統(tǒng)的一個組成部分,因為這些設(shè)備文件在操作系統(tǒng)啟動過程中必須可以使用。接下來通過本文給大家介紹Linux通過設(shè)備號找到設(shè)備的方法,感興趣的朋友一起看看吧
    2018-07-07
  • CentOS 7.6安裝MySQL 5.7 GA版的教程圖解

    CentOS 7.6安裝MySQL 5.7 GA版的教程圖解

    本文通過圖文并茂的形式給大家介紹了CentOS 7.6安裝MySQL 5.7 GA版,需要的朋友可以參考下
    2019-09-09
  • Linux十個新手命令分享

    Linux十個新手命令分享

    這篇文章主要介紹了Linux十個新手命令分享,然后介紹了幾個其他常用命令,具有一定參考價值,需要的朋友可以了解下。
    2017-11-11
  • Linux Centos7系統(tǒng)端口占用問題的解決方法

    Linux Centos7系統(tǒng)端口占用問題的解決方法

    這篇文章主要給大家介紹了關(guān)于Linux Centos7系統(tǒng)端口占用問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01

最新評論