본문 바로가기
컴퓨터 활용(한글, 오피스 등)/50_2.운영체제_리눅스

리눅스_리소스 제한 설정(limits.conf)의 최대 프로세스 생성 개수(nproc)와 최대 오픈 파일 개수(nofile) 관리

by 3604 2022. 11. 14.
728x90

출처: https://wasking.tistory.com/92

■ 현상
was의 어플리케이션에서 아래와 같은 로그 발생
OutOfMemoryError : unable to create new native thread

■ 원인
/etc/security/limit.conf 에서 nproc의 값(4096)으로 인해 프로세스 생성 제한이 되어버림.
조치 후 was계정에서 생성한 프로세스의 개수(4961)

■ 조치사항
/etc/security/limit.conf 에서 was계정에 대해 아래와 같이 설정

testuser soft nofile 65535
testuser hard nofile 65535
testuser soft nproc 65535
testuser hard nproc 65535

□ ulimit과 /etc/security/limit.conf 에 대한 설명
리눅스는 /etc/security/limit.conf 파일을 통해 서버의 리소스를 관리함

ulimit는 프로세스의 자원 한도를 설정 및 확인하는 명령(limit.conf)에서 읽어온다. soft / hard 두가지 제한으로 나뉨

soft : 새로운 프로그램을 생성하면 기본으로 적용되는 한도
hard : 최대로 늘릴 수 있는 한도

# ulimit -a // Soft 설정 보기
# ulimit -aH // Hard 설정 보기

통상적으로 soft와 hard를 1:1로 맞추어 설정

limit.conf의 내용은 주로 아래와 같이 구성

testuser soft nofile 65535
testuser hard nofile 65535
testuser soft nproc 65535
testuser hard nproc 65535

nproc (number of processes) : 프로세스 최대 개수
nofile (number of open files) : 파일 열기 최대 개수

리눅스에서는 모든 개체를 파일로 보기에 nproc를 높이면 nofile도 같이 높여주는 것이 맞다.

● 계정당 생성한 프로세스 개수
# ps h -Led -o user | sort | uniq -c | sort -n
● 계정의 오픈한 파일 개수
# lsof -u [username] | wc -l
# sysctl -a |grep file-nr

728x90