tomcat6解决too many open files
cookqq ›博客列表 ›tomcat

tomcat6解决too many open files

2015-11-23 12:39:30.0|分类: tomcat|浏览量: 3519

摘要: 网上普遍解决方法:(1)ulimit -n 2048 当前用户的最大允许打开文件数量设置为2048 (2)在 /etc/security/limits.conf 但是上面的方法设置open files失败,tomcat还是会报错too many open files 正确的方法是:(1)打开/etc/init.d/tomcat文件 (2)在start命令后面增加

最近发现tomcat日志发现too many open files

严重: Socket accept failed
java.net.SocketException: Too many open files
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:408)
at java.net.ServerSocket.implAccept(ServerSocket.java:462)
at java.net.ServerSocket.accept(ServerSocket.java:430)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:61)
at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:352)
at java.lang.Thread.run(Thread.java:662)
2015-11-20 12:57:52 org.apache.tomcat.util.net.JIoEndpoint$Acceptor run

too many open files问题是程序打开的文件/socket连接数量超过系统设定值,

(1)看每个用户最大允许打开文件数量ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 20
file size               (blocks, -f) unlimited
pending signals                 (-i) 16382
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

    其中 open files (-n) 1024 表示每个用户最大允许打开的文件数量是1024

(2)查看当前系统打开的文件数量

    lsof | wc -l  

    watch "lsof | wc -l" 

(3)查看某一进程的打开文件数量

    lsof -p 1234 | wc -l 

解决办法根本:修改open files 最大数量。

网上普遍解决方法:

    (1)ulimit -n 2048  当前用户的最大允许打开文件数量设置为2048

    (2)在 /etc/security/limits.conf  加入

            * soft nofile 4096   * 表示所有用户

            * hard nofile 4096  

但是上面的方法设置open files失败,tomcat还是会报错too many open files

正确的方法是:(1)打开/etc/init.d/tomcat文件(这个是tomcat启动文件)

         (2)在start命令后面增加

            ulimit -f unlimited

            ulimit -t unlimited

            ulimit -v unlimited

            ulimit -n 64000

            ulimit -m unlimited


            # In dash, ulimit takes -p for maximum user processes

            # In ba**'s -u

            if readlink /proc/$$/exe | grep -q dash

            then

                    ulimit -p 32000

            else

                    ulimit -u 32000

            fi

如下:::

...
case "$1" in
  start)
        if [ -z "$JAVA_HOME" ]; then
                log_failure_msg "no JDK found - please set JAVA_HOME"
                exit 1
        fi
        if [ ! -d "$CATALINA_BASE/conf" ]; then
                log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
                exit 1
        fi
            ulimit -f unlimited
            ulimit -t unlimited
            ulimit -v unlimited
            ulimit -n 64000
            ulimit -m unlimited
            # In dash, ulimit takes -p for maximum user processes
            # In bash, it's -u
            if readlink /proc/$$/exe | grep -q dash
            then
                    ulimit -p 32000
            else
                    ulimit -u 32000
            fi
        log_daemon_msg "Starting $DESC" "$NAME"
        if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
                --user $TOMCAT6_USER --exec "$JAVA_HOME/bin/java" \
                >/dev/null; then
                ....


(3)解决了tomcat的too many open files问题


一键分享文章

分类列表

  • • struts源码分析
  • • flink
  • • struts
  • • redis
  • • kafka
  • • ubuntu
  • • zookeeper
  • • hadoop
  • • activiti
  • • linux
  • • 成长
  • • NIO
  • • 关键词提取
  • • mysql
  • • android studio
  • • zabbix
  • • 云计算
  • • mahout
  • • jmeter
  • • hive
  • • ActiveMQ
  • • lucene
  • • MongoDB
  • • netty
  • • flume
  • • 我遇到的问题
  • • GRUB
  • • nginx
  • • 大家好的文章
  • • android
  • • tomcat
  • • Python
  • • luke
  • • android源码编译
  • • 安全
  • • MPAndroidChart
  • • swing
  • • POI
  • • powerdesigner
  • • jquery
  • • html
  • • java
  • • eclipse
  • • shell
  • • jvm
  • • highcharts
  • • 设计模式
  • • 列式数据库
  • • spring cloud
  • • docker+node.js+zookeeper构建微服务
版权所有 cookqq 感谢访问 支持开源 京ICP备15030920号
CopyRight 2015-2018 cookqq.com All Right Reserved.