mongodb连接超时
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=192.168.74.129:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
-
详情片段:
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=192.168.74.129:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}] at com.mongodb.connection.BaseCluster.getDescription(BaseCluster.java:167) at com.mongodb.Mongo.getConnectedClusterDescription(Mongo.java:885) at com.mongodb.Mongo.createClientSession(Mongo.java:877) at com.mongodb.Mongo$3.getClientSession(Mongo.java:866) at com.mongodb.Mongo$3.execute(Mongo.java:823) at com.mongodb.MongoCollectionImpl.executeCount(MongoCollectionImpl.java:215) at com.mongodb.MongoCollectionImpl.count(MongoCollectionImpl.java:183) at com.mongodb.MongoCollectionImpl.count(MongoCollectionImpl.java:173)
-
原因:
我使用的是虚拟机centos7.6,经多方验证最后发现是由于防火墙的原因。 -
解决方案:
关闭防火墙// 停止firewall systemctl stop firewalld.service // 禁止firewall开机启动 systemctl disable firewalld.service