2014-01-20 172 views
2

我正在使用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 27017MongoDB 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! 
+0

您的mongod看起來像停止了,如果再次啓動它,該怎麼辦? – Sammaye

+0

請看我更新的問題 - mongodb令人不快起步 – user2481422

+0

您的更新只是顯示退出,它不顯示錯誤,您能告訴我們您在日誌中遇到什麼錯誤嗎? – Sammaye

回答

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相當貪婪的磁盤空間。特別是,恢復和壓縮使用相當多的磁盤,因爲它複製了它處理的數據文件。確保你總是有一些演出備用。

+0

是的,但如何在日誌目錄中釋放空間? – user2481422

+0

這主要是管理員問題。刪除在該分區中不再需要的數據,或者添加新的硬盤驅動器/分區並將其掛載到日誌目錄。對日誌使用不同的物理磁盤通常不是一個壞主意,因爲它具有不同的訪問模式。默認情況下,MongoDB也會更頻繁地使用這種設置提交給日誌(30ms而不是100ms) – mnemosyn