JUST DO IT ~

          我只想當個程序員

          too many open files

          * too many open files 

          層次上:
          1.修改系統級限制. (/etc/sysctl.conf)
          2.修改用戶啟動shell限制.( /etc/security/limits.conf )
          3.修改當前回話限制. (有可能無效或者因為系統限制未修改.)(ulimited )
          4.如果已經啟動的程序,修復那么需要調用系統api RLIM_INFINITY.

          如果1和2步驟都做的好,根本不需要3和4.

          1,系統內核限制
          vi /etc/sysctl.conf
          添加:
          fs.file-max = 102400
          sysctl -p

          臨時方案:
          sysctl -w fs.file-max=10240

          2,針對用戶的限制
          cat /etc/security/limits.conf 
          vi  /etc/security/limits.conf
          *  soft nofile 102400
          *  hard nofile 102400
          查看某一個進程的限制
          cat /proc/815/limits

          bash_profile啟動進程腳本中加入:
          ulimit -f unlimited
          ulimit -t unlimited
          ulimit -v unlimited
          ulimit -u 65535
          ulimit -m unlimited
          ulimit -u 65535
          很可能會執行出結果:
          ulimit: open files: cannot modify limit: Operation not permitted
          ulimit: max locked memory: cannot modify limit: Operation not permitted

          很可能 security-limits.conf 未設定或者設定的太小了.
          大殺器:
          sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"   
          這句話可能不會執行.bash_profile需要手工執行以下.
          另外這句話還要exit 2次.

          fork出的子進程,資源限制都是父進程那里繼承來的.
          ulimit 只是對會話有效.
          如果不能關服務程序,只能動態需改.通過C程序.

          ulimit 并不是一個命令,是一個shell內部的指令.
          sudo 是一個命令.所以無法執行.sudo ulimit 
          當前的shell被新shell覆蓋掉了.新的shell含有ulimit.
          要exit 2次.
          http://stackoverflow.com/questions/17483723/command-not-found-when-using-sudo-ulimit


          參考:

          bash內建的功能.
          http://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins
          一次「Too many open files」故障
          http://huoding.com/2015/08/02/460   
          動態修改運行中進程的 rlimit
          http://xiezhenye.com/2013/02/%E5%8A%A8%E6%80%81%E4%BF%AE%E6%94%B9%E8%BF%90%E8%A1%8C%E4%B8%AD%E8%BF%9B%E7%A8%8B%E7%9A%84-rlimit.html

          動態修改運行中進程的 ulimit
          http://blog.chinaunix.net/uid-20662820-id-3928094.html

          中文注釋ulimit具體項目
          http://man.linuxde.net/ulimit

          linux的ulimit限制詳解 --有測試系統代碼
          http://www.dbafree.net/?p=967

          posted on 2015-12-10 10:39 小高 閱讀(334) 評論(0)  編輯  收藏 所屬分類: Linux

          導航

          <2015年12月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          統計

          常用鏈接

          留言簿(3)

          隨筆分類(352)

          收藏夾(19)

          關注的blog

          手冊

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 攀枝花市| 密山市| 太保市| 平利县| 扎赉特旗| 孟州市| 巫山县| 江安县| 灵寿县| 平原县| 北碚区| 峨眉山市| 永平县| 翁牛特旗| 永定县| 云龙县| 阿合奇县| 洛南县| 德庆县| 云浮市| 宣汉县| 周宁县| 河东区| 大城县| 岑溪市| 五常市| 横山县| 延吉市| 修水县| 白朗县| 永嘉县| 合水县| 射阳县| 公安县| 元谋县| 静乐县| 潮州市| 岑溪市| 谢通门县| 扎兰屯市| 肇源县|