【问题标题】:can't run a couchbase cluster with more than one node无法运行具有多个节点的 couchbase 集群
【发布时间】:2014-07-04 15:39:56
【问题描述】:

我正在尝试 Couchbase。我写了一些代码(在 couchbase 文档的帮助下)。当我有 1 服务器时,读写工作非常好。

当我放置第二台服务器时,我无法写入/或读取...连接很长(使用 1 台服务器速度非常快)

我做错了什么?

代码显然可以正常工作。这是我在 EC2 上添加节点时要做的事情?所有端口都是开放的(对整个世界)。当我加入集群时,再平衡就可以了。

示例:我的集群已启动并正在运行(此处 EC2 上有 5 个节点):

这是我的日志:

连接:

2014-07-04 17:25:20.600 INFO net.spy.memcached.auth.AuthThread:  Authenticated to /54.247.158.182:11210
2014-07-04 17:25:20.811 INFO com.couchbase.client.vbucket.provider.BucketConfigurationProvider:  Could bootstrap through carrier publication.

写:

2014-07-04 17:25:20.817 INFO com.couchbase.client.CouchbaseConnection:  Added {QA sa=/10.57.35.15:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-07-04 17:25:20.818 INFO com.couchbase.client.CouchbaseConnection:  Added {QA sa=/10.250.110.205:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-07-04 17:25:20.818 INFO com.couchbase.client.CouchbaseConnection:  Added {QA sa=/10.250.153.230:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-07-04 17:25:20.819 INFO com.couchbase.client.CouchbaseConnection:  Added {QA sa=/10.59.13.200:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-07-04 17:25:20.819 INFO com.couchbase.client.CouchbaseConnection:  Added {QA sa=/10.65.51.132:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue

阅读:

2014-07-04 17:25:30.820 INFO com.couchbase.client.vbucket.provider.BucketConfigurationProvider:  Could bootstrap through carrier publication.
2014-07-04 17:25:45.847 INFO com.couchbase.client.CouchbaseClient:  CouchbaseConnectionFactory{bucket='Users', nodes=[http://54.247.158.182:8091/pools], order=RANDOM, opTimeout=2500, opQueue=16384, opQueueBlockTime=10000, obsPollInt=10, obsPollMax=500, obsTimeout=5000, viewConns=10, viewTimeout=75000, viewWorkers=1, configCheck=10, reconnectInt=1100, failureMode=Redistribute, hashAlgo=NATIVE_HASH, authWaitTime=2500}
Connected to CouchbaseConnectionFactory{bucket='Users', nodes=[http://54.247.158.182:8091/pools], order=RANDOM, opTimeout=2500, opQueue=16384, opQueueBlockTime=10000, obsPollInt=10, obsPollMax=500, obsTimeout=5000, viewConns=10, viewTimeout=75000, viewWorkers=1, configCheck=10, reconnectInt=1100, failureMode=Redistribute, hashAlgo=NATIVE_HASH, authWaitTime=2500}
2014-07-04 17:26:10.908 INFO com.couchbase.client.CouchbaseClient:  viewmode property isn't defined. Setting viewmode to production mode
2014-07-04 17:26:10.989 INFO com.couchbase.client.CouchbaseConnection:  Node for key "user101" is not active (yet). Queueing up for retry and checking for stale configuration.
2014-07-04 17:26:11.362 INFO com.couchbase.client.CouchbaseConnection:  Node for key "user101" is not active (yet). Queueing up for retry and checking for stale configuration.
2014-07-04 17:26:12.363 INFO com.couchbase.client.CouchbaseConnection:  Node for key "user101" is not active (yet). Queueing up for retry and checking for stale configuration.
2014-07-04 17:26:13.365 INFO com.couchbase.client.CouchbaseConnection:  Node for key "user101" is not active (yet). Queueing up for retry and checking for stale configuration.
2014-07-04 17:26:13.490 WARN net.spy.memcached.MemcachedConnection:  handling node for operation is not set
java.lang.RuntimeException: Timed out waiting for operation
    at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:142)
    at com.t2s.injector.Injector.insertData(Injector.java:71)
    at com.t2s.injector.Injector.main(Injector.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: <unknown>
    at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:167)
    at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:140)
    ... 7 more
2014-07-04 17:27:27.995 INFO com.couchbase.client.CouchbaseConnection:  Reconnecting due to failure to connect to {QA sa=10.250.110.205/10.250.110.205:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connexion terminée par expiration du délai d'attente
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:735)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:677)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:436)
    at com.couchbase.client.CouchbaseConnection.run(CouchbaseConnection.java:324)
java.lang.RuntimeException: Timed out waiting for operation
    at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:75)
    at com.couchbase.client.CouchbaseClient.getView(CouchbaseClient.java:430)
    at com.t2s.injector.Injector.queryView(Injector.java:85)
    at com.t2s.injector.Injector.main(Injector.java:33)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.util.concurrent.TimeoutException: Timed out waiting for operation
    at com.couchbase.client.internal.HttpFuture.waitForAndCheckOperation(HttpFuture.java:93)
    at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:82)
    at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:72)
    ... 8 more
2014-07-04 17:27:53.249 WARN com.couchbase.client.CouchbaseConnection:  Closing, and reopening {QA sa=10.250.110.205/10.250.110.205:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}, attempt 1.
2014-07-04 17:27:53.249 INFO com.couchbase.client.CouchbaseConnection:  Reconnecting due to failure to connect to {QA sa=10.250.153.230/10.250.153.230:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connexion terminée par expiration du délai d'attente
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:735)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:677)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:436)
    at com.couchbase.client.CouchbaseConnection.run(CouchbaseConnection.java:324)
2014-07-04 17:28:08.534 INFO com.couchbase.client.ViewConnection:  I/O reactor terminated

java代码:

包 com.t2s.injector;

import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.protocol.views.Query;
import com.couchbase.client.protocol.views.View;
import com.couchbase.client.protocol.views.ViewResponse;
import com.couchbase.client.protocol.views.ViewRow;
import com.google.gson.Gson;
import com.t2s.injector.data.User;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class Injector {

    public static void main(String[] args) throws Exception {
        System.out.println("Starting...");
        try {
            CouchbaseClient client = createClient("Users", "54.247.158.182");//, "54.74.200.186");

            try {
                insertData(client);
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                queryView(client, "users", "by_firstname");
            } catch (Exception e) {
                e.printStackTrace();
            }

            // Shutting down properly
            client.shutdown(5, TimeUnit.SECONDS);
            System.exit(0);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    private static CouchbaseClient createClient(String bucket, String... ips) throws URISyntaxException, IOException {
        // (Subset) of nodes in the cluster to establish a connection
        Integer port = 8091;
        List<URI> nodes = new ArrayList<>();
        for (String ip : ips) {
            nodes.add(new URI("http://" + ip + ":" + port + "/pools"));
        }

        // Password of the bucket (empty) string if none
        String password = "";

        // Connect to the Cluster
        CouchbaseClient client = new CouchbaseClient(nodes, bucket, password);
        System.out.println("Connected to " + client);
        return client;
    }

    private static void insertData(CouchbaseClient client) throws InterruptedException, ExecutionException {
        Gson gson = new Gson();

        User user1 = new User("John", "Doe");
        User user2 = new User("Matt", "Ingenthron");
        User user3 = new User("Michael", "Nitschinger");

        client.set("user101", gson.toJson(user1)).get();
        client.set("user201", gson.toJson(user2)).get();
        client.set("user301", gson.toJson(user3)).get();
    }

    private static void queryView(CouchbaseClient client, String designDoc, String viewName) {
        /*
        function (doc, meta) {
          if(doc.firstname) {
            emit(doc.firstname, doc.lastname);
          }
        }
         */
        // 1: Load the View infos
        View view = client.getView(designDoc, viewName);

        // 2: Create a Query object to customize the Query
        Query query = new Query();
        query.setIncludeDocs(true); // Include the full document body

        // 3: Actually Query the View and return the results
        ViewResponse response = client.query(view, query);

        // 4: Iterate over the Data and print out the full document
        for (ViewRow row : response) {
            System.out.println(row.getId() + ": " + row.getDocument());
        }
    }
}

【问题讨论】:

  • 我用的是企业版

标签: amazon-ec2 couchbase


【解决方案1】:

我怀疑您的客户端无法连接到集群节点返回的 IP 地址。 EC2 通常有一个公共和私有地址 - 你能检查你的应用服务器是否可以在端口 8091 和 11210 上连接到每个节点?

有关如何配置的详细信息,请参阅 http://docs.couchbase.com/couchbase-manual-2.5/cb-admin/index.html#using-couchbase-in-the-cloud - 如果您将 Couchbase 节点配置为使用主机名而不是 IP 地址,您通常会更轻松。

【讨论】:

  • 谢谢,添加带有主机名的节点几乎成功了:第一个节点仍在使用它的私有 IP;我不得不将它从集群中删除并使用它的主机名再次添加它
【解决方案2】:

Dave 是对的,您似乎正在使用公共 IP 进行连接,这将适用于初始连接,但集群正在使用集群的私有 IP 地址空间进行响应,因此您可能无法连接到那些。

只是为了确认一下,您的客户端是在 AWS 本地还是远程?

另外,将数据库直接连接到 Internet 通常是一种不好的做法。向世界开放只是让我听到就紧张。您希望将您的 Web/应用程序服务器放在公共端,而您的 db 服务器则非常私密,并且可能有一个连接到 Couchbase 管理界面的 Web 代理。更好的办法是将所有这些都放在一个 VPC 中,Couchbase 位于私有子网中,而您的 Web/应用程序和代理位于公共子网中。

另一件事。连接到集群时,最好在连接字符串中包含 n+1 个节点,以防应用启动时其中一个节点出现故障。我看到你只有一个。

【讨论】:

  • 感谢您的安全建议。我只是对 couchbase 进行基准测试,所以如果 couchbase 适合我们,我将不会有相同的网络配置
猜你喜欢
  • 2016-02-01
  • 1970-01-01
  • 2013-12-29
  • 2019-09-28
  • 2013-10-16
  • 2023-01-31
  • 2011-08-13
  • 1970-01-01
  • 2016-06-26
相关资源
最近更新 更多