我正在使用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