2012-10-11 52 views
4

後,我們的VPS了下來,我們啓動它,mongod的服務didnt自動啓動,我們不能service mongod start啓動它, 文件/var/log/mongo/mongod.log包含以下日誌:MongoDB的崩潰,意外關機

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


Thu Oct 11 13:51:18 
Thu Oct 11 13:51:18 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability. 
Thu Oct 11 13:51:18 
Thu Oct 11 13:51:18 [initandlisten] MongoDB starting : pid=3821 port=27017 dbpath=/var/lib/mongo 32-bit host=server2.paransa.org 
Thu Oct 11 13:51:18 [initandlisten] 
Thu Oct 11 13:51:18 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data 
Thu Oct 11 13:51:18 [initandlisten] **  see http://blog.mongodb.org/post/137788967/32-bit-limitations 
Thu Oct 11 13:51:18 [initandlisten] **  with --journal, the limit is lower 
Thu Oct 11 13:51:18 [initandlisten] 
Thu Oct 11 13:51:18 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!! 
Thu Oct 11 13:51:18 [initandlisten] 
Thu Oct 11 13:51:18 [initandlisten] db version v2.2.0, pdfile version 4.5 
Thu Oct 11 13:51:18 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207 
Thu Oct 11 13:51:18 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49 
Thu Oct 11 13:51:18 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidfilepath: "/var/run/mongodb/mongod.pid" } 
Thu Oct 11 13:51:18 [initandlisten] couldn't open /var/lib/mongo/mydb_main.ns errno:13 Permission denied 
Thu Oct 11 13:51:18 [initandlisten] error couldn't open file /var/lib/mongo/mydb_main.ns terminating 
Thu Oct 11 13:51:18 dbexit: 
Thu Oct 11 13:51:18 [initandlisten] shutdown: going to close listening sockets... 
Thu Oct 11 13:51:18 [initandlisten] shutdown: going to flush diaglog... 
Thu Oct 11 13:51:18 [initandlisten] shutdown: going to close sockets... 
Thu Oct 11 13:51:18 [initandlisten] shutdown: waiting for fs preallocator... 
Thu Oct 11 13:51:18 [initandlisten] shutdown: closing all files... 
Thu Oct 11 13:51:18 [initandlisten] closeAllFiles() finished 
Thu Oct 11 13:51:18 [initandlisten] shutdown: removing fs lock... 
Thu Oct 11 13:51:18 dbexit: really exiting now 

,你可能會看到,日誌說蒙戈服務器無法打開* .ns文件權限

的原因湖,但如果我用下面的命令運行服務器:

mongod --dbpath=/var/lib/mongo -f /etc/mongod.conf 

似乎一切都很好,並且對日誌文件:

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


Thu Oct 11 14:02:06 
Thu Oct 11 14:02:06 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability. 
Thu Oct 11 14:02:06 
Thu Oct 11 14:02:06 [initandlisten] MongoDB starting : pid=4090 port=27017 dbpath=/var/lib/mongo 32-bit host=server2.paransa.org 
Thu Oct 11 14:02:06 [initandlisten] 
Thu Oct 11 14:02:06 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data 
Thu Oct 11 14:02:06 [initandlisten] **  see http://blog.mongodb.org/post/137788967/32-bit-limitations 
Thu Oct 11 14:02:06 [initandlisten] **  with --journal, the limit is lower 
Thu Oct 11 14:02:06 [initandlisten] 
Thu Oct 11 14:02:06 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!! 
Thu Oct 11 14:02:06 [initandlisten] 
Thu Oct 11 14:02:06 [initandlisten] db version v2.2.0, pdfile version 4.5 
Thu Oct 11 14:02:06 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207 
Thu Oct 11 14:02:06 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49 
Thu Oct 11 14:02:06 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidfilepath: "/var/run/mongodb/mongod.pid" } 
Thu Oct 11 14:02:07 [websvr] admin web console waiting for connections on port 28017 
Thu Oct 11 14:02:07 [initandlisten] waiting for connections on port 27017 

,並使用--repair精氨酸沒有幫助 (也許是因爲它可以與mongod --dbpath=/var/lib/mongo -f /etc/mongod.conf手動啓動和增加--repair ARG的命令,記錄一切很好!)

有什麼建議嗎?

+1

可能嘗試檢查該鏈接 http://stackoverflow.com/questions/5798549/why-cant-i -start-the-mongodb?rq = 1 – Nilesh

+0

是運行mongod的用戶,擁有.ns的用戶是否一樣? –

+0

更改權限沒有工作,當我嘗試開始使用「服務mongod啓動」和「sudo !!」日誌說我不具備許可,但我可以通過上述命令手動啓動它。 我使用root用戶啓動mongod – user1737875

回答

16

這是一個權限問題,當您通過服務啓動時,您正在作爲mongod(或mongodb等)用戶運行,並且在使用sudo時很可能以根用戶身份運行(您在上面的註釋中進行確認)或作爲根進行調用。您需要修復該文件夾中所有文件的權限,而不是以超級用戶身份啓動該服務。

要根據您發佈的內容修復這些文件,假設您的相關用戶是mongodb並且該組是mongodb,那麼您應該使用sudo(或以root身份)執行以下操作 - 替換系統的相應用戶:

chown -R mongodb:mongodb /var/lib/mongo 
chown -R mongodb:mongodb /var/run/mongodb 
chown mongodb:mongodb /var/log/mongo/mongod.log 

修復這些文件夾的權限後,您應該可以再次通過服務啓動。注:如果您發佈的ls -al /var/lib/mongo輸出,然後我可以給你,你需要運行

+0

哦真的thx,對我來說工作正常,但使用「mongod」代替「mongodb」作爲用戶 – user1737875

+0

也爲我工作,我用scp將db複製到我的服務器上,我想我可能會破壞權限。因爲我只需要第一個命令 – Nath

2

嘗試刪除*.lock文件"\data\db"文件夾中的CMD開始mongod.exe前的確切命令。

4
sudo rm /data/db/mongod.lock 
sudo mongod --dbpath /data/db --repair 
sudo mongod --dbpath /data/db 
+0

我是這樣運行的;但是有兩個問題:第一,沒有辦法正確關閉它,你必須做一個ctrl-C,然後手動刪除鎖定文件,第二,它不會開始使用sudo服務mongodb start。它可能與mongodb.conf文件有關,但我嘗試禁用journalling,這似乎是默認設置的唯一選項,並且它不起作用。實際上,它甚至更加怪異,它可以和「-f/etc/mongodb一起工作。CONF」,但沒有與該服務的命令。它可能有做的新貴腳本的東西,但無法弄清。 – jjmerelo

+0

我做到了一次,然後我可以開始‘命令的mongod’,沒有必要刪除手動鎖定FYI:我在/etc/mongodb.conf中啓用了以下內容: dbpath =/var/lib/mongodb logpath =/var/log/mongodb/mongodb.log logappend = true –

2
Stop the MongoDB service 

須藤服務的MongoDB停止 刪除MongoDB的鎖定文件

sudo rm /var/lib/mongodb/mongod.lock 

Change ownership from root to the MongoDB path 

sudo chown -R mongodb:mongodb /var/lib/mongodb/ 

Access the mongodb Shell 

sudo mongod --dbpath=/var/lib/mongodb 

Start the MongoDB service 

sudo service mongodb start 
Test the mongo application 

mongo