如何通过ssh隧道通过代理跳转(Bastion主机)连接到mongodb服务器

如何通过ssh隧道通过代理跳转(Bastion主机)连接到mongodb服务器,mongodb,mongoose,ssh-tunnel,mongodb-compass,bastion-host,Mongodb,Mongoose,Ssh Tunnel,Mongodb Compass,Bastion Host,我有一个像这样的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 Se

我有一个像这样的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 db主机:xxx nonprod.cluster xx.us-east-1.docdb.amazonaws.com

我必须使用SSH隧道通过主机test2连接到Mongodb,但它使用代理跳转通过ProxyCommand

我想使用SSH隧道连接到mongodb,使用mongodb Compass节点js mongoose

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

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

如何使用node js进行连接?

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

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包。

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

  • 建造一条隧道,穿过堡垒,从终点站进入数据库

    ssh-l27017:{mongodb主机}:27017主机1

  • 我能够通过隧道从另一个终端的本地主机连接到数据库

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

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