How to create 2 nodes with backup, but without document balance

雨燕双飞 提交于 2019-12-11 03:01:48

问题


I have 2 couchbase nodes.

One should backup the other, but I do NOT want the server to balance the documents between them.

So I've tried to add them both to one cluster, and set replicas to "disable" on the bucket, but still it balance the documents between those 2 servers.

Then I've tried to use the servers as different clusters with replication between them. I've also added in the client config those two servers:

<servers bucket="default" bucketPassword="private">
    <add uri="http://server1ip/pools/default">
    <add uri="http://server2ip/pools/default">
</servers>

When I shut down server1, the requests went to server2, so the backup worked!

BUT i'm not sure if I'm sending a request from a client on server1, it will always choose the nearest server (sending the request always to server1ip).

How can I achieve that ?


回答1:


When you are creating a Couchbase cluster, this is viewed as a "single" database. The data are always distributed in the same cluster.

So if you want to "backup" automatically the data into other nodes, what you have to use is the the XDCR (Cross Data Center Replication) that will replicate the data from one cluster to another cluster. (as you can see I am not using the word, "node", since a Couchbase database should be deployed on multipe nodes.)

I am inviting you to look at the following resources to learn more about this:

  • Generic documentation on XDCR :
    http://www.couchbase.com/docs/couchbase-manual-2.1.0/couchbase-admin-tasks-xdcr.html
  • Webinar : http://info.couchbase.com/webinar-couchbase-server-and-XDCR.html



回答2:


I would think a load balancer would help. You could put a load balancer in front of the two couchbase servers and direct each of the clients to the load balancer. If the load balancer has the ability, it could determine the preferred server based on something (ip address?). if the preferred server isn't available, it could go to the other one.




回答3:


If you add 2 servers in your config, I'm not sure that couchbase choose nearest server, it could just use roundrobin. But I've noticed, that servers order in configuration affects their load, so maybe just first server will have higher priority, but not all requests will go to it. And I haven't seen any configuration options for .Net client to set one of the servers like "main" and other like "backup". So maybe you can try:

  1. Ask couchbase .net library developers on couchbase forums if there is some solution to set main and backup servers in configuration.
  2. To use HA Proxy as middleware that will choose proper running server. (as Don Dickinson suggested)
  3. Create two couchbase connections in your app (one for main server, one for backup: you'll need two config sections). If some operation fails on main server repeat request to backup. So your code will look like:

    var getResult = _ClientMain.ExecuteGet(key); if (!getResult.Sucess){ getResult = _ClientBackup.ExecuteGet(key); }

  4. Modify .Net clien library to satisfy your needs.



来源:https://stackoverflow.com/questions/18693180/how-to-create-2-nodes-with-backup-but-without-document-balance

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!