我正在使用Django frameowrk
。我的客户端在js
,后端使用mongodb
。两天后,我停下来,重新启动Apache2
服务器,网站运行良好。今天突然网站显示500 Internel serve error
。当我检查了error.log
文件时,它显示:Mongodb服务器未启动
[.....] ConnectionError: Cannot connect to the database:
[.....] could not connect to localhost:27017: [Errno 111] Connection refused
所以,我试图测试通过python
这样的连接mongodb
:使用$mongo
>>> 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
我还测试了连接,它显示:
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
文件并重新启动像这里Pymongo keeps refusing the connection at 27017和MongoDB won't start after server crash mongodb但这里写道: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!
您的mongod看起来像停止了,如果再次启动它,该怎么办? – Sammaye
请看我更新的问题 - mongodb令人不快起步 – user2481422
您的更新只是显示退出,它不显示错误,您能告诉我们您在日志中遇到什么错误吗? – Sammaye