티스토리 뷰

os/Linux

process max open files with systemd

Jacob_baek 2021. 11. 24. 19:48

/etc/security/limits.conf 내에 nofile 을 변경했음에도 특정 프로세스는 적용이 안된것을 보게되어
이에 대해 확인한 사항을 정리한다.

이슈 확인

아래와 같이 ulimit으로 확인한 max open files 가 65535임에도

[root@localhost ~]# ulimit -n
65535

systemd에 의해 실행되는 process의 limits은 다른 값을 출력하는것을 확인하였다.

[root@localhost ~]# cat /proc/11223/limits  | grep "open file"
Max open files            1024                 4096                 files

분석결과

systemd는 기본적으로 기본값을 따로 가지고 있고 해당 값이 적용되는것으로 보인다.

$ sudo systemctl show -p DefaultLimitNOFILE
DefaultLimitNOFILE=4096

그렇다면 systemd는 별도로 limits를 관리하는걸까?

아래 bugzilla에 나와있듯이 systemd는 global limits를 무시하고 자체적으로 관리하게 된다.

해결방안

하여 다음과 같은 line이 systemd 의 service 파일에 들어가야한다.
다음과 같은 경로에 /etc/systemd/system/xxxxxxx.service (경로는 각 service 마다 다르니 systemctl status xxx로 확인해서 변경하자.)

[Service]

LimitNOFILE=65535
LimitNPROC=65535
...

물론 이를 변경하고 daemon-reload를 하고 restart를 진행하면 원하는 limits가 적용된다.

systemctl daemon-reload
systemctl restart XXXXXX

참고사항

참고로 Rocky Linux에서는 default value를 어떻게 가지는지 확인해보면

[rocky@localhost ~]$ systemctl show -p DefaultLimitNOFILE
DefaultLimitNOFILE=262144

default value가 올라가 있는것을 확인할 수 있다.

'os > Linux' 카테고리의 다른 글

nftables  (0) 2022.08.09
print net_ratelimit in the message  (0) 2022.02.15
How to occur hung_task_panic on Rocky Linux  (0) 2021.11.03
Ubuntu CVE Status  (0) 2021.03.17
KVM with NAT network  (0) 2021.01.27
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함