zoukankan      html  css  js  c++  java
  • linux修改open files

     

    linux系统默认的open files 为1024 ,如果程序报错 too many open files错误,就是因为open files 数目不够,需要修改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是设置 系统所有进程一共可以打开的文件数量 。同时一些程序可以通过setrlimit调用,设置每个进程的限制。如果得到大量使用完文件句柄的错误信息,是应该增加这个值。也就是说,这项参数是系统级别的。

    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都需要设置,否则就可能出现文件描述符用尽的问题修改。

    1.修改file-max

    # echo  6553560 > /proc/sys/fs/file-max
    # sysctl -w "fs.file-max=34166"

    前面2种重启机器后会恢复为默认值

    或 # vim /etc/sysctl.conf  加入以下内容,重启生效
    fs.file-max = 6553560
    2.需改open files
    # ulimit -HSn 102400 //这只是在当前终端有效,退出之后,open files又变为默认值。当然也可以写到/etc/profile中,因为每次登录终端时,都会自动执行/etc/profile
    # vim /etc/security/limits.conf  //加入以下配置,重启即可生效
    * soft nofile 65535
    * hard nofile 65535
    附录1.
    为了让一个程序的open files数目扩大,可以在启动脚本前面加上ulimit -HSn 102400命令。但当程序是一个daemon时,可能这种方法无效,因为没有终端。
    附录2.
    如果某项服务已经启动,再动态调整ulimit是无效的,特别是涉及到线上业务就更麻烦了。
    这时,可以考虑通过修改/proc/’程序pid’/limits来实现动态修改
  • 相关阅读:
    Java Swing打猎射击游戏源码
    php实现在线下载程序安装包功能
    WP
    双人对战的球类游戏IOS源码
    非常不错的新闻客户端应用安卓源码
    创业建议:如何写挖人邮件
    wp8路线跟踪应用源码详细说明
    wp版笔记本应用源码
    旅游风景展示应用源码iPad版
    bitset优化背包
  • 原文地址:https://www.cnblogs.com/ityunwei/p/13753057.html
Copyright © 2011-2022 走看看