Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

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:

enter image description here

like image 272
Alon Avatar asked Mar 14 '18 18:03

Alon


2 Answers

Alon,
Checkpoints

  1. 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.
  2. Port is allowed in security group attached to EC2 (You mentioned its done)
  3. Not using private IP to connect (I guess, you are using the right one as you connected through terminal)
  4. 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

like image 50
raevilman Avatar answered Oct 25 '22 15:10

raevilman


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.

like image 42
Bastian Avatar answered Oct 25 '22 14:10

Bastian