首页 文章

无法运行具有多个节点的couchbase群集

提问于
浏览
1

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

当我放第二台服务器时,我无法写/读...连接很长(1台服务器速度很快)

我究竟做错了什么 ?

代码显然正在运行 . 这是我在EC2上添加节点时要做的事情吗?所有港口都是开放的(对整个世界而言) . 当我加入群集时,重新 balancer 是可以的 .

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

这是我的日志:

连接:

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代码:

package 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());
        }
    }
}

2 回答

  • 1

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

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

  • 3

    Dave是对的,看起来你正在连接公共IP,它将用于初始连接,但是群集正在响应群集的私有IP地址空间,因此你无法连接到那些 .

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

    此外,将数据库直接连接到Internet通常是一种不好的做法 . 对世界开放只会让我感到紧张甚至听到 . 您希望将公共端的Web / app服务器和数据库服务器完全私有,并使用Couchbase管理界面的Web代理 . 更好的方法是将所有这些放在VPC中,Couchbase位于私有子网中,而您的Web / app和代理位于公共子网中 .

    另一件事 . 最佳做法是在连接到群集时在连接字符串中包含n个节点,以防其中一个节点在应用程序启动时关闭 . 我看到你只有一个是全部 .

相关问题