Can't connect to MongoDB server on Google Compute Engine from second VM instance - mongodb

I have MongoDb installed on two Ubuntu 16 VMs both hosted on the same network on Google Cloud's Compute Engine. The connecting instance has Internal IP 10.132.0.2, the database instance has 10.132.0.3.
(https://gyazo.com/59f9086591a1d6673e8194a50fff51e1)
I've opened tcp 27017 for the instance I wish to connect to. I added this using the gcloud console commands.
(https://gyazo.com/0d158aa735c6967e278fac63d598721f)
I have also tried opening tcp:1-65535;udp:1-65535 for testing purposes, with no result.
Running mongo on either instance will properly connect to it's own mongodb service, so they're installed, running and working.
On the database instance, netstat -a | grep :27017 displays that it's listening correctly.
(https://gyazo.com/0f4fb3c49a51f6886ff4ccb2d44a132a)
On the database instance, the config file at /etc/mongod.conf of the is edited so bind_ip also has the Internal IP of said instance.
(https://gyazo.com/20fb669506e7e67ef49fdcf9af6df144)
I have also tried 0.0.0.0 for testing purposes, with no result.
Running mongo 10.132.0.3 from the connecting instance results in Failed to connect to 10.132.0.3:27017, reason: errno:111 Connection refused.
(https://gyazo.com/9e5aec732e3f09cbfa62a4d78df3620f)
Running nmap -p 27017 10.132.0.3 on the connecting instance shows port 27017 is closed.
(https://gyazo.com/7ccd905db5b9946d616176b9ab75479c)
I'm at an utter loss, please help me out? :<

Your mongodb servers are only listening on the localhost address (127.0.0.1), rather than on INADDR_ANY (shows up as *:27017 in netstat).
Like this question, it looks like you need to set bind_ip = 0.0.0.0 in your mongod.conf.

Thanks to E. Anderson's link I managed to solve this issue; suddenly turning this into a duplicate. However, neither this answer nor the answer in the link were "correct".
The solution to set bind_ip=0.0.0.0 in mongod.conf is rather dangerous, besides, it didn't work. However, killing the mongodb service, and then manually running mongod --bind_ip 10.132.0.3 actually allowed my two instances to connect.
Which.. means that javadude's reply in the other thread saying "But I still dont get it. Why this did not work when I modified mongo.conf file to accept bind_ip 0.0.0.0"` also goes for me. I don't get it, but, it definitely worked to manually give it an ip-address to listen on.

Related

MongoDB not running on the provided host and port

I tried to connect to my local mongodb server through compass but It throws me an error "MongoDB not running on the provided host and port", I tried to change the config file many times. I tried setting
"bindIpAll: true" , bindIp: my hostname(IPv4 Address), comment the line. Everything is a failure. Anybody help me with this.
Thanks in Advance.
Just go to task manager then click on services and search for MongoDB, right click on it and start the service.
This works for me.
Have you try port number after IP address 27017 followed by ":".
I had this issue when attempting to connect with mongoDB Compass to a mongoDB on an AWS Ubuntu Linux instance (Lightsail Service to be exact).
After reading lots of similar questions here and elsewhere (and having checked my firewall rules to allow port 27017 connections) I went to check the /etc/mongodb.conf file.
By default the bind_ip (at row 11 in my system) comes configured as 127.0.0.1, and that is fine to connect from the same machine. In this config entry you should put all the IP's that are listening for connections.
I tried to add my instance public IP just after a comma
bind_ip = 127.0.0.1,35.xx.xx.xx (where 35.xx.xx.xx was my public IP)
At this point the service didn't start anymore. I started the service manually while following the log (look under /var/log/mongodb) to read this error message:
2019-03-19T15:51:59.338+0000 [initandlisten] ERROR: listen(): bind() failed errno:99 Cannot assign requested address for socket: 35.xx.xx.xx:27017
So I tried with 0.0.0.0 as suggested on another site but it gave a similar error.
I solved this by putting my AWS instance private IP address in the config file:
bind_ip = 127.0.0.1,172.xx.xx.xx (where 172.xx.xx.xx is your PRIVATE IP)
Hope this helps!
I have stumbled with the same issue while using latest mongodb v:6.14.4, my solution is to open cmd and run 'mongo' this gives the path where the mongodb is running if already installed, copy the path from cmd and you can use as below in your node module:
const mongodb = "mongodb://127.0.0.1:27017/database-name";

Connect to EC2 via MongoDB Compass Community

I have an EC2 instance (Ubuntu 14). I've defined port 27017 in its security group to be accessed from anywhere.
I'm trying to connect from my PC (Windows 10) to the EC2 instance, but getting the following error:
MongoDB not running on the provided host and port
which is not true since I've made sure that MongoDB is running.
These were the settings I specified:
I've also tried to use SSH (which is also defined in the sercurity group and works well through terminal), but got the following error:
Error creating SSH Tunnel: (SSH) Channel open failure: Connection
refused
These were the settings I specified:
Alon,
Checkpoints
See if there is a need to change the bind_ip variable at the /etc/mongodb.conf file.
By default, it is locked to localhost.
Try setting the value to 0.0.0.0 or assign the IP that will be able to connect the DB to it.
Port is allowed in security group attached to EC2 (You mentioned its done)
Not using private IP to connect (I guess, you are using the right one as you connected through terminal)
Rare case, OS firewall
I guess point 1 should do the trick. Rest points for future reference
[Update 1]
Doc link for bindIp
https://docs.mongodb.com/manual/reference/configuration-options/#net-options
I am putting this as an answer although it is meant as a comment to the answer by raevilman above but I do not have the necessary reputation to post comments yet.
If you set the bind_ip variable to 0.0.0.0 as mentioned, MongoDB accepts connections from all IP addresses. This might be a security risk if you do not use access control.
On the other hand, if I am not wrong, the idea of a SSH tunnel is for that, in this case MongoDB, the entering connection comes from localhost so no change in the configuration should be necessary.
That said, I came here because I could not connect either. I got the error 'Error creating SSH Tunnel: Timed out while waiting for forwardOut'.
In my case the solution was to put 'localhost' in the hostname field at the top instead of the host IP.

Can't connect to Ubuntu MongoDB instance from MongoChef Client

All, new to MongoDB and new to Ubuntu. I have an Ubuntu VPS with MongoDB running. On my local machine, I'm trying to set-up MongoChef for my admin GUI. It creates the SSH tunnel successfully but then fails when connecting to my VPS on port 27017. I assumed it was a firewall on my VPS blocking traffic but using the ufw status command, I see the port is accepting traffic:
To Action From
-- ------ ----
Apache Full ALLOW Anywhere
27017 ALLOW Anywhere
Any ideas of what I can try next? I've also commented out the blockip line in my mongodb config file since that seems to have resolved the issue for others.
MongoChef Connection Error
enter image description here
Turns out my mongodb was not restarting properly after commenting the bind_ip. Had to work through multiple repair commands, start the service again, and issuing a netstat -a | grep "LISTEN " shows that port 27017 was now open to accept from any IP. MongoChef connected after that.

Can't connect my mongoDB database from my local machine

UPDATED:
I just start to deal with a new VPS and i am trying to connect its port 27017 (mongodb database) from localhost (using robomongo).
It's working on my localhost machine and with another remote server, but i can't connect mongodb on this VPS, what could cause this issue ?
I start it this way:
mongod --setParameter enableLocalhostAuthBypass=0 --config /etc/mongodb.conf --fork
with the auth = true uncommented in the /etc/mongodb.conf file (but it looks like the issue is not that i can't auth but mongodb is not responding at all).
When i start mongo admin -u root -p root by being connected with SSH, it works great (i can connect my database) and i can see that mongodb is well listenning on the port 27017.
But when i try to access it from my local machine, it can't establish the connection, and if i try to connect it with my browser, i am supposed to get a mongodb error message: You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number but i don't, i just have a failure page with Chrome (and the port 28017 is not responding either).
How to solve this ? My VPS is brand new and i could need to install more packages but i really don't see what could be need for this, it also looks like a firewall issue, like something prevent mongodb and response before the request could reach it, i have juste installed apache2 and nginx and they are not running so i really don't see...
Ok, I have found the issue!
There is a line bind_ip 127.0.0.1 in the /etc/mongod.conf file.
It provides access only to the specified IP address to mongodb.
You should create an array of IPs and edit the config file as:
bind_ip [127.0.0.1, x.x.x.x, ...]
Where x.x.x.x is your IP.
i resolved this issue with file(/etc/mongod.conf)
commenting out as follows:
#bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

MongoDB is not installed properly on Ubuntu 11.04 in Amazon EC2

I'm trying to install MongoDB on my Ubuntu 11.04 AMI in Amazon EC2.
I allowed 27017 port in security option.
The problem is that I can use "mongo OTHER IP ADDRESS" to access to other mongoDB.
But simply "mongo" does not simply give me access to localhost mongoDB.
mongoDB shell shows like it is about to work but it stops at
MongoDB shell version: 1.8.3
connecting to: test
If it is truly connected, it should give me ">" but it doesn't and freezes.
I couldn't find answer on freezing problem by googling myself.
Also any tips on running mongoDB as daemon or running in background?
Be sure to use 0.0.0.0 as the IP in the security group. This will include your public IP and localhost IP. If this is not the issue, try this for debugging.
See what interface or IP range mongo is listening on:
netstat -pan | grep mongod
I imagine that it's listening on your public IP address (OTHER IP ADDRESS as you call it). If this is the case, try starting mongod without bind_ip. If you didn't specify the bind_ip argument then it's probably something related to EC2.
Another test:
Try telnet localhost 27017 (hit Ctrl-], type quit to quit). This should also fail because this is the same thing the mongo client is doing.