服务器断电、异常关闭以及直接killall命令导致服务终止的情况都可能会被mondodb认为是unclean shutdown,
因为unclean
shutdown可能会导致数据不一致性或者数据损坏,所以必须要手动修复后才能继续提供服务。
mongodb修复unclean
shutdown的方式有:
1、从journal修复,journal就是类似于Oracle数据库中的redo log,工作机制也是类似的,都是write-ahead的。
2、从集群中其他节点的副本中修复。
3、如果服务不是运行在集群环境中,也没有启用journal,那必须在再次启动服务时使用--repair或者--repair加上--repairpath修复。
带与不带--repairpath的区别在于,来一段官方的解释
Use the --repair optionin conjunction with the
--repairpath option. mongod will read the existing datafiles, and write the
existing data to new data files. This does not modify oralter the existing data
files.
You do not need to removethe mongod.lock file before
using this procedure.
Use the --repair option.mongod will read the existing
data files, write the existing data to new filesand replace the existing,
possibly corrupt, files with new files.
You must remove themongod.lock file before using this
procedure.
执行修复,必须要指定dbpath
- []# mongod --dbpath /mongodb/data --repair
- Thu Apr 4 00:08:07
- Thu Apr 4 00:08:07 warning: 32-bit servers don‘t have
journaling enabled by default. Please use --journal if you want
durability.
- Thu Apr 4 00:08:07
- Thu Apr 4 00:08:07 [initandlisten] MongoDB starting : pid=23196
port=27017 dbpath=/mongodb/data 32-bit host=biao.oracle.com
- Thu Apr 4 00:08:07 [initandlisten]
- Thu Apr 4 00:08:07 [initandlisten] ** NOTE: when using MongoDB
32 bit, you are limited to about 2 gigabytes of data
- Thu Apr 4 00:08:07 [initandlisten] **
see [url]http://blog.mongodb.org/post/137788967/32-bit-limitations[/url]
- Thu Apr 4 00:08:07 [initandlisten] **
with --journal, the limit is lower
- Thu Apr 4 00:08:07 [initandlisten]
- Thu Apr 4 00:08:07 [initandlisten] db version v2.2.3, pdfile
version 4.5
- Thu Apr 4 00:08:07 [initandlisten] git version:
f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
- Thu Apr 4 00:08:07 [initandlisten] build info: Linux
bs-linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686
BOOST_LIB_VERSION=1_49
- Thu Apr 4 00:08:07 [initandlisten] options: { dbpath:
"/mongodb/data", repair: true }
- Thu Apr 4 00:08:07 [initandlisten] Unable to check for journal
files due to: boost::filesystem::basic_directory_iterator constructor: No such
file or directory: "/mongodb/data/journal"
- Thu Apr 4 00:08:07 [initandlisten] finished checking dbs
- Thu Apr 4 00:08:07 dbexit:
- Thu Apr 4 00:08:07 [initandlisten] shutdown: going to close
listening sockets...
- Thu Apr 4 00:08:07 [initandlisten] shutdown: going to flush
diaglog...
- Thu Apr 4 00:08:07 [initandlisten] shutdown: going to close
sockets...
- Thu Apr 4 00:08:07 [initandlisten] shutdown: waiting for fs
preallocator...
- Thu Apr 4 00:08:07 [initandlisten] shutdown: closing all
files...
- Thu Apr 4 00:08:07 [initandlisten] closeAllFiles()
finished
- Thu Apr 4 00:08:07 [initandlisten] shutdown: removing fs
lock...
- Thu Apr 4 00:08:07 dbexit: really exiting now
再运行
[~]# mongod --dbpath /mongodb/data/
最后查看mongodb状态
mongdb 非正常关闭导致的不能启动的解决方法
原文:http://www.cnblogs.com/figo--fiona/p/3541436.html