3

I am using Django frameowrk. My client is in js and backend is using mongodb. Two days back I stopped and restarted the Apache2 server and the website was running fine. Today all of a sudden the website is showing 500 Internel serve error. When I checked the error.log file it is showing:

[.....] ConnectionError: Cannot connect to the database:
[.....] could not connect to localhost:27017: [Errno 111] Connection refused

So, I tried to test the connection to mongodb through python like this:

>>> from pymongo import Connection
>>> connection = Connection('localhost',27017)
 Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 381, in __init__
self.__find_node()
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 659, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: could not connect to localhost:27017: [Errno 111] Connection refused

I also tested the connection using $mongo and it shows:

MongoDB shell version: 2.4.9
connecting to: test
Mon Jan 20 15:22:53.729 Error: couldn't connect to server 127.0.0.1:27017 at    src/mongo/shell/mongo.js:145
exception: connect failed

I tried to search for answers to this problem and there I saw people are telling to delete the mongod.lock file and restart the mongodb like here Pymongo keeps refusing the connection at 27017 and MongoDB won't start after server crash but here it is written : http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/ In normal operation, you should never remove the mongod.lock file and start mongod. Instead consider the one of the above methods to recover the database and remove the lock files. In dire situations you can remove the lockfile, and start the database using the possibly corrupt files, and attempt to recover data from the database; however, it’s impossible to predict the state of the database in these situations. I am really confused on what to do? Should I remove the mongod.lock file or not? Also, do I first need to start the mongodbserver and then start the apache2server? Mongodb log file shows:

   tail -n -30 mongodb.log 

    ***** SERVER RESTARTED *****


   Mon Jan 20 15:10:19.740 [initandlisten] MongoDB starting : pid=8061 port=27017    dbpath=/var/lib/mongodb 64-bit host=hand
   Mon Jan 20 15:10:19.740 [initandlisten] db version v2.4.9
   Mon Jan 20 15:10:19.740 [initandlisten] git version:   xxxxx //gives the number
   Mon Jan 20 15:10:19.740 [initandlisten] build info:  xxxx 
   Mon Jan 20 15:10:19.740 [initandlisten] allocator: tcmalloc
   Mon Jan 20 15:10:19.740 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }
   Mon Jan 20 15:10:19.742 [initandlisten] journal dir=/var/lib/mongodb/journal
   Mon Jan 20 15:10:19.742 [initandlisten] recover : no journal files present, no recovery needed
   Mon Jan 20 15:10:19.742 [initandlisten] 
   Mon Jan 20 15:10:19.742 [initandlisten] ERROR: Insufficient free space for journal files
   Mon Jan 20 15:10:19.742 [initandlisten] Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
   Mon Jan 20 15:10:19.742 [initandlisten] 
   Mon Jan 20 15:10:19.743 [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
   Mon Jan 20 15:10:19.743 dbexit: 
   Mon Jan 20 15:10:19.743 [initandlisten] shutdown: going to close listening sockets...
   Mon Jan 20 15:10:19.743 [initandlisten] shutdown: going to flush diaglog...
   Mon Jan 20 15:10:19.743 [initandlisten] shutdown: going to close sockets...
   Mon Jan 20 15:10:19.743 [initandlisten] shutdown: waiting for fs preallocator...
   Mon Jan 20 15:10:19.743 [initandlisten] shutdown: lock for final commit...
   Mon Jan 20 15:10:19.743 [initandlisten] shutdown: final commit...
   Mon Jan 20 15:10:19.743 [initandlisten] shutdown: closing all files...
   Mon Jan 20 15:10:19.743 [initandlisten] closeAllFiles() finished
   Mon Jan 20 15:10:19.743 [initandlisten] journalCleanup...
   Mon Jan 20 15:10:19.743 [initandlisten] removeJournalFiles
   Mon Jan 20 15:10:19.743 [initandlisten] shutdown: removing fs lock...
   Mon Jan 20 15:10:19.743 dbexit: really exiting now

If I run the following command it shows:

   $ sudo service mongodb start
     Starting database: mongodb failed!
Community
  • 1
  • 1
user2481422
  • 868
  • 3
  • 17
  • 31

1 Answers1

2

Well, the error message is pretty clear: You don't have enough disk space available:

ERROR: Insufficient free space for journal files
   Please make at least 3379MB available in 
                                   /var/lib/mongodb/journal or use --smallfiles
   exception in initAndListen: 15926 Insufficient free space for journals, terminating

Generally, MongoDB is rather greedy with disk space. In particular, recovery and compaction uses quite a bit of disk because it copies the data files it processes. Make sure you always have a few gigs spare.

mnemosyn
  • 45,391
  • 6
  • 76
  • 82
  • Yeah but how to free space in journal directory? – user2481422 Jan 20 '14 at 13:46
  • That's mostly an admin problem. Either delete data that you no longer need in that partition, or add a new harddrive/partition and mount it to the journal directory. It's generally not a bad idea to use a different physical disk for the journal, because it has different access patterns. MongoDB will also, by default, commit to the journal more often with such a setup (30ms instead of 100ms) – mnemosyn Jan 20 '14 at 13:52