Mongodb服务器无法启动

时间:2014-01-20 13:29:00

标签: django apache mongodb apache2

我正在使用Django frameowrk。我的客户位于js,后端正在使用mongodb。两天前我停下来重启了Apache2服务器,网站运行正常。今天网站突然显示500 Internel serve error。当我检查error.log文件时,它显示:

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

所以,我尝试通过mongodb测试与python的连接,如下所示:

>>> 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

我还使用$mongo测试了连接,并显示:

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

我尝试搜索此问题的答案,在那里我看到有人告诉我们删除mongod.lock文件并重新启动mongodb,例如此处Pymongo keeps refusing the connection at 27017MongoDB won't start after server crash但是这里写的是: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.我真的很困惑该怎么做?我应该删除mongod.lock文件吗?另外,首先需要启动mongodb服务器,然后启动apache2服务器吗? Mongodb日志文件显示:

   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

如果我运行以下命令,则会显示:

   $ sudo service mongodb start
     Starting database: mongodb failed!

1 个答案:

答案 0 :(得分:2)

嗯,错误信息非常明确:您没有足够的可用磁盘空间:

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

通常,MongoDB对磁盘空间相当贪婪。特别是,恢复和压缩使用相当多的磁盘,因为它复制了它处理的数据文件。确保你总是有一些演出。