Mina之too many open files问题

Linux version 2.6.8 服务器经常出现Too many open files 错误!需要调整一下Linux操作系统的 打开文件的最大句柄数。

要永久生效修改:/etc/security/limits.conf文件

在文件最后加上以下信息:

*  -   nofile 65536

以上语句表示,每个用户打开文件的个数为65536个


修改文件:/etc/sysctl.conf

在文件最后一行加上:

fs.file-max=65536


重启服务器后运行: ulimit -a

[root@redhat ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited

max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

以上红色字体为修改好的 最大打开文件个数!

临时增大 open files的个数可以运行命令:  ulimit -n 65536


以上是解决方案之一,我们可以在apache的官方网站上查询到:

you may have a too low ulimit setup. It defaults to 1024, and each time you open a socket, that eats a file descriptor

You have options, though :
> - either you increase this ulimit, or set it to unlimited,
> - or you lower the tcp-time-wait value so that the sockets are closed faster.

故另外的一个方法就是减少操作系统 socket连接的等待时间

详细解决方案:http://mina.apache.org/mina-project/faq.html

In Windows, the default TIME_WAIT timeout is 4 minutes, in Linux it is 60 seconds.

在windows TIME_WAIT的缺省值是4 minutes,在Linux中时60秒;

修改方法如下:

Change the timeout in Windows(windows的更改方法,改为30-300秒)

  1. Run regedit to start the Registry Editor
  2. Locate the following key: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\tcpip\Parameters
  3. Add a new value named TcpTimedWaitDelay asa decimal and set the desired timeout in seconds (30-300)
  4. Reboot

Change the timeout in Linux(Linux的更改方法,改为30s)

  1. Update the configuration value by running (30 seconds used in the example)

  2. echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
  3. Restart the networking component, for example by running

  4. /etc/init.d/networking restart
    

    or

    service network restart

猜你喜欢

转载自wkm.iteye.com/blog/1761590