LoginSignup
3
6

More than 5 years have passed since last update.

reboot/shutdown後も設定を維持したい場合はulimit -nではなく/etc/security/limits.confを編集する(「Too many open files」「ファイルを開きすぎています」エラー対策)

Posted at

RHEL7/CentOS7上で開発や運用をしていると「Too many open files」「ファイルを開きすぎています」といったエラーが出ることがあります。これはファイルディスクリプタの枯渇が原因であり、その上限値を調整することが対策法となります。

さて調査の結果、ファイルディスクリプタの上限値はulimit -nにより設定できることが分かったのですが――ulimitによる設定は一時的な効力しかなく、rebootshutdownをすると、もともとの値に戻ってしまいます。

[root@localhost ~]# ulimit -n
1024
[root@localhost ~]# ulimit -n 4096
[root@localhost ~]# ulimit -n 
4096
[root@localhost ~]# reboot 

=== 再起動後 === 

[root@localhost ~]# ulimit -n
1024

shutdown/reboot後も設定を維持したいという場合/etc/security/limits.confという設定ファイルに以下のような記述をくわえます。

* soft nofile 4096
* hard nofile 4096

/etc/security/limits.confには詳細な説明と凡例が掲載されているので、説明は割愛します。

[root@localhost ~]# vi /etc/security/limits.conf 
[root@localhost ~]# tail -n 5 /etc/security/limits.conf

* soft nofile 4096
* hard nofile 4096

# End of file
[root@localhost ~]# reboot

=== 再起動後 ===

[root@localhost ~]# ulimit -n
4096
3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6