WritableServerSelector没有从群集中选择任何服务器 [英] No server chosen by WritableServerSelector from cluster

查看:1322
本文介绍了WritableServerSelector没有从群集中选择任何服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为MongoDB的新手,我试图将一个简单的文档插入到刚安装的mongoDB(v3.2.4)中.使用了MongoDB驱动程序3.2.2. 这是我最小化的代码:

As a newbie to MongoDB I'm trying to insert a simple document into my freshly installed mongoDB (v3.2.4). MongoDB Driver 3.2.2 is used. Here my minimized code:

public <classname>()
{
    public static final String COLLECTION_NAME = "logs";
    MongoClient mongoClient = new MongoClient("<server-adress>");
    MongoDatabase db = mongoClient.getDatabase("test");

    Document  data = new Document ();
    data.append(<whatever>);
    //...inserting more into document...
    db.getCollection(COLLECTION_NAME).insertOne(data); //collection should be created new

    mongoClient.close();
}

程序正在执行,但是在执行过程中出现以下错误(和信息):

The programm is executing, but I'm getting the following errors (and informations) during execution:

Mär 16, 2016 3:50:06 PM com.mongodb.diagnostics.logging.JULLogger log
INFORMATION: Cluster created with settings {hosts=[<server-adress>:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Mär 16, 2016 3:50:06 PM com.mongodb.diagnostics.logging.JULLogger log
INFORMATION: No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=<server-adress>:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
Mär 16, 2016 3:50:07 PM com.mongodb.diagnostics.logging.JULLogger log
INFORMATION: Exception in monitor thread while connecting to server <server-adress>: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:128)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
    (...) 
    at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
    at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
    ... 3 more

Error: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=<server-adress>:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]

文档也未插入.

当我用insertOne()命令注释该行时,它消失了.所以我认为连接不是问题,对吗?

When I'm commenting the line with the insertOne()-command, it disappears. So I assume it isnt' a problem with the connection, is that right?

我有一些想法:

  • 与异步有关吗?我会很惊讶,我无处不说不想同步执行它.
  • 是否缺少任何权限(由于此WritableServerSelector-问题)?
  • 它与测试"数据库有关吗?
  • MongoDB的独立模式是否存在问题? (我不想使用副本集.)
  • Does it has something to do with asynchronity? I'd be suprized, I said nowhere that I don't want to execute it synchronous.
  • Are any permissions missing (because of this WritableServerSelector-Thing)?
  • Does it has to do with the "test"-database?
  • Are there problems with the stand-alone-mode of MongoDB? (I don't want to use replicasets.)

但是对于所有这些想法,我都找不到真正的证据...

But for all these ideas I couldn't find real proofs...

(请改进标题,我没有更好的主意...)

(Please improve the question-title, I had no better idea...)

推荐答案

自行解决.

我还应该提到,我正在尝试从另一台机器连接到MongoDB实例. MongoDB预设不允许这样做.

I also should have mentioned, that I'm trying to connect from another machine to the MongoDB-instance. That is not allowed with the MongoDB-presets.

所以我不得不在/etc/mongod.conf文件中将bindIp后面的值从127.0.0.1更改为0.0.0.0.

So I had to change in the /etc/mongod.conf File the value behind bindIp from 127.0.0.1 to 0.0.0.0.

[来源]

这篇关于WritableServerSelector没有从群集中选择任何服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆