【问题标题】:How to connect from outside to MongoDB Atlas under VPC peering?VPC peering下如何从外部连接到MongoDB Atlas?
【发布时间】:2020-01-10 23:25:01
【问题描述】:

我有:

  1. MongoDB Atlas 集群

  2. GCP 之间的 VPC 对等。

当我尝试从家用笔记本电脑连接到数据库时:

mongo "mongodb+srv://hello-dev-x53pa.gcp.mongodb.net/test" --username myuser

我收到一个错误:

2020-01-09T15:32:33.697+0200 W NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Failed to connect to 192.168.240.4:27017 after 5000ms milliseconds, giving up.
2020-01-09T15:32:33.698+0200 W NETWORK  [thread1] Failed to connect to 192.168.240.2:27017 after 5000ms milliseconds, giving up.

我看到收到的本地 IP 地址,但我不明白如何连接到我在私有 VPC 中的数据库?

如果有任何帮助,我将非常高兴!

【问题讨论】:

    标签: mongodb google-cloud-platform


    【解决方案1】:

    您必须将您的 IP 地址列入白名单。 VPC Peering 允许 GCP 资源连接到您的数据库,但您还需要指定您的私有 IP 地址。

    请参考以下文档添加IP地址:

    https://docs.atlas.mongodb.com/security-whitelist/#add-whitelist-entries

    编辑: 我不会将所有 IP 地址列入白名单,只需使用“当前 IP 地址”选项将您的笔记本电脑尝试访问的 IP 地址列入白名单。

    另外,尝试添加--password 选项,因为这应该与--username 选项一起使用。另外,确认“test”数据库是您创建用户名/密码的位置。

    mongo "mongodb+srv://hello-dev-x53pa.gcp.mongodb.net/test" --username myuser --password mypassword
    

    【讨论】:

    • 它不起作用,因为我有私有 IP 地址。 BTW 在白名单中添加了 0.0.0.0/0
    • 我进行了编辑以反映您的评论。请让我知道这可不可以帮你。如果更新的答案没有帮助,我会删除它。
    • 我也尝试过这个解决方案,但它不起作用。我的假设是,我们添加到启用了 VPC 对等互连的项目的白名单中的 IP 地址仅适用于该网络内部的那些。事实上,在 Atlas 中为项目创建 VPC Peering 时,它会说“在 GCP 上启用 VPC Peering 意味着:来自对等 VPC 之外的公共 IP 的连接将无法访问专用的 MongoDB Atlas 集群。”
    猜你喜欢
    • 2021-12-20
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 2020-12-07
    • 2016-10-30
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多