【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”
@kurumi 你好,想跟你请教个问题:
http://www.oschina.net/question/2380402_248685 这篇帖子我遇到了同样的问题一直没有解决~
复制集状态都正常:
{
"set" : "res",
"date" : ISODate("2016-09-12T10:01:24.787Z"),
"myState" : 1,
"term" : NumberLong(23),
"heartbeatIntervalMillis" : NumberLong(2000),
"members" : [
{
"_id" : 0,
"name" : "172.16.200.41:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 23605,
"optime" : {
"ts" : Timestamp(1473672023, 2),
"t" : NumberLong(23)
},
"optimeDate" : ISODate("2016-09-12T09:20:23Z"),
"lastHeartbeat" : ISODate("2016-09-12T10:01:23.556Z"),
"lastHeartbeatRecv" : ISODate("2016-09-12T10:01:23.137Z"),
"pingMs" : NumberLong(1),
"syncingTo" : "172.16.100.40:27017",
"configVersion" : 2
},
{
"_id" : 1,
"name" : "172.16.100.40:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 23605,
"optime" : {
"ts" : Timestamp(1473672023, 2),
"t" : NumberLong(23)
},
"optimeDate" : ISODate("2016-09-12T09:20:23Z"),
"electionTime" : Timestamp(1473672023, 1),
"electionDate" : ISODate("2016-09-12T09:20:23Z"),
"configVersion" : 2,
"self" : true
},
{
"_id" : 2,
"name" : "172.16.200.20:27017",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 1860,
"lastHeartbeat" : ISODate("2016-09-12T10:01:23.701Z"),
"lastHeartbeatRecv" : ISODate("2016-09-12T10:01:24.746Z"),
"pingMs" : NumberLong(0),
"configVersion" : 2
}
],
"ok" : 1
}
但JAVA连接就出错:
String url = "mongodb://" + "admin" + ":" + "res1234" + "@"
+ "54.119.134.45:27017" + ","
+ "54.119.129.46:27017" + "/"
+ "admin"
+ "?replicaSet=" + replset_name
+ "&slaveOk=true&connectTimeoutMS=300000&readPreference=secondary";
System.out.println(url);
MongoClientURI connectionString = new MongoClientURI(url);
return new MongoClient(connectionString);
错误信息:
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector.
Client view of cluster state is {type=REPLICA_SET, servers=[{address=172.16.100.40:27017, type=UNKNOWN, state=CONNECTING,
exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}},
{address=172.16.200.20:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket},
caused by {java.net.SocketTimeoutException: connect timed out}},
{address=172.16.200.41:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket},
caused by {java.net.SocketTimeoutException: connect timed out}}]