How to load balance/failover with pouchdb/couchdb?

送分小仙女□ 提交于 2019-12-24 00:36:30

问题


Just looking for info on what strategies people use for this?

In the examples I see it is really easy to make a remote database connection that I will call get() on.

var remoteDb = new PouchDB('https://myhost.com/db');
var data = remoteDb.get("myId");

But what if I have several remote databases set up that are syncing with each other. I want the clients to be able to use them all without changing the code.

I am considering doing this through dns. For example have db.myhost.com with multiple records pointing to the other servers. If I do this and one server goes down will pouchDB realize and reconnect to another?

Potentially I could write some javascript to give users a random server or assign a server based on region, etc. Then I could set up error handlers to switch servers on any errors. Is this necessary or is it already implemented in some library I could use?


回答1:


You can use nginx as a reverse proxy for that, as explained here: http://karmi.tumblr.com/post/247255194/simple-couchdb-multi-master-clustering-via-nginx

Basically you configure nginx to listen on one address and then pass the traffic to your CouchDB instances (adapted from the original post):

http {
  # ...
  upstream couchdb_cluster {
    server couchdb1.example.com:5984;
    server couchdb2.example.com:5984;
  }

  server {
    listen 80;
    server_name db.example.com;

    location / {
      proxy_pass http://couchdb_cluster;
      break;
    }

  }
  # ...
}


来源:https://stackoverflow.com/questions/33793240/how-to-load-balance-failover-with-pouchdb-couchdb

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