如何使用pouchdb/couchdb进行负载平衡/故障转移? [英] How to load balance/failover with pouchdb/couchdb?

查看:101
本文介绍了如何使用pouchdb/couchdb进行负载平衡/故障转移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是在寻找有关人们为此采取何种策略的信息?

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

在示例中,我看到建立远程数据库连接非常容易,我将在该数据库上调用get().

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.

我正在考虑通过dns执行此操作.例如,让db.myhost.com包含指向其他服务器的多个记录.如果我这样做,并且一台服务器出现故障,pouchDB是否会意识到并重新连接到另一台服务器?

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?

可能我可以编写一些JavaScript来为用户提供随机服务器或根据区域分配服务器,等等.然后我可以设置错误处理程序以在发生任何错误时切换服务器.这是必需的还是已经在我可以使用的某些库中实现了?

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?

推荐答案

您可以使用nginx作为其反向代理,如此处所述:

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

基本上,您将nginx配置为侦听一个地址,然后将流量传递到您的CouchDB实例(改编自原始文章):

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;
    }

  }
  # ...
}

这篇关于如何使用pouchdb/couchdb进行负载平衡/故障转移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆