MongoDB on Vagrant via Port Forwarding issue

2019-02-14 23:53发布

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?

4条回答
Anthone
2楼-- · 2019-02-15 00:24

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.

查看更多
Animai°情兽
3楼-- · 2019-02-15 00:40

TCP port numbers are 16-bit unsigned, which mean the max value is 65535 (2^16), and you're trying with 127017.

查看更多
Evening l夕情丶
4楼-- · 2019-02-15 00:46

bind_ip to 0.0.0.0 does not work. Try bind_ip=127.0.0.1,10.0.0.25, that worked for me.

查看更多
对你真心纯属浪费
5楼-- · 2019-02-15 00:51

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.)

查看更多
登录 后发表回答