修改oplogsize导致无法启动mongodb
2016-06-07 00:30
519 查看
1.故障现象
mongodb数据库启用了master-slave,修改配置文件oplogsize后,mongodb无法启动
2.故障分析
查看mongod.log日志发现出现如下关键字:2016-06-06T23:03:16.752+0800 I REPL [initandlisten] cmdline oplogsize (2048) different than existing (990) see: http://dochub.mongodb.org/core/increase-oplog
看来是我们修改oplogsize的方法不对.我是直接在配置文件中修改然后重启mongodb的,日志中贴了具体的操作方法.
3.故障解决
根据日志中提供的链接,我们来看看如何正确的修改oplogsize的大小:http://dochub.mongodb.org/core/increase-oplog
Change the Size of the Oplog¶
On this pageOverview
Procedure
The oplog exists internally as a capped
collection, so you cannot modify its size in the course of normal operations. In most cases the default
oplog size is an acceptable size; however, in some situations you may need a larger or smaller oplog. For example, you might need to change the oplog size if your applications perform large numbers of multi-updates or deletes in short periods of time.
This tutorial describes how to resize the oplog. For a detailed explanation of oplog sizing, see Oplog
Size. For details how oplog size affects delayed members and affects replication
lag, see Delayed Replica Set Members.
Overview
To change the size of the oplog, you must perform maintenance on each member of the replica set in turn. The procedure requires: stopping the mongod instanceand starting as a standalone instance, modifying the oplog size, and restarting the member.
IMPORTANT
Always start rolling replica set maintenance with the secondaries, and finish with the maintenance on primary member.
Procedure
Restart the member in standalone mode.TIP
Always use rs.stepDown() to
force the primary to become a secondary, before stopping the server. This facilitates a more efficient election process.
Recreate the oplog with the new size and with an old oplog entry as a seed.
Restart the mongod instance
as a member of the replica set.
Restart a Secondary in Standalone Mode on a Different Port
Shut down the mongod instancefor one of the non-primary members of your replica set. For example, to shut down, use the db.shutdownServer() method:
db.shutdownServer()
Restart this mongod as
a standalone instance running on a different port and without the --replSet parameter. Use a command similar to the following:
mongod --port 37017 --dbpath /srv/mongodb
Create a Backup of the Oplog (Optional)
Optionally, backup the existing oplog on the standalone instance, as in the following example:mongodump --db local --collection 'oplog.rs' --port 37017
Recreate the Oplog with a New Size and a Seed Entry
Save the last entry from the oplog. For example, connect to the instance using the mongo shell,and enter the following command to switch to the local database:
use local
In mongo shell
scripts you can use the following operation to set the db object:
db = db.getSiblingDB('local')
Ensure that the temp temporary collection is empty by dropping the collection:
db.temp.drop()
Use the db.collection.save() method
and a sort on reverse natural order to find the last entry and save it to a temporary
collection:
db.temp.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() )
To see this oplog entry, use the following operation:
db.temp.find()
Remove the Existing Oplog Collection
Drop the old oplog.rs collection in the local database. Usethe following command:
db = db.getSiblingDB('local')db.oplog.rs.drop()
This returns true in the shell.
Create a New Oplog
Use the create commandto create a new oplog of a different size. Specify the size argument in bytes. A value of 2 * 1024 * 1024 * 1024 will
create a new oplog that’s 2 gigabytes:
db.runCommand( { create: "oplog.rs", capped: true, size: (2 * 1024 * 1024 * 1024) } )
Upon success, this command returns the following status:
{ "ok" : 1 }
Insert the Last Entry of the Old Oplog into the New Oplog
Insert the previously saved last entry from the old oplog into the new oplog. For example:db.oplog.rs.save( db.temp.findOne() )
To confirm the entry is in the new oplog, use the following operation:
db.oplog.rs.find()
Restart the Member
Restart the mongod asa member of the replica set on its usual port. For example:
db.shutdownServer()mongod --replSet rs0 --dbpath /srv/mongodb
The replica set member will recover and “catch up” before it is eligible for election to primary.
Repeat Process for all Members that may become Primary
Repeat this procedure for all members you want to change the size of the oplog. Repeat the procedure for the primary as part of the following step.Change the Size of the Oplog on the Primary
To finish the rolling maintenance operation, step down the primary with the rs.stepDown() methodand repeat the oplog resizing procedure above.
相关文章推荐
- mongodb master-slave主从复制
- linux 64位下的 mongodb 安装
- MongoDB for Java Programmer ——3
- mongodb单台安装
- mongoDB安装
- MongoCola使用教程 2 - MongoDB的Replset 初始化和配置
- MongoDB 可视化管理工具 MongoCola-1.1.0 测试版发布
- MongoCola使用教程 1 - MongoDB的基本操作和聚合功能---Mongdb客户端软件操作说明
- 安装mongodb
- linux下的Mongodb安装和使用python(linux自带)连接mongo
- MongoDB与MySQL的插入、查询性能测试
- MongoDB初识篇
- raft 分布式协议 -- mongodb
- MongoDB GridFS
- mongodb的导入导出、复制表
- MongoDB-3.2.6 副本集 和主从
- WEEK3-HOMEWORK
- mongodb 应用程序无法正常启动(0xc000007b)
- 玩转mongodb(六):索引,速度的引领(普通索引篇)
- MongoDB for Java Programmer ——2