linux修改open files:ulimit、file-max
linux修改open files:ulimit、file-max
linux系統(tǒng)默認的open files 為1024 ,如果程序報錯 too many open files錯誤,就是因為open files 數(shù)目不夠,需要修改ulimit 和file-max
file-max的含義。man proc,可得到file-max的描述:
/proc/sys/fs/file-maxThis file defines a system-wide limit on the number of open files for all processes. (Seealso setrlimit(2), which can be used by a process to set the per-process limit,RLIMIT_NOFILE, on the number of files it may open.) If you get lots of error messagesabout running out of file handles, try increasing this value:即file-max是設置 系統(tǒng)所有進程一共可以打開的文件數(shù)量 。同時一些程序可以通過setrlimit調(diào)用,設置每個進程的限制。如果得到大量使用完文件句柄的錯誤信息,是應該增加這個值。也就是說,這項參數(shù)是系統(tǒng)級別的。
ulimit
Provides control over the resources available to the shell and to processes started by it, on systems that allow such control.即設置當前shell以及由它啟動的進程的資源限制。顯然,對服務器來說,file-max, ulimit都需要設置,否則就可能出現(xiàn)文件描述符用盡的問題修改。
1.修改file-max
# echo 6553560 > /proc/sys/fs/file-max # sysctl -w "fs.file-max=34166"前面2種重啟機器后會恢復為默認值
或 `# vim /etc/sysctl.conf `加入以下內(nèi)容,重啟生效 fs.file-max = 65535602.需改open files
# ulimit -HSn 102400 //這只是在當前終端有效,退出之后,open files又變?yōu)槟J值。當然也可以寫到/etc/profile中,因為每次登錄終端時,都會自動執(zhí)行/etc/profile 或 # vim /etc/security/limits.conf //加入以下配置,重啟即可生效 * soft nofile 65535 * hard nofile 65535附錄1.
為了讓一個程序的open files數(shù)目擴大,可以在啟動腳本前面加上ulimit -HSn 102400命令。但當程序是一個daemon時,可能這種方法無效,因為沒有終端。
附錄2.
如果某項服務已經(jīng)啟動,再動態(tài)調(diào)整ulimit是無效的,特別是涉及到線上業(yè)務就更麻煩了。
這時,可以考慮通過修改/proc/’程序pid’/limits來實現(xiàn)動態(tài)修改.
參考鏈接:
https://www.cnblogs.com/cncaptain/p/8629502.html
總結(jié)
以上是生活随笔為你收集整理的linux修改open files:ulimit、file-max的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: helm部署SkyWalking
- 下一篇: k8s部署postgresql(含pos