java mongo连接问题,一直超时,原因不知道在哪

kurumi 发布于 2015/09/02 14:08
阅读 49K+
收藏 0

解读下一代网络:算力网络正从理想照进现实!>>>

九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Cluster created with settings {hosts=[183.129.244.199:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=2500}
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Adding discovered server 183.129.244.199:27017 to client view of cluster
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=MULTIPLE, all=[ServerDescription{address=183.129.244.199:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Opened connection [connectionId{localValue:1, serverValue:223527}] to 183.129.244.199:27017
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Monitor thread successfully connected to server with description ServerDescription{address=183.129.244.199:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[2, 6, 7]}, minWireVersion=0, maxWireVersion=2, maxDocumentSize=16777216, roundTripTimeNanos=19822617, setName='logstoge', hosts=[10.96.0.18:27017, 10.96.0.7:27017], passives=[], arbiters=[10.96.0.18:27018], primary='10.96.0.18:27017', tagSet=TagSet{[]}}
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Discovered cluster type of REPLICA_SET
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Adding discovered server 10.96.0.18:27017 to client view of cluster
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Adding discovered server 10.96.0.7:27017 to client view of cluster
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Adding discovered server 10.96.0.18:27018 to client view of cluster
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Server 183.129.244.199:27017 is no longer a member of the replica set.  Removing from client view of cluster.
九月 02, 2015 2:02:47 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Discovered replica set primary 183.129.244.199:27017
九月 02, 2015 2:03:07 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Exception in monitor thread while connecting to server 10.96.0.18:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
... 3 more


九月 02, 2015 2:03:07 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Exception in monitor thread while connecting to server 10.96.0.18:27018
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
... 3 more


九月 02, 2015 2:03:07 下午 com.mongodb.diagnostics.logging.SLF4JLogger info
信息: Exception in monitor thread while connecting to server 10.96.0.7:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
... 3 more


Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=REPLICA_SET, servers=[{address=10.96.0.18:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=10.96.0.18:27018, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=10.96.0.7: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.createTimeoutException(BaseCluster.java:370)
at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
at com.mongodb.binding.ClusterBinding.getReadConnectionSource(ClusterBinding.java:63)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:166)
at com.mongodb.operation.FindOperation.execute(FindOperation.java:394)
at com.mongodb.operation.FindOperation.execute(FindOperation.java:57)
at com.mongodb.Mongo.execute(Mongo.java:736)
at com.mongodb.Mongo$2.execute(Mongo.java:723)
at com.mongodb.OperationIterable.iterator(OperationIterable.java:47)
at com.mongodb.FindIterableImpl.iterator(FindIterableImpl.java:135)
at com.hczd.logsys.Server.db.HZ_DBHandle.find(HZ_DBHandle.java:245)
at com.hczd.logsys.Server.quartz.HZ_StatisticQuartz.main(HZ_StatisticQuartz.java:293)
加载中
0
Gillian_Male
Gillian_Male
首先要看看能不能ping的通
0
kurumi
kurumi

引用来自“Gillian_Male”的评论

首先要看看能不能ping的通

还是找不到原因,用的复制集,可以连上主的(只提供主的ip和端口),但我要去从的查数据,可是就报上面的,连接从数据库的一直报错(从数据库的ip端口我并不知道),报错时的3个从库的ip端口都自动解析出来,连接超时

String username = mongo_user;
String password = mongo_pass;
String dbname = mongo_dbname;
List<MongoCredential> mcList = new ArrayList<MongoCredential>();
if(mcList.add(MongoCredential.createCredential(username, dbname,password.toCharArray()))){

MongoClientOptions.Builder builder = MongoClientOptions.builder();
builder.connectionsPerHost(50);  
builder.threadsAllowedToBlockForConnectionMultiplier(50);  
builder.maxWaitTime(1000*60*2);  
builder.readPreference(ReadPreference.primaryPreferred());
builder.connectTimeout(1000*60*1); 
MongoClientOptions mco = builder.build();
mongoClient = new MongoClient(addresses,mcList,mco);
db = mongoClient.getDatabase(dbname);

0
kurumi
kurumi
另外从库是内网的,并不能直接访问
0
m
mingxu
哥们 问题解决了吗  我遇到了你同样的问题 困扰我几天了 感谢
m
mingxu
回复 @chenyou : 复制集配置时写的是服务器内网IP JAVA程序测试时写的外网IP , 现以修改复制集也先用外网IP配置,问题已解决
c
chenyou
回复 @mingxu : 那怎么解决的啊?
m
mingxu
@chenyou 不行
c
chenyou
回复 @JerryYing : 我也遇到了,关掉防火墙就可以吗?
m
mingxu
回复 @JerryYing : 我单台的连接服务器都没有问题呀,不知道为什么用复制集的方式连接就有问题?
下一页
0
ChangeZ
ChangeZ

不知道你的原因,我是因为端口写错了,写成了27071

返回顶部
顶部