我正在尝试从本地计算机连接到运行mongodb实例的虚拟机,我认为这应该类似于在单独的远程服务器上运行时的生产环境。
环境如下:
- 虚拟机的私有IP: 192.168.184.155 - 本地计算机和虚拟机的公共IP:96.88.169.145
我更改了/etc/mongod.conf文件中的bind_ip。
bind_ip = 127.0.0.1
to
bind_ip = 127.0.0.1,192.168.184.155,96.88.169.145
在我重新启动mongod服务后,无论是虚拟机还是本地机器都无法通过mongodb命令访问mongodb,并给出以下错误。
MongoDB shell version: 3.0.1
connecting to: test
2015-03-17T16:02:22.705-0400 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-03-17T16:02:22.707-0400 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
然而,如果我改变
bind_ip = 192.168.184.155
重新启动服务后,我可以从本地机器上使用mongo进行访问。但是在多个IP地址上似乎无法正常工作。我尝试在mongodb文档中查找信息,但它们提到的bind_ip参数需要使用逗号分隔的列表,这让我很困惑。
非常感谢您的帮助。
bindIpAll: true
。当您有一台具有多个网络接口的机器时,使用带有IP地址的bindIp
是有用的,否则在我看来它没有太多意义。例外情况是bindIp: localhost
,当您想要防止任何外部连接时,通常在维护工作期间使用。 - Wernfried Domscheit