Vagrant 上的 MongoDB 通过端口转发问题
我最近在 Vagrant 上运行的 CentOS 6 VM 上安装了 mongodb。
我向 Vagrantfile 添加了端口转发以转发 mongo 端口,
config.vm.forward_port 27017, 127017
我将 mongod 配置为在服务器启动时自动启动,并确认服务按预期启动。
但是,当我从我的主机(不是流浪者)运行 mongo localhost:127017 时,我收到以下错误
MongoDB shell version: 1.8.2
connecting to: localhost:127017/test
Fri Jan 20 13:58:28 getaddrinfo("127.0.0.1") failed: nodename nor servname provided, or not known
Fri Jan 20 13:58:28 Error shell/mongo.js:81
exception: connect failed
有什么想法吗?
I've recently installed mongodb on my CentOS 6 VM running on Vagrant.
I added port forwarding to Vagrantfile to forward the mongo port
config.vm.forward_port 27017, 127017
I configured mongod to start automatically when the server starts and have confirmed that the service starts as intended.
however when i run mongo localhost:127017
from my host machine (not vagrant) i get the following error
MongoDB shell version: 1.8.2
connecting to: localhost:127017/test
Fri Jan 20 13:58:28 getaddrinfo("127.0.0.1") failed: nodename nor servname provided, or not known
Fri Jan 20 13:58:28 Error shell/mongo.js:81
exception: connect failed
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要将 mongod bind_ip 设置为 0.0.0.0 而不是 127.0.0.1(环回地址),以便所有接口都可以访问它。
You will need to set the mongod bind_ip to 0.0.0.0 instead of 127.0.0.1 (which is the loopback address) so that all interfaces can access it.
TCP 端口号是 16 位无符号的,这意味着最大值是 65535 (2^16),而您正在尝试使用 127017。
TCP port numbers are 16-bit unsigned, which mean the max value is 65535 (2^16), and you're trying with 127017.
你能从 vagrant ssh 连接到 mongo 服务器吗?如果没有,您可能需要确保 mongod 正在运行。
您的 mongodb.conf 或 mongod 启动脚本中是否设置了
ip_bind
? (如果你这样做,你可能想取消它——不完全确定 vagrant 的端口转发是如何工作的,但这可能是导致问题的原因。)Can you connect to the mongo server from vagrant ssh? If not, you might want to make sure that mongod is running.
Do you have an
ip_bind
set up in your mongodb.conf or mongod startup script? (If you do, you might want to unset it--not exactly sure how vagrant's port forwarding works, but this might be what's causing the problem.)bind_ip to 0.0.0.0
不起作用。尝试bind_ip=127.0.0.1,10.0.0.25
,这对我有用。bind_ip to 0.0.0.0
does not work. Trybind_ip=127.0.0.1,10.0.0.25
, that worked for me.