Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

MongoDB bind_ip won't work unless set to 0.0.0.0

I really tried, even reinstall the MongoDB.

And it's the same to MongoDB bind_ip error: bind() failed errno:99 Cannot assign requested address for socket

It works if set bind_ip to: 0.0.0.0, or 127.0.0.1

$ sudo service mongod start
mongod start/running, process 30040
$ sudo service mongod restart
mongod stop/waiting
mongod start/running, process 29704
$ mongo --port 19708
MongoDB shell version: 3.0.3
connecting to: 127.0.0.1:19708/test
>

It won't work if set bing_ip to: 127.0.0.1,192.118.96.10,42.112.36.110

$ sudo service mongod start
mongod start/running, process 29969
$ sudo service mongod restart
stop: Unknown instance:
mongod start/running, process 29766
$ mongo --port 19708
MongoDB shell version: 3.0.3
connecting to: 127.0.0.1:19708/test
2015-06-17T06:32:34.625+0000 W NETWORK  Failed to connect to 127.0.0.1:19708
reason: errno:111 Connection refused
2015-06-17T06:32:34.627+0000 E QUERY
Error: couldn't connect to server   127.0.0.1:19708 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181
exception: connect failed

locations:

$ which mongod
/usr/bin/mongod
$ which mongo
/usr/bin/mongo

configurations in /etc/mongod.conf

dbpath=/var/lib/mongodb

logpath=/var/log/mongodb/mongod.log

logappend=true

port = 19708

# ips, eg:
# private ip for mongodb server: 192.118.96.10
# public ip for remote app server: 42.112.36.110

bind_ip = 127.0.0.1,192.118.96.10,42.112.36.110

auth = true

Thanks in advance.

question from:https://stackoverflow.com/questions/30884021/mongodb-bind-ip-wont-work-unless-set-to-0-0-0-0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Edit: I do not know wether I was simply wrong with my answer or if the behavior of bind_ip was changed, but it is possible to bind to multiple, distinct IPs

bind_ip:127.0.0.1,10.0.0.1,8.8.8.8

So, most likely, one of the IP addresses mongod was assigned to bind to did not exist on the machine in question.


You can bind mongod only to one IP, with 0.0.0.0 being the alias for "listen on all available network interfaces".

So either use

bind_ip=127.0.0.1

to listen to the loop back interface or

bind_ip=<someIP>

to listen to that IP only or

bind_ip=0.0.0.0

to listen to all available IPs on the system.

If you need to listen to several specific IPs, it is very likely that your system design is somehow screwed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...