zoukankan      html  css  js  c++  java
  • linux服务器报Too many open files的解决方法

    linux 上tomcat 服务器抛出socket异常“文件打开太多”的问题 
    java.net.SocketException: Too many open files
    at java.net.PlainSocketImpl.socketAccept(Native Method)
    at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
    at java.net.ServerSocket.implAccept(ServerSocket.java:450)
    at java.net.ServerSocket.accept(ServerSocket.java:421)
    at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.acceptSocket(PoolTcpEndpoint.java:407)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:70)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595) 
    原本以为是tomcat的配置或是应用本身的问题,"谷歌"一把后才发现,该问题的根本原因是由于系统文件资源的限制导致的。
    具体的解决方式可以参考一下:
    1。ulimit -a 查看系统目前资源限制的设定。
    [root@test security]# ulimit -a
    core file size        (blocks, -c) 0
    data seg size         (kbytes, -d) unlimited
    file size             (blocks, -f) unlimited
    max locked memory     (kbytes, -l) unlimited
    max memory size       (kbytes, -m) unlimited
    open files                    (-n) 1024
    pipe size          (512 bytes, -p) 8
    stack size            (kbytes, -s) 8192
    cpu time             (seconds, -t) unlimited
    max user processes            (-u) 7168
    virtual memory        (kbytes, -v) unlimited
    [root@test security]# 
    通过以上命令,我们可以看到open files 的最大数为1024
    那么我们可以通过一下命令修改该参数的最大值
    2. ulimit -n 4096
    [root@test security]# ulimit -n 4096
    [root@test security]# ulimit -a
    core file size        (blocks, -c) 0
    data seg size         (kbytes, -d) unlimited
    file size             (blocks, -f) unlimited
    max locked memory     (kbytes, -l) unlimited
    max memory size       (kbytes, -m) unlimited
    open files                    (-n) 4096
    pipe size          (512 bytes, -p) 8
    stack size            (kbytes, -s) 8192
    cpu time             (seconds, -t) unlimited
    max user processes            (-u) 7168
    virtual memory        (kbytes, -v) unlimited
    这样我们就修改了系统在同一时间打开文件资源的最大数,基本解决以上问题。

    报这个错误就在我那次登陆更新之后又报的,原来ulimit -n 4096 命令只能临时的改变open files 的值,当重新登陆后又会恢复,所以需要永久设置open files 的值才行啊,用ulimit -n 修改open files 总是不能保持。所以用下面一个简单的办法更好些。
    修改/etc/security/limits.conf
    添加如下一行:* - nofile 65536

    修改/etc/pam.d/login
    添加如下一行session required /lib/security/pam_limits.so

    退出shell登陆,重新登陆一次即生效(运行ulimit -n 检查)

  • 相关阅读:
    centos7 安装prometheus node_exporter
    RMAN备份演练初级篇
    RMAN命令
    oracle数据库的归档模式
    oracle的会话(session)
    oracle的例程
    oracle热备份
    Oracle数据库归档模式的切换及其相关操作详解
    Oracle角色
    类名.class, class.forName(), getClass()区别
  • 原文地址:https://www.cnblogs.com/yangxia-test/p/3356928.html
Copyright © 2011-2022 走看看