mongdb 非正常关闭导致的不能启动的解决方法

服务器断电、异常关闭以及直接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

  1. []# mongod --dbpath /mongodb/data --repair
  2. Thu Apr  4 00:08:07
  3. Thu Apr  4 00:08:07 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
  4. Thu Apr  4 00:08:07
  5. Thu Apr  4 00:08:07 [initandlisten] MongoDB starting : pid=23196 port=27017 dbpath=/mongodb/data 32-bit host=biao.oracle.com
  6. Thu Apr  4 00:08:07 [initandlisten]
  7. Thu Apr  4 00:08:07 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
  8. Thu Apr  4 00:08:07 [initandlisten] **       see [url]http://blog.mongodb.org/post/137788967/32-bit-limitations[/url]
  9. Thu Apr  4 00:08:07 [initandlisten] **       with --journal, the limit is lower
  10. Thu Apr  4 00:08:07 [initandlisten]
  11. Thu Apr  4 00:08:07 [initandlisten] db version v2.2.3, pdfile version 4.5
  12. Thu Apr  4 00:08:07 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
  13. 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
  14. Thu Apr  4 00:08:07 [initandlisten] options: { dbpath: "/mongodb/data", repair: true }
  15. 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"
  16. Thu Apr  4 00:08:07 [initandlisten] finished checking dbs
  17. Thu Apr  4 00:08:07 dbexit:
  18. Thu Apr  4 00:08:07 [initandlisten] shutdown: going to close listening sockets...
  19. Thu Apr  4 00:08:07 [initandlisten] shutdown: going to flush diaglog...
  20. Thu Apr  4 00:08:07 [initandlisten] shutdown: going to close sockets...
  21. Thu Apr  4 00:08:07 [initandlisten] shutdown: waiting for fs preallocator...
  22. Thu Apr  4 00:08:07 [initandlisten] shutdown: closing all files...
  23. Thu Apr  4 00:08:07 [initandlisten] closeAllFiles() finished
  24. Thu Apr  4 00:08:07 [initandlisten] shutdown: removing fs lock...
  25. Thu Apr  4 00:08:07 dbexit: really exiting now

再运行

[~]# mongod --dbpath /mongodb/data/

最后查看mongodb状态

 

posted @ 2014-02-09 14:34  figo361  阅读(1067)  评论(0编辑  收藏  举报