简体   繁体   English

连接到远程 MongoDB 服务器时出现问题

[英]Having problem in connecting to remote MongoDB Server

I tried to connect a remote MongoDB Server running on Ubuntu using MongoDB Compass on Windows. But I have problems connecting always as the IP of the Windows machine changes every day.我尝试使用 Windows 上的 MongoDB Compass 连接运行在 Ubuntu 上的远程 MongoDB 服务器。但由于 Windows 机器的 IP 每天都在变化,所以我总是遇到连接问题。

I did the following things to connect to the remote server-我做了以下事情来连接到远程服务器 -

  1. Got the IP of the Client Machine, then allowed that IP on the firewall of the server machine on port 27017.获得客户端机器的 IP,然后在端口 27017 上的服务器机器的防火墙上允许 IP。
sudo ufw allow from client_machine_ip to any port 27017

Note: The ufw status looked okay.注意:ufw 状态看起来没问题。

  1. Got the IP of the Server Machine, then on the MongoDB configuration file on the server, I modified the bindIp.拿到Server Machine的IP,然后在server上的MongoDB配置文件上,我修改了bindIp。
bindIp: 127.0.0.1,server_machine_ip

Note: I restarted mongod and it was okay too.注:我重启了mongod也没有问题。

I was able to connect the remote MongoDB Server using MongoDB Compass successfully for the first time.我第一次成功使用 MongoDB Compass 连接到远程 MongoDB 服务器。 Then I saw, the IP of the client machine was changing every day.然后我看到,客户端机器的IP每天都在变。 So, every time, the client IP changes, I need to allow that IP on the firewall of the server machine (in which I am using the MongoDB Server) on port 27017. Could you help to solve this?因此,每次客户端 IP 更改时,我都需要在端口 27017 上的服务器机器(其中我使用 MongoDB 服务器)的防火墙上允许 IP。你能帮忙解决这个问题吗? Thanks in advance.提前致谢。

You can update the firewall for port 27017 to allow from anywhere since client machine IP is not static.您可以更新端口 27017 的防火墙以允许来自任何地方,因为客户端计算机 IP 不是 static。

sudo ufw allow 27017 #(this will allow from any IP)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM