用 CentOS 做 API 接口服务器供其他终端调用时,并发量高会报错:java.io.IOException: Too many open files。

其原因是在 Linux 下默认的Socket最大连接数为 1024(可以通过 ulimit -n 查看)。

 

高并发连接导致打开文件过多:java.io.IOException: Too many open files 解决方法

 

于是开始修改Linux的配置文件来增加连接数: 

1.在/etc/rc.local 后增加一行

ulimit -SHn 65535

 

2.在/etc/profile 后增加一行 

ulimit -SHn 65535

 

3.在/etc/security/limits.conf最后加入两行

* soft nofile 65535

* hard nofile 65535

用'*'号表示修改所有用户的限制;

 

重启 Linux 服务器,通过 ulimit -a 查看可以发现

 

高并发连接导致打开文件过多:java.io.IOException: Too many open files 解决方法

到此,完美收官~

 

相关文章:

  • 2021-08-16
  • 2022-01-03
  • 2022-01-21
  • 2022-01-05
  • 2022-01-17
  • 2022-12-23
  • 2021-09-02
  • 2022-01-01
猜你喜欢
  • 2021-05-29
  • 2021-08-13
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
相关资源
相似解决方案