使用 Windows Server 在本地网络中公开 MongoDB 实例 [英] Expose MongoDB instance within the local network with Windows Server
问题描述
我在同一个网络中有两台计算机.其中之一是服务器,为可公开访问的网站提供服务;另一个是我日常使用的.
I have two computers within the same network. One of them is a server, which serves a publicly accessible website; the other one is for my daily use.
两台计算机都使用 Microsoft 技术.(Windows Server 2019/Windows 10)
Both computers are using Microsoft technologies. (Windows Server 2019/Windows 10)
我在服务器上运行了一个 MongoDB 实例,我想使用我的日常 PC 连接它.
但是,如果我尝试连接到 MongoDB 实例(mongodb://192.168.50.33:27017
,192.168.50.33
是服务器的本地 IP 地址PC,27017
是实例的端口),它总是超时使用
However, if I try to connect to the MongoDB instance (mongodb://192.168.50.33:27017
, 192.168.50.33
is the local IP address of the server PC, 27017
is the port for the instance), it always timeout using
- Google Chrome:如果连接正常,我应该会看到一条消息,内容为
您似乎正在尝试通过本机驱动程序端口上的 HTTP 访问 MongoDB.
. - MongoDB Compass:如果连接正常,我应该能够看到数据库中的内容.
我已经尝试/设置了以下内容:
I have tried/setup the following:
使用以下属性设置入站防火墙规则:
Setup an inbound firewall rule with the following properties:
- 允许连接
- 协议:
TCP
- 端口:
- 本地:
所有端口
- 远程:
27017
检查防火墙日志.看到我的日常 PC 的连接可以通过防火墙.
Checked the firewall log. Saw that the connection from my daily PC is allowed through the firewall.
在连接到我的两台计算机的路由器 (ASUS RT-AC58U) 上设置端口转发:
Set up a port forwarding on the router (ASUS RT-AC58U) which connects to both of my computers with the following properties:
- 端口范围:
27017
- 本地端口:
27017
- 本地IP:
192.168.50.33
设置MongoDB实例配置的
net.bindIp
为0.0.0.0
Set the
net.bindIp
of the configuration of the MongoDB instance to be0.0.0.0
有什么想法吗?
推荐答案
mongodb 配置文件中的bindIp 值也应该有你的服务器/局域网地址才能访问.
bindIp value in mongodb config file should have the address of your server/lan as well to access.
net.bindIp=0.0.0.0,192.168.50.33
net.bindIp=0.0.0.0,192.168.50.33
有关更多信息,您可以访问以下链接:https://mkyong.com/mongodb/mongodb-allow-remote-access/
for more info you can visit the below link: https://mkyong.com/mongodb/mongodb-allow-remote-access/
从以下链接下载应用程序,并检查您是否可以从 27017 ping 到 mongodb 服务器:https://www.elifulkerson.com/projects/tcping.php
Download the app from the below link and also check if you can ping to mongodb server from 27017: https://www.elifulkerson.com/projects/tcping.php
tcping.exe 192.168.50.33 27017
tcping.exe 192.168.50.33 27017
并使用mongo客户端检查是否可以连接,以下是命令:
And use mongo client to check if you can connect, below is the command:
mongo --host 192.168.50.33 --port 27017
mongo --host 192.168.50.33 --port 27017
如果这也没有帮助,请尝试使用以下命令启动 mongodb,然后尝试访问它们:
If this also does not help try starting the mongodb using the below commands and then try to access them:
mongod --bind_ip=192.168.50.33 --port=27017
mongod --bind_ip=192.168.50.33 --port=27017
mongod --bind_ip_all --port=27017(仅当 mongodb 为 3.6 或更高版本时有效)
mongod --bind_ip_all --port=27017 (works only if mongodb is 3.6 or greater)
让我知道发生了什么.
这篇关于使用 Windows Server 在本地网络中公开 MongoDB 实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 本地: