
Photo by
uranus_xii_jp
【IT】max file descriptors対策(RHEL9)
皆さま
こんにちは
OSをインストール後、デフォルトですと
ファイルのオープン数が1024となっております。
ファイルを多数オープンするプロセスがあった場合に
頭打ちがすぐに来てしまいます。
今回は、RHEL9を用いてOS全体での設定をします。
現状を確認します。
# ulimit -a
real-time non-blocking time (microseconds, -R) 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) 6817
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) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 6817
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
open files が1024のままです。
NOFILEとNPROCの上限をアップします。
# cd /etc/systemd/
# cp -p system.conf system.conf.orig
# diff system.conf system.conf.orig
66d65
< DefaultLimitNOFILE=65535:655359
69d67
< DefaultLimitNPROC=655359
再起動をして再度、確認をします。
# ulimit -a
real-time non-blocking time (microseconds, -R) 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) 6817
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 65535
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Apacheを起動してプロセスが増えているのか確認します。
# systemctl start httpd
# cat /proc/`pgrep httpd | head -1`/limits | grep 'open files'
Max open files 65535 655359 files
プロセス個々に設定する場合は、
例えばSquidに対して設定する場合は、以下のように設定します。
# mkdir /etc/systemd/system/squid.service.d
# vi /etc/systemd/system/squid.service.d/override.conf
ーーーーーーーーーーーーーーーーー
[Service]
LimitNOFILE=101010 (上限1006500)
ーーーーーーーーーーーーーーーー
# systemctl daemon-reload
# systemctl restart squid.service
確認方法:(Portを8080にしている場合)
# squidclient -p 8080 mgr:info | grep "file desc"
Maximum number of file descriptors: 101010
Largest file desc currently in use: 11
Number of file desc currently in use: 6
Available number of file descriptors: 101004
Reserved number of file descriptors: 100
では