备库先扩,如果是主节点,先退位成备份节点吧.
这样都是在操作备库了.
1.关闭
[root@test3 ~]# systemctl stop mongod
2.单机模式启动
直接注释原有的参数文件更方便
#replication: 注释副本集配置参数
# replSetName: repltest1
port: 27018 改端口
[root@test3 ~]# systemctl start mongod
连接local库
mongo 127.0.0.1:27018/local
var cursor=db.oplog.rs.find({"op":"i"})
//op:"i"用于查找最后一条Insert操作
var lastInsert=cursor.sort({"$natural":-1}).limit(1).next()
db.tempLastOp.save(lastInsert)
//确保保存成功,这非常重要!
db.tempLastOp.findOne()
3.删除当前的oplog
> db.oplog.rs.drop()
true
4.创建新的oplog
例如2g
db.runCommand( { create: "oplog.rs", capped: true, size: (2 * 1024 * 1024 * 1024) } )
5.将tmp中的数据存储到新的oplog中,并验证:
var temp = db.tempLastOp.findOne()
db.oplog.rs.insert(temp)
确保写入成功
db.oplog.rs.findOne()
[root@test3 ~]# systemctl stop mongod
关闭节点,并恢复原有config配置,并在config中设置oplogSize为你之前设置的大小,并启动。
replication:
oplogSizeMB: 50//默认为磁盘的5%,指定oplog的最大尺寸。对于已经建立过oplog.rs的数据库,指定无效
[root@test3 ~]# systemctl start mongod 启动完成.更改完毕
检查
repltest1:SECONDARY> db.printReplicationInfo();
configured oplog size: 2048MB
log length start to end: 522611secs (145.17hrs)
oplog first event time: Tue Jul 24 2018 09:51:54 GMT+0800 (CST)
oplog last event time: Mon Jul 30 2018 11:02:05 GMT+0800 (CST)
now: Mon Jul 30 2018 11:02:07 GMT+0800 (CST)