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

本文详细介绍了MongoDB在遇到服务器断电、异常关闭或使用killall命令终止服务时如何通过从journal修复、从集群副本中修复或在再次启动时使用--repair或--repair加上--repairpath选项进行修复,确保数据的一致性和完整性。
摘要由CSDN通过智能技术生成

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

 

转载于:https://www.cnblogs.com/figo--fiona/p/3541436.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值