2014-07-04 66 views
1

我正在嘗試Couchbase。我寫了一些代碼(在couchbase文檔的幫助下)。當我有服務器時,讀寫工作非常好。無法運行具有多個節點的couchbase羣集

當我把第2個服務器,我不能寫/或讀取...連接很長

我在做什麼錯了(它與1個服務器超快)?

該代碼顯然工作。當我在EC2上添加節點時,這是我做的事情?所有的港口都是開放的(向全世界)。當我加入集羣時,重新平衡就沒問題。

例子:我的羣集啓動並運行(在這裏與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代碼:

包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()); 
     } 
    } 
} 
+0

我正在使用企業版 –

回答

3

我懷疑你的客戶端無法連接到羣集節點返回的IP地址。 EC2通常具有公共和私人地址 - 您是否可以檢查您的應用服務器是否可以通過端口8091 & 11210連接到每個節點?

有關如何配置的詳細信息,請參閱http://docs.couchbase.com/couchbase-manual-2.5/cb-admin/index.html#using-couchbase-in-the-cloud - 如果將Couchbase節點配置爲使用主機名而不是IP地址,則通常會有更輕鬆的時間。

+0

好吧,我明白了。我會試試這個。謝謝 –

+0

謝謝,添加主機名幾乎工作的節點:第一個節點仍在使用其私有IP;我必須從集羣中刪除它,並再次將其與主機名 –

1

Dave是對的,看起來您正在連接公共IP,它將用於初始連接,但羣集正在響應羣集的私有IP地址空間,因此您無法連接到這些羣集。

只是爲了確認,您的客戶是AWS還是遠程本地?

此外,將您的數據庫直接連接到Internet通常是一種不好的做法。開放給世界讓我緊張,甚至聽到。您可能希望將公共端的Web /應用程序服務器與您的數據庫服務器完全私有,並使用Couchbase管理界面的Web代理服務器。更好的做法是將所有這些放在一個VPC中,使Couchbase位於私有子網中,並將您的Web /應用程序和代理放置在公共子網中。

另一件事。連接到羣集時,最好在連接字符串中有n + 1個節點,以防在應用程序啓動時其中一個節點處於關閉狀態。我看到你只有一個。

+0

重新添加,謝謝您的安全建議。我只是測試couchbase,所以如果couchbase適合我們,我不會有相同的網絡配置 –