리눅스

/etc/security/limits.conf , /etc/security/limits.d/*

정지홍 2024. 8. 3. 16:37

/etc/security는 리소스를 제안할수있다.

db를 운영하다보면 disk full 혹은 여러 이유로 인한 너무 많은 파일이 오픈되어 cubrid운영이 어려울수있다.

만약 서버의 리소스를 특정 프로그램 or 유저가 많이 점유한다면 서버가 못터티고 다운될수있다

그거를 예방하기 위해 여기에서 이 파일을 수정한다.


[root@localhost security]# cat 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
tomcat           soft    nproc           8192
tomcat           hard    nproc           8192
tomcat           soft    nofile          8192
tomcat           hard    nofile          8192
# End of file

domain : 제한할 대상작성 (*, user명, 그룹명을 줄 수 있다.(그룹에 적용할 경우 @가 붙는다))
type : 강하게 제한할 것인지, 어느정도 여유를 줄 것인지를 결정한다.
soft : soft로 설정한 용량을 넘어가면 경고 메시지를 남김. 
       혹은 새로운 프로그램을 생성하면 기본으로 적용되는 한도
hard : 어떠한 일이 있어도 hard를 넘을 수 없음
item : 제한할 항목으로 core, data seg, file size등 여러가지가 존재
nproc : 최대 프로세스의 갯수(KB)
stack : 최대 스택 사이즈(KB)
nofile : 한번에 열 수 있는 최대 파일 수
core : core파일의 사이즈(KB)
value : 제한 하고자 하는 설정값

96core 512GB nproc: 256*1024, nofile: 2*1024*1024
vendor recommendation value

/etc/security/limits.d/*

/etc/security/limits.d

  • 이 디렉토리는 리눅스에서 사용자와 프로세스에 대한 자원 제한 설정 파일을 저장하는 디렉토리
  • 여기에 존재하는 각 파일은 특정 사용자나 그룹에 대한 자원 제한을 정의할수있음
  • 유저별 혹은 그룹별로 시스템 자원을 효율적 관리 및 보호가 가능
  • 구성은 limits.conf와 비슷하다.
  • <도메인> <유형> <항목> <값>
  •  

[root@localhost limits.d]# cat 20-nproc.conf
# Default limit for number of user's processes to prevent
# 사용자가 생성할 수 있는 프로세스 수에 기본 제한을 설정해요
# accidental fork bombs.
# 포크 bombs를 방지해요.
# See rhbz #432903 for reasoning.

*          soft    nproc     4096
root       soft    nproc     unlimited

  • 위에 첫 줄 * soft nproc 4096
  • *은 시스템의 모든 사용자에게 이 규칙이 적용됨을 의미
  • 유형을 소프트 제한으로 설정
  • 항목은 nproc으로 설정
  • 최대 4096개 프로세스 생성 가능하게 함
  • root soft nproc unlimited
  • root는 루트 사용자에게 적용됨을 의미
  • 유형을 소프트 제한으로 설정
  • 항목은 nproc으로 설정
  • 프로새스 생성 제한 없음을 의미