164

rethinkdb远程访问方法

 6 years ago
source link: http://mp.weixin.qq.com/s/oMuLO-miKOkC3bo_k2lyRA
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

rethinkdb远程访问方法

写在最前面

从8月1日小孩出生到现在一直没有更新过公众号,希望接下来继续和大家分享我们K米的测试经验和自动化测试的技巧,给大家提供一些参考,我分享我快乐。

rethinkdb启动后只能本地访问http://localhost:8080,这里有一个可视化的页面,对于数据查看和调试是非常有用的,如果是本地调试没有任何问题,但是如果rethinkdb部署到服务器端,且服务器端是没有UI,只能通过ssh访问,rethinkdb没有开启远程访问服务,那该如何访问远程服务器本地的8080端口?

Image

这个问题纠结了很久,一开始考虑的方案是直接使用python命令行连接,实现如下:
清空表内容

import rethinkdb as r
r.connect(db='kmtestplatform').repl()
r.table('errorcode').delete().run()

根据ID更新数据

import rethinkdb as r
r.connect(db='kmtestplatform').repl()
r.table('errorcode').get(error_id).update(data).run()

根据ID删除数据

import rethinkdb as r
r.connect(db='kmtestplatform').repl()
r.table('testreport').get('348ce91a-2aef-4794-8283-50f27e7e0ac3').delete().run()

但是如果要查看具体数据库里面的具体内容是无法实现的。如果是本地调试的话,可以直接访问http://localhost:8080 进入UI页面,但是这个页面远程是无法访问的。

在远程服务器上添加一个代理,通过代理来转发本地8080端口的请求,实现如下:

  1. 安装nignx服务并启动;

  2. 在nginx配置目录/usr/local/nginx/conf/vhosts/里面添加一个配置文件rethinkdb.conf,详细如下:

upstream rethinkdb
{
server  127.0.0.1:8080;
}

server {
listen 8085;
server_name  localhost;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://rethinkdb;
}

access_log off;
}
  1. 接着就可以访问远程服务器8085的端口来实现访问远程服务器本地端口的8080了。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK