Mongodb Error: network error while attempting to run command ‘isMaster’ on host

$ mongo
MongoDB shell version: 3.2.4
connecting to: test
2016-05-16T14:33:58.461+0800 E QUERY    [thread1] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017'  :
connect@src/mongo/shell/mongo.js:224:14
@(connect):1:6

exception: connect failed

搜了一下有说一个解决方案是在启动参数上加个flag

Solution: add the following option to your mongod command
--bind_ip 127.0.0.1 

不过燃冰暖,随后检查了下日志发现其实就是连接数过多,

...
2016-05-16T14:33:28.311+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:50075 #200 (200 connections now open)
2016-05-16T14:33:28.311+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:50074 #201 (201 connections now open)
2016-05-16T14:33:28.311+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:50089 #202 (202 connections now open)
2016-05-16T14:33:28.312+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:50088 #203 (203 connections now open)
2016-05-16T14:33:28.312+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:50087 #204 (204 connections now open)
2016-05-16T14:33:38.360+0800 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:50092 #205 (205 connections now open)
2016-05-16T14:33:38.360+0800 I NETWORK  [initandlisten] connection refused because too many open connections: 204

根据日志里面的 accepted from ip:port ,找到端口,然后 lsof -i tcp:50075 之类的命令找到访问太多的进程,问题基本上就找到了。

实际上的问题应该是 “connection refused because too many open connections: 204”

Advertisements