mongo exception: connect failed on a fresh install

2.8k views Asked by At

I've installed mongodb for the very first time on my Debian 8, following this mongodb install guide. The goal is to use mongodb for rocket.chat, for which I follow this guide.

So far, all I did was:

$sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
$echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

$sudo apt-get update
$sudo apt-get install mongodb-org

$sudo systemctl enable mongod
$sudo vi /etc/mongod.conf
<insert>    
replication:                                                               
   oplogSizeMB: 1                                                          
   replSetName: rs0

$sudo systemctl restart mongod
$export LC_ALL=C
$sudo mongo

MongoDB shell version v3.4.0
connecting to: mongodb://127.0.0.1:27017
2016-12-14T10:21:55.356+0100 W NETWORK  [main] Failed to connect to 127.0.0.1:27017 after 5000 milliseconds, giving up.
2016-12-14T10:21:55.356+0100 E QUERY    [main] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:234:13
@(connect):1:6
exception: connect failed

I'm monitoring the log file, when attempting to access the mongo shell, but nothing shows up.

The mongod service is running, configured to listen on 127.0.0.1 and I'm working on the server locally.

How do I access the mongo shell from the localhost?

edit Solved. The issue was an iptables rule, that disallowed local connections to the mongodb.

3

There are 3 answers

1
Phillip Kigenyi On

Run the following command :

sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart

Credit: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused

0
Fad On

To recover from an unclean shutdown run these in a terminal

killall mongod
cd ~
./mongod --repair
rm -rfv data/mongod.lock
./mongod

If you want to remove the --httpinterface warning then run, try this :

echo 'mongod --bind_ip=$IP --dbpath=data --nojournal --rest --httpinterface "$@"' > mongod

(it only needs running once) before you run

./mongod

I hope this helps. Cheers!

5
Nadir Latif On

You can access the mongodb shell by changing directory to your MongoDb installation and entering ./bin/mongo. See this guide: enter link description here