{"id":49771,"date":"2023-08-12T14:42:49","date_gmt":"2023-08-12T06:42:49","guid":{"rendered":"http:\/\/xyryd.com\/?p=49771"},"modified":"2024-03-30T14:31:52","modified_gmt":"2024-03-30T06:31:52","slug":"linux-debian-%e4%b8%8b-too-many-open-files-%e9%97%ae%e9%a2%98%e6%8e%92%e6%9f%a5%e4%b8%8e%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"http:\/\/www.xyryd.com\/49771.html","title":{"rendered":"Linux Debian \u4e0b Too many open files \u95ee\u9898\u6392\u67e5\u4e0e\u89e3\u51b3"},"content":{"rendered":"\n
\n

Too many open files\u662fLinux\u7cfb\u7edf\u4e2d\u5e38\u89c1\u7684\u9519\u8bef\uff0c\u4ece\u5b57\u9762\u610f\u601d\u4e0a\u770b\u5c31\u662f\u8bf4\u7a0b\u5e8f\u6253\u5f00\u7684\u6587\u4ef6\u6570\u8fc7\u591a\uff0c\u4e0d\u8fc7\u8fd9\u91cc\u7684files\u4e0d\u5355\u662f\u6587\u4ef6\u7684\u610f\u601d\uff0c\u4e5f\u5305\u62ec\u6253\u5f00\u7684\u901a\u8baf\u94fe\u63a5(\u6bd4\u5982socket)\uff0c\u6b63\u5728\u76d1\u542c\u7684\u7aef\u53e3\u7b49\u7b49\uff0c\u6240\u4ee5\u6709\u65f6\u5019\u4e5f\u53ef\u4ee5\u53eb\u505a\u53e5\u67c4(handle)\uff0c\u8fd9\u4e2a\u9519\u8bef\u901a\u5e38\u4e5f\u53ef\u4ee5\u53eb\u505a\u53e5\u67c4\u6570\u8d85\u51fa\u7cfb\u7edf\u9650\u5236\u3002\u5f15\u8d77\u7684\u539f\u56e0\u5c31\u662f\u8fdb\u7a0b\u5728\u67d0\u4e2a\u65f6\u523b\u6253\u5f00\u4e86\u8d85\u8fc7\u7cfb\u7edf\u9650\u5236\u7684\u6587\u4ef6\u6570\u91cf\u4ee5\u53ca\u901a\u8baf\u94fe\u63a5\u6570\u3002<\/p>\n<\/blockquote>\n\n\n\n

\u901a\u8fc7\u547d\u4ee4 ulimit -a<\/code> \u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u8bbe\u7f6e\u7684\u6700\u5927\u53e5\u67c4\u6570\u662f\u591a\u5c11<\/p>\n\n\n\n

core file size          (blocks, -c) 0\ndata seg size           (kbytes, -d) unlimited\nscheduling priority             (-e) 0\nfile size               (blocks, -f) unlimited\npending signals                 (-i) 31767\nmax locked memory       (kbytes, -l) 64\nmax memory size         (kbytes, -m) unlimited\nopen files                      (-n) 1024\npipe size            (512 bytes, -p) 8\nPOSIX message queues     (bytes, -q) 819200\nreal-time priority              (-r) 0\nstack size              (kbytes, -s) 8192\ncpu time               (seconds, -t) unlimited\nmax user processes              (-u) 31767\nvirtual memory          (kbytes, -v) unlimited\nfile locks                      (-x) unlimited\n<\/code><\/pre>\n\n\n\n

\u53ef\u4ee5\u770b\u5230\uff0copen files\u7684\u914d\u7f6e\u662f1024\uff0c\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\u5c06open files\u589e\u52a0<\/p>\n\n\n\n

ulimit -n 65535<\/code><\/code><\/pre>\n\n\n\n

\u8fd9\u79cd\u4fee\u6539\u65b9\u5f0f\u53ef\u4ee5\u4e34\u65f6<\/strong>\u628a\u6587\u4ef6\u6253\u5f00\u6570\u91cf\u589e\u52a0\u523065535\uff0c\u4f46\u662f\u7cfb\u7edf\u91cd\u542f\u540e\u8fd9\u4e2a\u914d\u7f6e\u4f1a\u5931\u6548\u3002<\/p>\n\n\n\n

\u8fd8\u6709\u4e00\u79cd\u65b9\u5f0f\u662f\u4fee\u6539\u7cfb\u7edf\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4ee5Ubuntu\u4e3a\u4f8b\uff0c\u914d\u7f6e\u6587\u4ef6\u9ed8\u8ba4\u5728<\/p>\n\n\n\n

vi \/etc\/security\/limits.conf<\/code><\/pre>\n\n\n\n

\u5728\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\u589e\u52a0<\/p>\n\n\n\n

* soft nofile 65535\n* hard nofile 65535<\/code><\/pre>\n\n\n\n

\u5982\u679c\u8981\u67e5\u770b\u67d0\u4e2a\u8fdb\u7a0b\u76ee\u524d\u6253\u5f00\u7684\u53e5\u67c4\u6570\u91cf\uff0c\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n

lsof -p \u8fdb\u7a0bID|wc -l<\/code><\/pre>\n\n\n\n

\u6b64\u5916\uff0c\u5982\u679c\u7528supervisor\u6258\u7ba1\u548c\u542f\u52a8\u9879\u76ee\uff0c\u4f1a\u9047\u5230\u8fd9\u4e2a\u914d\u7f6e\u65e0\u6cd5\u751f\u6548\u7684\u95ee\u9898\uff0c\u539f\u56e0\u5728\u4e8esupervisor\u4f1a\u9ed8\u8ba4\u914d\u7f6e\u6253\u5f00\u7684\u53e5\u67c4\u6570\u91cf\u662f1024\uff0c<\/p>\n\n\n\n

\u5982\u679c\u8981\u67e5\u770b\u67d0\u4e2a\u8fdb\u7a0b\u6700\u5927open files\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u8fdb\u7a0b\u7684\u8fdb\u7a0b\u53f7\u5bf9\u5e94\u7684limits\u67e5\u770b<\/p>\n\n\n\n

cat \/proc\/\u8fdb\u7a0bID\/limits<\/code><\/pre>\n\n\n\n

\u5176\u4e2d\u6709\u4e00\u884c\u662f\uff1a<\/p>\n\n\n\n

Max open files 1024 1024 bytes<\/code><\/pre>\n\n\n\n

supervisor\u6258\u7ba1\u7684\u7a0b\u5e8f\u8fd9\u4e00\u884c\u9ed8\u8ba4\u90fd\u662fsupervisor\u914d\u7f6e\u7684\u6700\u5927\u6570\u91cf1024\uff0c\u8fd9\u65f6\u9700\u8981\u624b\u52a8\u6539\u4e00\u4e0bsupervisor\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4fee\u6539\u65b9\u5f0f\u5982\u4e0b\uff0c\u4ee5Ubuntu\u7cfb\u7edf\u4e3a\u4f8b\uff0c\u627e\u5230supervisor\u7684\u914d\u7f6e\u6587\u4ef6supervisord.conf<\/p>\n\n\n\n

\u5728[supervisord]<\/code>\u9009\u9879\u4e2d\uff0c\u589e\u52a0minfds\u9009\u9879\u7684\u914d\u7f6e<\/p>\n\n\n\n

[supervisord]\nminfds=65535                  ; min. avail startup file descriptors; default 1024<\/code><\/pre>\n\n\n\n

\u914d\u7f6e\u5b8c\u6bd5\u540e\uff0c\u9700\u8981\u91cd\u542fsupervisor(\u4ee5systemctl\u4e3a\u4f8b)<\/p>\n\n\n\n

systemctl restart supervisor<\/code><\/p>\n\n\n\n

\u5373\u53ef\u751f\u6548<\/p>\n\n\n\n

\u5728\u901a\u8fc7\uff1acat \/proc\/\u8fdb\u7a0b\u53f7\/limits<\/code><\/p>\n\n\n\n

\u67e5\u770b\u4e0b\u5bf9\u5e94\u8fdb\u7a0b\u7684\u53efopen files\u7684\u6570\u91cf<\/p>\n\n\n\n

Max open files 65535 65535 bytes<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Too many open files\u662fLinux\u7cfb\u7edf\u4e2d\u5e38\u89c1\u7684\u9519\u8bef\uff0c\u4ece\u5b57\u9762\u610f\u601d\u4e0a\u770b\u5c31\u662f\u8bf4\u7a0b\u5e8f\u6253\u5f00\u7684\u6587\u4ef6\u6570\u8fc7\u591a\uff0c […]<\/p>\n","protected":false},"author":1,"featured_media":45598,"comment_status":"open","ping_status":"closed","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[34,17],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/49771"}],"collection":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/comments?post=49771"}],"version-history":[{"count":1,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/49771\/revisions"}],"predecessor-version":[{"id":50687,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/49771\/revisions\/50687"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media\/45598"}],"wp:attachment":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media?parent=49771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/categories?post=49771"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/tags?post=49771"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}