mongodb报错:connection refused because too many open connections: 819
问题:
发现mongodb无法连接,查看mongodb日志,出现大量的如下报错:
[initandlisten] connection refused because too many open connections: 819
mongodb的连接数到达819后,就无法增加,所以无法连接上去。
分析解决:
1、maxConns 限制
默认情况下,在Linux系统中,mongodb的最大连接数为819。
可以修改mongodb的最大连接数,修改其配置文件mongod.conf:
maxIncomingConnections=20000 #官方指定,mongodb最大连接数设置,不能超过20000
重启mongodb服务,让配置生效。
network interfaces
net:
port: 27017
bindIp: [127.0.0.1] # Listen to local interface only, comment to listen on all interfaces.
maxIncomingConnections: 20000
2、ulimit 限制
如果调大了maxConns,还是出现 too many open connections 的报错,也可能跟系统的ulimit限制有关。
Linux系统默认每个进程的文件句柄限制open files 为1024,这数值一般过小,需要调大。
查看系统当前所有的limit信息