我在Windows 7上使用vagrant 1.6.2
来运行Ubuntu 12.04虚拟机。
我已在Vagrantfile
上启用此功能:
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.network :forwarded_port, guest: 27017, host: 27017, auto_correct: true
config.vm.network :forwarded_port, guest: 27018, host: 27018, auto_correct: true
config.vm.network :forwarded_port, guest: 9494, host: 9494
在框中,我可以看到Mongodb正在运行,
~ $ mongo
MongoDB shell version: 2.0.4
connecting to: test
> exit
bye
但是,从我的Windows主机,我无法使用localhost:27017
连接到Mongodb实例。
auto_correct: true
是我在其中一个论坛上阅读的内容,并尝试了它。
在vagrant up
上,这是我在控制台上得到的内容:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 3000 => 3000 (adapter 1)
default: 27017 => 27017 (adapter 1)
default: 27018 => 27018 (adapter 1)
default: 9494 => 9494 (adapter 1)
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
GuestAdditions 4.3.12 running --- OK.
如果我执行了rackup -p 3000
,我就可以点击http://localhost:3000
。端口9494也可以工作,只是Mongo端口无法正常工作。
我在我的主机(Windows)上安装了Mongo,我卸载了它,仍然是同样的问题。
任何提示?
答案 0 :(得分:3)
看来你的Vagrant端口转发工作正常。您的问题可能是因为MongoDB设置为仅侦听127.0.0.1。检查你的绑定设置。