mongodb - 如何使用身份验证和 SSH 隧道连接到远程 MongoDB
问题描述
我正在尝试使用来自 ROBO3T 的以下凭据连接到远程 MongoDB,并且连接成功。
我正在尝试通过 .sh 文件(即 shell 脚本)复制相同的内容,但它不起作用。
1)这是我正在执行 frm mongo shell script 的命令,
mongo --username username --password password --authenticationDatabase admin --host ip-test --port 27017
但是我收到了 Socket Exception 和 COnnection Timed Out Exception 并且无法连接到远程 MongoDB。
2)所以,我在 mongo.cfg 文件中添加了以下 ip,
bindIp: ip-test,127.0.0.1,0.0.0.0
3)我也在windows主机文件中定义了ip-test。
4)在所有配置之后,我也尝试了以下命令,
mongo -u username -p password ip-test:27017/sample --authenticationDatabase admin
但仍然得到相同的套接字错误和连接超时。
5)然后我尝试在 mongo shell 命令本身中提供 ssh 隧道(配置),如下所示,
mongo ip-test:27017/sample -u username -p pasword -e 'SHOW DATABASES;' -h 127.0.0.1 | ssh -fN -l root -i "path for private key/id_rsa" -L 22:ip-test:27017 ip-test
这不是给出任何套接字异常,而是给出连接超时。
当我尝试独立于终端连接 ssh 时,它成功了。
但问题是我想将 mongo shell 命令与身份验证和 ssh 隧道结合在一个命令中。
谁能帮助我理解,如何通过 .SH 文件(Shell 脚本)通过身份验证和 SSH 配置连接到远程 MongoDB 服务器?
我对使用 shell 脚本的 ssh Tunneling 非常陌生,需要帮助。
非常感谢你。
解决方案
推荐阅读
- dagger-2 - dagger2 在哪里存储作用域实例?
- python - 运行 shell 脚本的 Django 命令
- visual-studio-code - 片段选择:显示一个值并用另一个值完成
- python - ImportError:无法导入名称 FlowReader
- python - 对 Pandas Groupby 中的每个组应用排名
- javascript - OnMouseOver/OnMouseOut 组合不可靠 - 究竟是什么导致了这种情况以及如何最好地解决它?
- postgresql - 来自 pg_stat_statements 的查询第一次出现的时间。有可能得到吗?
- ruby-on-rails - 在 ruby on rails 中,我怎样才能一一排队工作?
- haskell - Fix 和 Mu 同构
- sql-server - SSIS 目录包错误 - FlatFile 目标版本与 DataFlow 版本不兼容