日期:2014-05-16  浏览次数:20593 次

MongoDB非正常关闭后修复记录

MongoDB非正常关闭后修复记录

mongod没有后台执行,在终端连接非正常断开后,再次执行mongod报错,如下所示:

[root@sunrise16 bin]# ./mongod
./mongod --help for help and startup options
Tue Oct 25 19:49:02
Tue Oct 25 19:49:02 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Oct 25 19:49:02
Tue Oct 25 19:49:02 [initandlisten] MongoDB starting : pid=13626 port=27017 dbpath=/data/db/ 32-bit host=sunrise16
Tue Oct 25 19:49:02 [initandlisten]
Tue Oct 25 19:49:02 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Tue Oct 25 19:49:02 [initandlisten] **?????? see http://blog.mongodb.org/post/137788967/32-bit-limitations
Tue Oct 25 19:49:02 [initandlisten] **?????? with --journal, the limit is lower
Tue Oct 25 19:49:02 [initandlisten]
Tue Oct 25 19:49:02 [initandlisten] db version v2.0.0, pdfile version 4.5
Tue Oct 25 19:49:02 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Tue Oct 25 19:49:02 [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_37
Tue Oct 25 19:49:02 [initandlisten] options: {}
**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
Tue Oct 25 19:49:02 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
Tue Oct 25 19:49:02 dbexit:
Tue Oct 25 19:49:02 [initandlisten] shutdown: going to close listening sockets...
Tue Oct 25 19:49:02 [initandlisten] shutdown: going to flush diaglog...
Tue Oct 25 19:49:02 [initandlisten] shutdown: going to close sockets...
Tue Oct 25 19:49:02 [initandlisten] shutdown: waiting for fs preallocator...
Tue Oct 25 19:49:02 [initandlisten] shutdown: closing all files...
Tue Oct 25 19:49:02 [initandlisten] closeAllFiles() finished
Tue Oct 25 19:49:02 dbexit: really exiting now

?

http://www.mongodb.org/display/DOCS/Durability+and+Repair#DurabilityandRepair-RepairCommand 写道
Repair Command

When not using journaling (--nojournal), after a machine crash or kill -9 termination, run the repairDatabase command. This command will check all data for corruption, remove any corruption found, and compact data files a bit. Repair is analogous to running fsck for a file system.

When journaling is enabled, it should not be necessary to run repair. However one could still use the repair command to compact a database.

From the command line:

mongod --repair

From the shell (you have to do for all dbs including local if you go this route):

> db.repairDatabase();

During a repair operation, mongod must store temporary files to disk. By default, mongod creates temporary directories under the dbpath for this purpose. Alternatively, the --repairpath command line option can be used to specify a base directory for temporary repair files.

Note that repair is a slow operation which inspects the entire database.

After running with --repair, mongod will start up normally.
?

现在执行修复。
[root@sunrise16 bin]# ./mongod --repair
Tue Oct 25 19:50:21
Tue Oct 25 19:50:21 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Oct 25 19:50:21
Tue Oct 25 19:50:21 [initandlisten] MongoDB starting : pid=14452 port=27017 dbpath=/data/db/ 32-bit host=sunrise16
Tue Oct 25 19:50:21 [initandlisten]
Tue Oct 25 19:50:21 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Tue O