【问题标题】:how to connect to mongodb server via ssh tunnel with Proxy Jump (Bastion Host)如何使用代理跳转(堡垒主机)通过 ssh 隧道连接到 mongodb 服务器
【发布时间】:2021-08-17 05:07:06
【问题描述】:

我有一个像这样的 ssh 配置文件。 我有一个从 test2 到 host1 的代理跳转。

Host host1
  Hostname xxxxxx.us-east-1.elb.amazonaws.com
  Port 2222
  User xxxx
  IdentityFile ~/.ssh/cert
  StrictHostKeyChecking no
  UserKnownHostsFile /dev/null
  KeepAlive yes
  ServerAliveInterval 30
  ServerAliveCountMax 30

Host test2
  Hostname xx.xxx.xx.xxx
  ProxyCommand  ssh.exe host1  -q -W %h:%p host1
  User ubuntu
  IdentityFile ~/.ssh/cert
  KeepAlive yes
  StrictHostKeyChecking no
  UserKnownHostsFile /dev/null
  ServerAliveInterval 30
  ServerAliveCountMax 30

我的 mongo 数据库主机:xxx-nonprod.cluster-xx.us-east-1.docdb.amazonaws.com

我必须使用主机 test2 使用 SSH 隧道到 Mongodb,但它使用 ProxyCommand

使用代理跳转

我想通过 Mongo DB Compassnode js mongoose 使用 SSH 隧道连接到 mongodb。

如何使用 Mongo DB Compass 进行连接?

这里我没有输入ProxyCommand详细信息的选项。

如何使用 node js 进行连接?

我正在使用tunnel-ssh,我有一个参考代码,

var config = {
    username:'ubuntu',
    host:'xx.xxx.xx.xxx',
    agent : process.env.SSH_AUTH_SOCK,
    privateKey:require('fs').readFileSync('~/.ssh/cert'),
    port:22,
    dstPort:27017
};

var server = tunnel(config, function (error, server) {
  
});

我如何在此处输入 ProxyCommand 详细信息?或者请推荐任何可以解决这个问题的node js包。

【问题讨论】:

    标签: mongodb mongoose ssh-tunnel mongodb-compass bastion-host


    【解决方案1】:

    我现在可以连接到数据库了。

    1. 从终端通过堡垒到数据库建立隧道。

      ssh -L 27017:{mongodb-host}:27017 host1

    2. 我可以通过隧道从另一个终端的本地主机连接到数据库。

      mongo --host 127.0.0.1:27017 --username {username} --password {password}

    所以我也可以使用连接字符串通过猫鼬进行连接。 mongodb://dbadmin:{username}:{password}@localhost:27017

    【讨论】:

      猜你喜欢
      • 2020-06-04
      • 2018-12-19
      • 2018-07-16
      • 2020-07-24
      • 1970-01-01
      • 2019-11-19
      • 2019-11-12
      • 2020-09-30
      • 1970-01-01
      相关资源
      最近更新 更多