Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB on an AWS instance, reason: errno:61 Connection refused

Mongo version 3.2

I set up MongoDB on an instance at AWS.

I then added it to the security group, as an exception for the firewall. Specifically, I set this up as a Customer TCP rule, with an exception for port 27017.

If I ssh to the instance and do:

  netstat -pl

I can see in the output:

tcp 0 0 localhost:27017 : LISTEN 2025/mongod

So mongodb is running, it is is listening on port 27017, and an exception for 27017 was added to the firewall.

But on my local Mac, when I try to connect, I get an error:

  mongo ec2-154-52-32-196.compute-1.amazonaws.com:27017/vvvvv -u ccccc -p xxxx

  MongoDB shell version: 3.2.6
  connecting to: ec2-54-152-232-96.compute-1.amazonaws.com:27017/vvvvv
  2016-05-06T09:52:07.281-0400 W NETWORK  [thread1] Failed to connect to 54.152.232.96:27017, reason: errno:61       Connection refused
  2016-05-06T09:52:07.281-0400 E QUERY    [thread1] Error: couldn't connect to server       ec2-54-152-232-96.compute-1.amazonaws.com:27017, connection attempt failed :
  connect@src/mongo/shell/mongo.js:231:14
  @(connect):1:6

  exception: connect failed

What else do I need to do to connect?

[[ UPDATE ]]

So I:

  emacs /etc/mongod.conf 

and I add 0.0.0.0:

  net:
    port: 27017
    bindIp: 127.0.0.1,0.0.0.0

and then:

  service mongod restart
  mongod stop/waiting
  mongod start/running, process 5315

but I still get the same error as before

Hmmmm, I no longer see it in netstat -pl

like image 595
lorm Avatar asked May 06 '16 14:05

lorm


3 Answers

I modified in /etc/mongod.conf

# network interfaces
    net:
      port: 27017
#  bindIp: 127.0.0.1  
      bindIp: 0.0.0.0`

Then,

sudo service mongod restart


sudo netstat -utpl | grep mongo

And check if: 0.0.0.0:27017 appear,

like image 91
Omar Hernandez Avatar answered Nov 14 '22 18:11

Omar Hernandez


From the netstat output: tcp 0 0 localhost:27017 : LISTEN 2025/mongod - Looks like it is accepting connections only from localhost(samehost) - You have to make it run on 0.0.0.0 or the Public IP.

like image 23
RaviTezu Avatar answered Nov 14 '22 17:11

RaviTezu


Check in /etc/mongod.conf

# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip=127.0.0.1

Comment that line and reload the service. It should work.

like image 30
juanmhidalgo Avatar answered Nov 14 '22 18:11

juanmhidalgo