linux 開啟檔案數 too many open files 解決方案

來源:互聯網
上載者:User

標籤:code   串連數量   content   pipe   ulimit   soc   core   files   登出   

linux 開啟檔案數 too many open files 解決方案


too many open files

出現這句提示的原因是程式開啟的檔案/socket串連數量超過系統設定值。


查看每一個使用者最大同意開啟檔案數量

ulimit -a

[email protected]:~$ ulimit -acore file size          (blocks, -c) 0data seg size           (kbytes, -d) unlimitedscheduling priority             (-e) 20file size               (blocks, -f) unlimitedpending signals                 (-i) 16382max locked memory       (kbytes, -l) 64max memory size         (kbytes, -m) unlimitedopen files                      (-n) 1024pipe size            (512 bytes, -p) 8POSIX message queues     (bytes, -q) 819200real-time priority              (-r) 0stack size              (kbytes, -s) 8192cpu time               (seconds, -t) unlimitedmax user processes              (-u) unlimitedvirtual memory          (kbytes, -v) unlimitedfile locks                      (-x) unlimited

當中 open files (-n) 1024 表示每一個使用者最大同意開啟的檔案數量是1024


查看當前系統開啟的檔案數量

lsof | wc -lwatch "lsof | wc -l"

查看某一進程的開啟檔案數量

lsof -p pid | wc -llsof -p 1234 | wc -l

設定open files數值方法

ulimit -n 2048

[email protected]:~$ ulimit -n 2048[email protected]:~$ ulimit -acore file size          (blocks, -c) 0data seg size           (kbytes, -d) unlimitedscheduling priority             (-e) 20file size               (blocks, -f) unlimitedpending signals                 (-i) 16382max locked memory       (kbytes, -l) 64max memory size         (kbytes, -m) unlimitedopen files                      (-n) 2048pipe size            (512 bytes, -p) 8POSIX message queues     (bytes, -q) 819200real-time priority              (-r) 0stack size              (kbytes, -s) 8192cpu time               (seconds, -t) unlimitedmax user processes              (-u) unlimitedvirtual memory          (kbytes, -v) unlimitedfile locks                      (-x) unlimited

這樣就能夠把目前使用者的最大同意開啟檔案數量設定為2048了。但這樣的設定方法在重新啟動後會還原為預設值。


永久設定方法

vim /etc/security/limits.conf在最後增加* soft nofile 4096* hard nofile 4096
最前的 * 表示全部使用者。可依據須要設定某一使用者,比如

fdipzone soft nofile 8192fdipzone hard nofile 8192
改完後登出一下就能生效。


linux 開啟檔案數 too many open files 解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.