systemd / ulimit 制限のプロパティ一覧

10月 3, 2023AmazonLinux_CentOS,OperatingSystem,Ubuntu(WSL)

概要

  • Linux において、リソースの制限を掛けたい! という要件があります。だけど、頻度は低いため指定方法が分からなくなってしまう。今回は、systemd のプロパティ/ ulimit のオプションの対応が分かる一覧になります。
  • Linux の systemd にdrop-in のユニット構成ファイル (/etc/systemd/system/[サービス名].d/limits.conf) を作成し、リソースの制限を行う際に活用できます。

プロパティ一覧

systemd ulimit Description Used
LimitCORE= ulimit -c core files size Bytes
LimitDATA= ulimit -d data segment size Bytes
LimitNICE= ulimit -e niceness level Nice Level
LimitFSIZE= ulimit -f file size Bytes
LimitSIGPENDING= ulimit -i queued signals Number of Queued Signals
LimitMEMLOCK= ulimit -l locked memory size Bytes
LimitRSS= ulimit -m resident set size Bytes
LimitNOFILE= ulimit -n open file descriptors Number of File Descriptors
LimitMSGQUEUE= ulimit -q POSIX message queue size Bytes
LimitRTPRIO= ulimit -r real-time priority Realtime Priority
LimitRTTIME= ulimit -R runtime before blocking Microsecond
LimitSTACK= ulimit -s stack size Bytes
LimitCPU= ulimit -t CPU time Seconds
LimitNPROC= ulimit -u available processes Number of Processes
LimitAS= ulimit -v process virtual memory Bytes
LimitLOCKS= ulimit -x file lock count Number of Locks

 

systemd の設定方法を紹介

  • systemd にdrop-in のユニット構成ファイルを作成し、設定の再読み込みおよびサービスのrestartを行います。
  • サービス再起動後に、systemctl status httpd.service の出力結果に、Drop-In として追加したユニット構成ファイルが表示されています。
$ systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-03-16 02:38:59 UTC; 9h ago
     Docs: man:httpd.service(8)
 Main PID: 2789 (httpd)
   Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec:   0 B/sec"
   CGroup: /system.slice/httpd.service
           tq2789 /usr/sbin/httpd -DFOREGROUND
           tq2823 /usr/sbin/httpd -DFOREGROUND
           tq2824 /usr/sbin/httpd -DFOREGROUND
           tq2827 /usr/sbin/httpd -DFOREGROUND
           tq2828 /usr/sbin/httpd -DFOREGROUND
           mq2829 /usr/sbin/httpd -DFOREGROUND

Mar 16 02:38:59 hostname systemd[1]: Starting The Apache HTTP Se....
Mar 16 02:38:59 hostname httpd[2789]: AH00558: httpd: Could not r...
Mar 16 02:38:59 hostname systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
$ sudo mkdir -p /etc/systemd/system/httpd.service.d
$ sudo vi /etc/systemd/system/httpd.service.d/00-limits.conf
$ cat /etc/systemd/system/httpd.service.d/00-limits.conf
[Service]
LimitNOFILE=32768:32768
$ sudo systemctl daemon-reload
$ sudo systemctl restart httpd.service
$ systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/httpd.service.d
           mq00-limits.conf
   Active: active (running) since Wed 2022-03-16 12:28:00 UTC; 1min 39s ago
     Docs: man:httpd.service(8)
 Main PID: 5970 (httpd)
   Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec:   0 B/sec"
   CGroup: /system.slice/httpd.service
           tq5970 /usr/sbin/httpd -DFOREGROUND
           tq5971 /usr/sbin/httpd -DFOREGROUND
           tq5972 /usr/sbin/httpd -DFOREGROUND
           tq5974 /usr/sbin/httpd -DFOREGROUND
           tq5975 /usr/sbin/httpd -DFOREGROUND
           mq5976 /usr/sbin/httpd -DFOREGROUND

Mar 16 12:28:00 hostname systemd[1]: Stopped The Apache HTTP Server.
Mar 16 12:28:00 hostname systemd[1]: Starting The Apache HTTP Se....
Mar 16 12:28:00 hostname httpd[5970]: AH00558: httpd: Could not r...
Mar 16 12:28:00 hostname systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.