4

申し訳ありませんが、この質問にはいくつかのレイヤーがありますが、すべて開いているファイルの数を扱っています。

開発中のアプリのアプリケーション ログに「開いているファイルが多すぎます」というメッセージが表示されます。誰かが私に提案しました:

  1. システム全体およびユーザーごとに、現在使用されている開いているファイルの数を見つける
  2. システムとユーザーの開いているファイルの制限を見つけます。

実行ulimit -nしたところ、1024 が返されました。 /etc/limits.conf も調べましたが、そのファイルには特別なものはありません。/etc/sysctl.conf も変更されません。以下にファイルの内容を列挙します。も実行しましたがlsof | wc -l、これは 5000 行以上を返しました (正しく使用している場合)。

だから、私の主な質問は次のとおりです。

  1. ユーザーごとに許可されている開いているファイルの数を確認するにはどうすればよいですか? ソフト制限は、/etc/limits.conf で見つかった/定義された nofile 設定ですか? /etc/limits.conf に触れていないので、デフォルトは何ですか?
  2. システム全体で許可されている開いているファイルの数を確認するにはどうすればよいですか? limits.conf のハード リミットですか? limits.conf が変更されていない場合のデフォルトの数は?
  3. 開いているファイルに対して ulimit が返す数値は? 1024 と表示されますが、lsof を実行して行数を数えると、5000 以上あるため、何かがクリックされません。これらの制限を取得するために実行する必要がある他のコマンドやファイルはありますか? よろしくお願いします。

limits.conf の内容

# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - an user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open files
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4

# End of file

sysctl.conf の内容

# Controls IP packet forwarding
net.ipv4.ip_forward = 0

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1

# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536

# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296

# the interval between the last data packet sent and the first keepalive probe
net.ipv4.tcp_keepalive_time = 600

# the interval between subsequential keepalive probes
net.ipv4.tcp_keepalive_intvl = 60

# the interval between the last data packet sent and the first keepalive probe
net.ipv4.tcp_keepalive_time = 600

# the interval between subsequential keepalive probes
net.ipv4.tcp_keepalive_intvl = 60

# the number of unacknowledged probes to send before considering the connection dead and notifying the application layer
net.ipv4.tcp_keepalive_probes = 10

# the number of unacknowledged probes to send before considering the connection dead and notifying the application layer
net.ipv4.tcp_keepalive_probes = 10

# try as hard as possible not to swap, as safely as possible
vm.swappiness = 1
fs.aio-max-nr = 1048576
#fs.file-max = 4096
4

1 に答える 1

5

ユーザーごとのファイル制限はありません。注意する必要があるのは、システム全体およびプロセスごとです。プロセスあたりのファイル数の制限にユーザーあたりのプロセス数の制限を掛けると、理論的にはユーザーあたりのファイル数の制限が得られますが、通常の値では、製品は非常に大きくなり、事実上無制限になります。

また、lsof の本来の目的は、開いているファイルを一覧表示することでしたが、現在では cwd や mmap 領域などの他のものを拡張して一覧表示しています。これが、予想よりも多くの行を出力するもう 1 つの理由です。

エラーメッセージ「開いているファイルが多すぎます」は、プロセスごとの制限である errno 値に関連付けられていますEMFILE。この場合、1024 のように見えます。lsof を単一プロセスの実際のファイル記述子のみを表示するように制限する適切なオプションが見つかった場合、おそらくそれらが 1024 個、または非常に近い値であることがわかります。

システム全体のファイル記述子の制限は、デフォルト値がメモリに比例するため、最近では手動で調整する必要はほとんどありません。必要な場合は、 で、/proc/sys/fs/file-max現在の使用状況に関する情報を で見つけることができます/proc/sys/fs/file-nr。sysctl ファイルの値は4096forですfile-maxが、コメントアウトされているため、真剣に受け止めないでください。

システム全体の制限に達すると、 errno が返さENFILEれ、「ファイル テーブル オーバーフロー」または「システムで開いているファイルが多すぎます」というエラー メッセージに変換されます。

于 2014-02-25T01:59:50.447 に答える