首页 文章

如何在rethinkdb代理中使用nginx负载均衡?

提问于
浏览
0

这个问题确实是从问题开始的,在进行研究时,我想出了针对多个rethinkdb代理的nginx balancer 的这个设置 .

我有3个rethinkdb代理服务器在运行 . 为了便于讨论,可以打电话给他们:

proxy0
proxy1
proxy2

然后将所有连接( - join)连接到rethinkdb集群中的第一个db . 现在我已经像这样定义了nginx上游:

upstream proxy {
    server proxy0:6003;      # rethindb proxy instance 0
    server proxy1:6003;      # rethinkdb proxy instance 1
    server proxy2:6003;      # rethinkdb proxy instance 2
}

然后只是代理传递 location /.

这一切看起来都很简单但不起作用 . 我得到这样的python错误:

File "isDead.py", line 86, in <module>
    o = DeadLinksDelete(db="db", db_host="loadBalancerAddress", api_url=url, page=sys.argv[2])
  File "isDead.py", line 22, in __init__
    password="pass")
  File "/usr/local/lib/python2.7/dist-packages/rethinkdb/net.py", line 656, in connect
    return conn.reconnect(timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/rethinkdb/net.py", line 567, in reconnect
    return self._instance.connect(timeout)
  File "/usr/local/lib/python2.7/dist-packages/rethinkdb/net.py", line 425, in connect
    self._socket = SocketWrapper(self, timeout)
  File "/usr/local/lib/python2.7/dist-packages/rethinkdb/net.py", line 325, in __init__
    raise ReqlDriverError(error)
rethinkdb.errors.ReqlDriverError: Connection is closed.

好吧,我的第一个问题是我假设rethinkdb驱动程序通过http / https连接到代理,并且从我的例子中假设是错误的 .

  • 从源代码安装nginx以支持--with-sream如下:

./configure --prefix = / opt / nginx --sbin-path = / usr / sbin / nginx --conf-path = / opt / nginx / nginx.conf --pid-path = / var / run / nginx .pid --lock-path = / var / run / nginx.lock --with-threads --with-stream --with-http_slice_module --without-http_rewrite_module

  • 编辑/opt/nginx/nginx.conf并添加(在http {}之后):

stream {server {listen 6003; proxy_pass db; } upstream db {server proxy0:6003; server proxy1:6003; server proxy2:6003; }}

  • 仅使用 nginx 启动nginx

  • 将您应用中的数据库主机设置为您的nginx负载均衡器,就是这样 .

这个设置现在适合我 .

1 回答

  • 0

    由于驱动程序不通过HTTP进行通信,因此最好使用HAProxy之类的东西,主要用于代理TCP连接 .

相关问题