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 小高 閱讀(325) 評論(0)  編輯  收藏 所屬分類: Linux

          導航

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

          統計

          常用鏈接

          留言簿(3)

          隨筆分類(352)

          收藏夾(19)

          關注的blog

          手冊

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 沂源县| 娱乐| 永年县| 观塘区| 无极县| 澄城县| 兴宁市| 贵州省| 襄樊市| 高淳县| 六安市| 正阳县| 衡南县| 嘉黎县| 玛多县| 天等县| 金湖县| 东至县| 佳木斯市| 上栗县| 庆云县| 宁波市| 明溪县| 鄄城县| 双城市| 温泉县| 平武县| 永顺县| 陈巴尔虎旗| 龙里县| 松潘县| 宜城市| 通海县| 安福县| 炉霍县| 苗栗市| 桐乡市| 彝良县| 共和县| 安塞县| 哈巴河县|