1

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.

SaAtomic
  • 619
  • 1
  • 12
  • 29
  • Try deleting /var/lib/mongodb/mongod.lock file and restart service. Then try connecting. – Abhay PS Dec 14 '16 at 11:42
  • The connection fails with the same error message after deleting the lock and restarting the service. – SaAtomic Dec 14 '16 at 12:02
  • Strange! Just to test, stop the service and run mongodb manually and then try to connect using 'mongo'. You can simply run 'mkdir -p /data/db && chown -R $USER:$USER /data/db && mongod'. After this open another shell and run 'mongo'. If this works then most probably, it has some permission problem. – Abhay PS Dec 14 '16 at 13:46
  • fails with the same error again. – SaAtomic Dec 14 '16 at 13:56
  • 1
    Do you have any firewall in place? Run 'iptables -L' – Abhay PS Dec 14 '16 at 13:58
  • This is a good point. Thanks for the hint - I'll check it out soon! – SaAtomic Dec 15 '16 at 09:34

3 Answers3

2

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

Community
  • 1
  • 1
Phillip Kigenyi
  • 1,359
  • 14
  • 21
  • I should have edited my post, I've resolved the issue. My firewall was blocking the local connection. Thanks for your input though! – SaAtomic Jan 10 '17 at 06:59
-1

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

Nadir Latif
  • 3,690
  • 1
  • 15
  • 24
  • The issue is that the connection to the shell isn't working. If I'm not mistaken, the link plainly suggests changing into the directory of the mongo executable and starting it. Which I do (as shown in OP) and fails to connect. – SaAtomic Dec 14 '16 at 11:24
  • Is the mongod daemon running?. What is the output of the command: "service mongod status" – Nadir Latif Dec 15 '16 at 03:10
  • Yes, it's running - `active (running)` – SaAtomic Dec 15 '16 at 08:36
  • Does the mongodb service show when you enter the netstat command?. You can check with this command: netstat -tulpn – Nadir Latif Dec 15 '16 at 09:49
  • Yes it does, as another user suggested, I need to check the firewall rules. – SaAtomic Dec 15 '16 at 10:23
-1

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!

Fad
  • 1