標籤:mongodb
之前MongoDB啟動的時候是蠻正常的,不知道後來啟動報錯了,就把粘貼出來查詢了。最後才知道是由於自己不正常的關閉導致的這個情況。
--摘錄:MongoDB非正常關閉後修複記錄
mongod沒有後台執行,在終端串連非正常斷開後,再次執行mongod報錯,如下所示:
[[email protected] mongodb]# ./bin/mongod ./bin/mongod --help for help and startup options Thu Nov 17 22:42:49 Thu Nov 17 22:42:49 warning: 32-bit servers don‘t have journaling enabled by default. Please use --journal if you want durability. Thu Nov 17 22:42:49 Thu Nov 17 22:42:49 [initandlisten] MongoDB starting : pid=3257 port=27017 dbpath=/data/db/ 32-bit host=localhost Thu Nov 17 22:42:49 [initandlisten] Thu Nov 17 22:42:49 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data Thu Nov 17 22:42:49 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations Thu Nov 17 22:42:49 [initandlisten] ** with --journal, the limit is lower Thu Nov 17 22:42:49 [initandlisten] Thu Nov 17 22:42:49 [initandlisten] db version v2.0.1, pdfile version 4.5 Thu Nov 17 22:42:49 [initandlisten] git version: 3a5cf0e2134a830d38d2d1aae7e88cac31bdd684 Thu Nov 17 22:42:49 [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_41 Thu Nov 17 22:42:49 [initandlisten] options: {} ************** Unclean shutdown detected. Please visithttp://dochub.mongodb.org/core/repair for recovery instructions. ************* Thu Nov 17 22:42:49 [initandlisten] exception in initAndListen: 12596 old lock file, terminating Thu Nov 17 22:42:49 dbexit: Thu Nov 17 22:42:49 [initandlisten] shutdown: going to close listening sockets... Thu Nov 17 22:42:49 [initandlisten] shutdown: going to flush diaglog... Thu Nov 17 22:42:49 [initandlisten] shutdown: going to close sockets... Thu Nov 17 22:42:49 [initandlisten] shutdown: waiting for fs preallocator... Thu Nov 17 22:42:49 [initandlisten] shutdown: closing all files... Thu Nov 17 22:42:49 [initandlisten] closeAllFiles() finished Thu Nov 17 22:42:49 dbexit: really exiting now
修複方法:
這算是一個Mongod 啟動的一個常見錯誤,非法關閉的時候,lock 檔案沒有幹掉,第二次啟動的時候檢查到有lock 檔案的時候,就報這個錯誤了。
解決方案:進入 mongod 上一次啟動的時候指定的 data 目錄 --dbpath=/data/mongodb
刪除掉該檔案:
rm /data/mongodb/mongo.lock --linux
del /data/mongodb/mongo.lock --windows
再執行:
./mongod --repair
啟動:
/usr/local/src/mongodb-linux-x86_64-2.0.2/bin/mongod --port=27017 --pidfilepath=/var/run/mongod.pid --dbpath=/data/mongodb --directoryperdb --nojournal --noauth
OK,問題解決。
正確關閉mongod 的方法:進入mongo shell
use admin
db.shutdownServer()
也可以按照文檔粗暴的殺掉它,它內部應該有KILL訊號處理常式。
killall mongod
請不要 kill -9 ,會造成檔案資料混亂丟失 repair 也無力回天。
ctrl+c 可以退出mongo的介面 或是ext
mongodb啟動出現問題解決方案。