我是mongoDB的新手并且喜欢它到目前为止,我在我的开发人员本地工作,我在Win7上运行mongo作为服务。我把它作为服务在Win服务器2008上的VPS上运行。当我在服务器上它工作正常但我不知道要设置它以便我可以从服务器外部访问它?找不到任何好的文档。此外,我很难从本地计算机上对服务器进行备份/恢复,因为我无法从服务器外部看到它。
我想在master / slave和hos上获得更多信息,以便正确设置它。
当我运行netstat -anb时,我得到了
TCP 127.0.0.1:27017 0.0.0.0:0 LISTENING
[mongod.exe]
TCP 127.0.0.1:27017 127.0.0.1:62990 ESTABLISHED
[mongod.exe]
TCP 127.0.0.1:28017 0.0.0.0:0 LISTENING
这就是我对mongod.exe所有的一切
[编辑]
我尝试使用--bind_ip xxx.x.x.xx重新安装,现在xxx.x.x.xx:27017只能在远程服务器上运行,如果我尝试从失败的任何地方进行访问。
另外,我关闭了防火墙并且它没有改变任何东西。
非常感谢!
答案 0 :(得分:12)
我想我找到了如何实现它。首先,允许防火墙上的端口27017。然后我使用配置文件将Mongo安装为服务。我像这样创建了mongos.conf:
dbpath = d:\mongo\data
logpath = d:\mongo\logs
noauth = true # use 'true' for options that don't take an argument
我把它保存在:d:\ mongo \ mongos.conf
然后我在命令行中执行了此操作:
mongod --config d:\mongo\mongos.conf --reinstall
关键是确保配置文件中没有bind_ip配置密钥。因此它允许将mongo绑定到任何ip。然后你应该可以去
http://localhost:27017并看到以下消息:
You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number
你也应该去:
http://192.168.x.x:27017(你的ip),你应该看到相同的输出。
答案 1 :(得分:3)
尝试从管理DOS提示符运行此命令以打开对默认MongoDB端口27017的外部访问:
C:\> netsh.exe advfirewall firewall add rule name="MongoDB (port 27017)"
dir=in action=allow protocol=TCP localport=27017
答案 2 :(得分:1)
如果您无法远程访问它,则听起来像防火墙问题。默认情况下,mongod侦听端口27017.是否可以从您尝试连接的计算机访问该端口?这听起来比mongod的问题更多或是防火墙问题。你可以编辑你的问题来设置mongo服务运行的命令行。
this article博客Kristina Chodorow's上有关副本集信息的良好来源。
答案 3 :(得分:0)
一些细节可以参考这篇文章 http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-install-mongodb-windows-server/
答案 4 :(得分:0)
对于MongoDb 4.x,我做了以下事情:
默认情况下,MongoDb已安装在Windows的C:\Program Files\MongoDB\Server\4.0\bin
上,并且包含名为mongod.cfg
的文件。
bindIp: 127.0.0.1
并添加主机IP bindIp: 127.0.0.1, 192.168.1.xxx
重新启动MongoDb服务,您应该能够从另一台计算机192.168.1.xxx:27017
访问它。
答案 5 :(得分:0)
在mongod.cfg(位于C:\ Program Files \ MongoDB \ Server \ 4.0 \ bin)中,只需更新:
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1
bindIp: 0.0.0.0
将mongo数据库设置为0.0.0.0,即所有接口,而不仅仅是127.0.0.1。 然后它将允许连接到所有接口。
答案 6 :(得分:0)
安装 mongo 和设置
安装 mongodb 并检查 Windows 服务
在防火墙中允许特定端口:27017
在 mongod.cfg(位于 C:\Program Files\MongoDB\Server\4.4\bin)中,只需注释 bindIp: 127.0.0.1 并添加新行 bindIp: 0.0.0.0:
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1
bindIp: 0.0.0.0
最后两步将允许您远程访问
创建用户
打开cmd进入安装路径,例如C:\Program Files\MongoDB\Server\4.4\bin
在cmd中输入mongo C:\Program Files\MongoDB\Server\4.4\bin>mongo
然后输入 use admin (admin 是数据库) 最后
db.createUser( { user: "adminName", pwd: "xxxxxx", roles: ["readWrite"] })
在服务中重启mongo服务