1

All of a sudden I can't get mongodb to work.

Usually I will start with

mongo

however I get this when trying to start.

MongoDB shell version: 3.0.6
connecting to: test
2016-10-11T15:36:56.462+0100 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-10-11T15:36:56.464+0100 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
    at connect (src/mongo/shell/mongo.js:179:14)
    at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed

I haven't updated anything on the server or even logged into it until the website broke. Any ideas why this is happening? I have tried to comment out the bind_ip but I don't get why it would just stop working and failing to start.

I have also tried

sudo service mongo start

mongod start/running, process 1529

Then when I tried -

sudo service mongod status

mongod stop/waiting. 

I can't start my nodejs app because it returns

 /node_modules/mongoose/node_modules/mongodb/lib/server.js:22‌​8 process.nextTick(function() { throw err; }) ^ Error: connect ECONNREFUSED at exports._errnoException (util.js:746:11) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)

I think that is because mongodb isn't starting correctly but not sure.

The error produces this

2016-10-11T15:40:30.400+0100 E JOURNAL  [initandlisten] Insufficient free space for journal files
2016-10-11T15:40:30.400+0100 I JOURNAL  [initandlisten] Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
2016-10-11T15:40:30.400+0100 I JOURNAL  [initandlisten]
2016-10-11T15:40:30.402+0100 I STORAGE  [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
2016-10-11T15:40:30.402+0100 I CONTROL  [initandlisten] now exiting
2016-10-11T15:40:30.402+0100 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2016-10-11T15:40:30.402+0100 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2016-10-11T15:40:30.402+0100 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2016-10-11T15:40:30.402+0100 I NETWORK  [initandlisten] shutdown: going to close sockets...
2016-10-11T15:40:30.402+0100 I STORAGE  [initandlisten] shutdown: waiting for fs preallocator...
2016-10-11T15:40:30.402+0100 I STORAGE  [initandlisten] shutdown: final commit...
2016-10-11T15:40:30.402+0100 I STORAGE  [initandlisten] shutdown: closing all files...
2016-10-11T15:40:30.402+0100 I STORAGE  [initandlisten] closeAllFiles() finished
2016-10-11T15:40:30.402+0100 I CONTROL  [initandlisten] dbexit:  rc: 100
2016-10-11T15:45:36.614+0100 I CONTROL  ***** SERVER RESTARTED *****
2016-10-11T15:45:36.642+0100 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-10-11T15:45:36.642+0100 I -        [initandlisten] Fatal Assertion 28578
2016-10-11T15:45:36.642+0100 I -        [initandlisten]

***aborting after fassert() failure


2016-10-11T15:46:21.636+0100 I CONTROL  ***** SERVER RESTARTED *****
2016-10-11T15:46:21.663+0100 E NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-10-11T15:46:21.663+0100 I -        [initandlisten] Fatal Assertion 28578
2016-10-11T15:46:21.663+0100 I -        [initandlisten]

I broswed to that dir and saw this!!! Why are those files so huge?

enter image description here

ServerSideSkittles
  • 2,713
  • 10
  • 34
  • 60
  • Is `mongod` running? `mongo` is just the CLI for interacting with a MongoDB instance. `mongod` is the actual service. – notion Oct 11 '16 at 14:42
  • sudo mongod gives me. 2016-10-11T15:43:07.025+0100 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating 2016-10-11T15:43:07.025+0100 I CONTROL [initandlisten] dbexit: rc: 100 – ServerSideSkittles Oct 11 '16 at 14:43
  • Are you on a debian based OS? If so, try `sudo service mongod start` – notion Oct 11 '16 at 14:44
  • Yes I am on ubuntu 14.04. I tried that cmd and got - mongod start/running, process 1529. then when I tried - sudo service mongod status - I got mongod stop/waiting. I can't start my nodejs app because it returns /node_modules/mongoose/node_modules/mongodb/lib/server.js:228 process.nextTick(function() { throw err; }) ^ Error: connect ECONNREFUSED at exports._errnoException (util.js:746:11) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19) – ServerSideSkittles Oct 11 '16 at 14:49
  • Is there anything in the log? (`/var/log/mongodb`) – notion Oct 11 '16 at 14:56
  • do you see anything in the /data/db directory? you may need to re-create that (assuming something removed it) and set the permissions on it. – Dave V Oct 11 '16 at 14:56
  • Ok in var log I get errors which are quite strange , ill paste them to my question. Also add image of directory with massive files!! – ServerSideSkittles Oct 11 '16 at 15:01

3 Answers3

2

It seems that your error is similar to this

Removing the /tmp/mongodb-27017.sock file should do the trick.

Also check your disk space, as it seems the process is not starting because you are missing space for the journal files (check @dave-v comment below)

Community
  • 1
  • 1
andresk
  • 2,845
  • 1
  • 13
  • 17
  • 1
    I would also look at adding more space for the journaling files and/or removing older ones. If you are using the MMAPv1 engine, a single journal file can take up to 1Gb of space, so they can grow quite large. If you don't need journaling you could always look at disabling it (not sure if this is a dev environment or prod) – Dave V Oct 11 '16 at 15:10
  • How do I delete those files? I have tried removing /tmp/mongodb-27017.sock but it keeps coming back and says no space. I have also added smallfiles=true to my config but nothing is happening – ServerSideSkittles Oct 11 '16 at 15:14
  • 1
    How much disk space do you have left? You can check it by using `df -h` – andresk Oct 11 '16 at 15:18
  • Yes it was a disk space issue! Thank you so much for everyone that has helped. I rebooted and now it works fine. I have 17gb of data somewhere on the system so I am going to hunt it out. I have also set mongo to log smaller files and now the nodejs app boots fine. – ServerSideSkittles Oct 11 '16 at 15:30
1

i open file /etc/mongodb.conf and put a # in begin of line bind_ip = 127.0.0.1 (#bind_ip = 127.0.0.1) .Then restart mongodb, it's work fine again !

Warning: If you use mongodb in online server, please don't do that. Hacker can attack for this port !

0

I faced same issue , solution is here

1) Once the mongo installation done by downloading or yum install 2) Create folder db under /home/scc-dev/data/db/ 3)Goto mongo folder under bin , open terminal run the below command sudo ./mongod dbpath /home/scc-dev/data/db 4)Check few lines command running in the console 5)open new terminal under bin run the below command sudo ./mongo 6) type command -> show dbs (it should show default dbs like local..) then it is working fine

7) if you get error like Failed to connect to 127.0.0.1:27017, reason: errno: 61 Connection refused then 8) restart the linux m/c command - > /sbin/reboot (do the steps from 3 - issue will be resolved )

To open the any ports in linux m/c sudo iptables -I INPUT -p tcp -m tcp --dport 27017 -j ACCEPT sudo iptables-save