Linux ETC

ulimit 설정 관련

2015.07.29 20:56

호스트웨이 조회 수:77646

Ulimit 이란?

ulimit 프로세스의 자원 한도를 설정하는 명령으로, soft한도와 hard한도 두가지가 있습니다.

 

sof t : 새로운 프로그램을 생성하면 기본으로 적용되는 한도

hard : 소프트한도에서 최대로 늘릴 있는 한도

 

 

apache 같이 서비스를 운영 동접자가 많은 경우 구동되는apache 프로세스 수와 해당  프로세스가 처리하게되는 파일 또한 증가 하게 됩니다.

 

이에 따라 시스템 적으로도 해당 요청에 대응 있도록 상향 설정이 필요로 하며, 해당

설정을 조정 하는 방법에 대해서 다루도록 하겠습니다.

 

 

 

 

ulimit [옵션]

 

-a : 모든 제한 사항을 보여줌.

 

-c : 최대 코어 파일 사이즈

 

-d : 프로세스 데이터 세그먼트의 최대 크기

 

-f : shell 의해 만들어질 있는 파일의 최대 크기

 

-s : 최대 스택 크기

 

-p : 파이프 크기

 

-n : 오픈 파일의 최대수

 

-u : 오픈파일의 최대수

 

-v : 최대 가상메모리의

 

 -S : soft 한도

 

-H : hard 한도

 


 

현재 ulimit 설정 상태를 보는 명령어

 

 

Soft 설정 보기

 

[boriwater] /root > # ulimit -a

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 14943

max locked memory       (kbytes, -l) 64

max memory size         (kbytes, -m) unlimited

open files                      (-n) 1024

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 10240

cpu time               (seconds, -t) unlimited

max user processes              (-u) 1024

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

 

 

Hard 설정 보기

 

[boriwater] /root > # ulimit -Ha

core file size          (blocks, -c) unlimited

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 14943

max locked memory       (kbytes, -l) 64

max memory size         (kbytes, -m) unlimited

open files                      (-n) 4096

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) unlimited

cpu time               (seconds, -t) unlimited

max user processes              (-u) 14943

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

 

 

 


 

항목의 설명

core file size          (blocks, -c) 0                        : 코어파일의 최대크기

data seg size           (kbytes, -d) unlimited          : 프로세스의 데이터 세그먼트 최대크기

scheduling priority             (-e) 0                        : 쉘에서 생성되는 파일의 최대 크기

file size               (blocks, -f) unlimited                         

pending signals                 (-i) 14943

max locked memory       (kbytes, -l) 64

max memory size         (kbytes, -m) unlimited    : resident set size 최대 크기(메모리 최대크기)

open files                      (-n) 1024                         : 프로세스에서 있는 open file descriptor 최대 숫자(열수 있는 최대 파일 )

pipe size            (512 bytes, -p) 8                          : 512-바이트 블럭의 파이프 크기

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 10240

cpu time               (seconds, -t) unlimited             : 누적된 CPU 시간()

max user processes              (-u) 1024                  : 단일 유저가 사용가능한 프로세스의 최대 갯수

virtual memory          (kbytes, -v) unlimited         : 쉘에서 사용가능 가상 메모리의 최대 용량

file locks                      (-x) unlimited

 

max user process 또는  opens files 수가 해당 설정 값을 초과하여 동작할 예를 들어 동접자의 증가로 apache 자식 프로세스가 증가하여 1024 초과할 경우 이로 인해 apache hang 현상 등이 발생 있습니다.

 

아래와 같이 변경 하는 방법이 있으나 이는 실제 적용이 되진 않습니다.


[boriwater] /root > # ulimit -u 2048

[boriwater] /root > # ulimit -a

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 14943

max locked memory       (kbytes, -l) 64

max memory size         (kbytes, -m) unlimited

open files                      (-n) 1024

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 10240

cpu time               (seconds, -t) unlimited

max user processes              (-u) 2048

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

 

위와 같이 보여지더라도 재 로그인 또는 리부팅 시 기본 설정으로 적용 됩니다.


따라서 아래와 같은 방법을 통해 수정 가능합니다.

  

1. ulimit 명령을 통한 변경

-n –u 사용하여 max user process open files 개수를 수정 합니다.

 

boriwater] /root > # ulimit -n 2048

[boriwater] /root > # ulimit -u 4096

[boriwater] /root > # ulimit -a

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 14943

max locked memory       (kbytes, -l) 64

max memory size         (kbytes, -m) unlimited

open files                      (-n) 2048

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 10240

cpu time               (seconds, -t) unlimited

max user processes              (-u) 4096

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

 

2. /etc/security/limits.conf 설정 파일 수정

 

프로세스 user 별로 설정을 지정할 있으며, 이와 같이 적용 특정 user 해당 설정이 적용 되기에 무분별하게 자원을 많이 쓰게 되는 부분에 대해 보안이 가능합니다.

 

해당 문서 파일에 아래와 같이 기입

 

daemon           soft    nproc          4096

daemon           hard    nproc          4096

 

#user                #soft, hard 지정 # nproc - max number of processes  # 한도 숫자 지정

# End of file

 

설정 파일 내에 작성 방법 지시어에 대한 설명도 간략히 나와 있으므로 참조하시기 바랍니다.

 

3. /etc/profile 수정

 

#ulimit setting

ulimit -u 8192   # max number of process 수정

ulimit -n 2048  # open files 수정

 

적용

[boriwater] /root > # source /etc/profile

 

 

확인

 

[boriwater] /root > # ulimit -a

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 14943

max locked memory       (kbytes, -l) 64

max memory size         (kbytes, -m) unlimited

open files                      (-n) 2048

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 10240

cpu time               (seconds, -t) unlimited

max user processes              (-u) 4096

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

 

 

[boriwater] /root > # ulimit -aH

core file size          (blocks, -c) unlimited

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 14943

max locked memory       (kbytes, -l) 64

max memory size         (kbytes, -m) unlimited

open files                      (-n) 2048

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) unlimited

cpu time               (seconds, -t) unlimited

max user processes              (-u) 4096

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

번호 제목 글쓴이 날짜 조회 수
226 XFS파일 장점및 단점 호스트웨이 2012.07.06 25484
225 IBM Integrated Management Module 로그인 정보 호스트웨이 2012.07.06 16182
224 ALERT! /dev/disk/xxxx Does not exist. Dropping to a shell 문제 해결 호스트웨이 2012.07.06 17320
223 데비안에서 CPU 온도 확인 해보기-lm_sensors 호스트웨이 2012.07.13 20447
222 리눅스에서 서버 호스트네임 관리 호스트웨이 2012.07.13 21205
221 리눅스에서 Which 명령어로 명령어 경로 확인 호스트웨이 2012.07.13 14959
220 리눅스 runlevel이란? 호스트웨이 2012.07.13 15452
219 리눅스 more 명령어 file 호스트웨이 2012.07.13 16104
218 Rsync를 이용한 데이터 Sync, 백업하기 – 2탄 호스트웨이 2012.07.13 23902
217 가장 안정적인 NTP 서버 주소 호스트웨이 2012.07.20 32124
216 SED 명령어 사용법 호스트웨이 2012.07.20 16956
215 리눅스 ss 명령어 호스트웨이 2012.07.20 23519
214 Vsftpd 파일명 혹은 확장자에 따른 업로드 제한하기 호스트웨이 2012.07.20 18597
213 리눅스 퍼미션(Permission)이란? file 호스트웨이 2012.07.20 15923
212 Linux 미사용 Demon이 실행되지 않게 설정하기 file 호스트웨이 2012.07.20 15565
211 Proftpd – ‘unable to determine IP address’ 에러 발생시 호스트웨이 2012.07.20 16193
210 Yum - Dag Repository 추가 호스트웨이 2012.07.27 19548
209 "The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA" 에러 메시지 발생 시 호스트웨이 2012.07.27 15400
208 Putty 접속 시 창 분할하는 방법(screen 이용) file 호스트웨이 2012.07.27 28520
207 리눅스 부트로더란? 호스트웨이 2012.07.27 17668