目录方法一方法二方法三1.关闭monGod2.修改配置文件3.启动mongod实例,并备份oplog4.重建oplog5.插入前面保存的oplog时间点记录6.关闭mongod实例方
修改oplog有四种方法:
步骤如下:
优点:操作简单。
缺点:需要停服务,若数据量大,数据同步代价高。
步骤如下:
优点:解决了方法一中的停机问题。
缺点:每个节点都要逐个重新同步,时间代价更高。
The oplog exists internally as a capped collection, so you cannot modify its size in the course of nORMal operations.另:改变oplog大小,需要在每个节点上执行维护模式。(官方推荐)
关闭mongod实例,如果是primary节点,执行rs.stepDown() 降级
handong1:PRIMARY> rs.stepDown()
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1619693040, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1619693040, 1)
}
handong1:SECONDARY>
handong1:SECONDARY>
handong1:SECONDARY>
handong1:SECONDARY> use admin
switched to db admin
handong1:SECONDARY> db.shutdownServer()
2021-04-29T18:44:33.947+0800 I NETWORK [js] DBClientConnection failed to receive message from 127.0.0.1:27017 - HostUnreachable: Connection closed by peer
server should be down...
2021-04-29T18:44:33.950+0800 I NETWORK [js] trying reconnect to 127.0.0.1:27017 failed
2021-04-29T18:44:33.967+0800 I NETWORK [js] reconnect 127.0.0.1:27017 failed failed
修改配置文件,修改端口,注释掉replSet和认证相关的设置
port=27018
fork=true
journal = true
maxConns=500
logappend=true
directoryperdb=true
dbpath=/mongoDB/data
logpath=/mongodb/logs/mongodb.log
mongod -f /mongodb/conf/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 31553
child process started successfully, parent exiting
mongodump -d local -c oplog.rs --port 27018 -h 172.16.254.134 -o /mongodb/backup
2021-04-29T18:55:18.167+0800 writing local.oplog.rs to /mongodb/backup/local/oplog.rs.bson
2021-04-29T18:55:18.170+0800 done dumping local.oplog.rs (798 documents)
保存oplog最新时间点
> use local
switched to db local
> db.temp.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() )
WriteResult({ "nInserted" : 1 })
> db.temp.find()
{ "_id" : ObjectId("608a914089abaa981f14e888"), "ts" : Timestamp(1619693066, 1), "h" : NumberLong(0) }
删除旧的oplog
db.oplog.rs.drop()
重建新的oplog,大小为2GB
> db.runCommand( { create: "oplog.rs", capped: true, size: (2 * 1024 * 1024 * 1024) } )
> db.oplog.rs.save( db.temp.findOne() )
> db.oplog.rs.find()
> use admin
switched to db admin
> db.shutdownServer()
2021-04-29T19:06:53.745+0800 I NETWORK [js] DBClientConnection failed to receive message from 127.0.0.1:27018 - HostUnreachable: Connection closed by peer
server should be down...
2021-04-29T19:06:53.749+0800 I NETWORK [js] trying reconnect to 127.0.0.1:27018 failed
2021-04-29T19:06:53.749+0800 I NETWORK [js] reconnect 127.0.0.1:27018 failed failed
最后恢复mongodb.conf到初始状态,启动
如果你的MongoDB版本为4.0以后的版本,可以直接使用replSetResizeOplog修改。
handong1:SECONDARY> db.getReplicationInfo()
{
"logSizeMB" : 1000,
"usedMB" : 0.17,
"timeDiff" : 6736,
"timeDiffHours" : 1.87,
"tFirst" : "Thu Apr 29 2021 17:19:14 GMT+0800 (CST)",
"tLast" : "Thu Apr 29 2021 19:11:30 GMT+0800 (CST)",
"now" : "Thu Apr 29 2021 19:11:42 GMT+0800 (CST)"
}
handong1:SECONDARY> db.adminCommand({replSetResizeOplog:1,size:2000})
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1619694744, 14),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1619694744, 14)
}
handong1:SECONDARY> db.getReplicationInfo()
{
"logSizeMB" : 2000,
"usedMB" : 0.18,
"timeDiff" : 6852,
"timeDiffHours" : 1.9,
"tFirst" : "Thu Apr 29 2021 17:19:14 GMT+0800 (CST)",
"tLast" : "Thu Apr 29 2021 19:13:26 GMT+0800 (CST)",
"now" : "Thu Apr 29 2021 19:13:28 GMT+0800 (CST)"
}
handong1:SECONDARY> use local
switched to db local
handong1:SECONDARY> db.runCommand({"compact" : "oplog.rs"})
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1619694840, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1619694840, 1)
}
到此这篇关于分享MongoDB修改oplog大小的4种方法的文章就介绍到这了,更多相关MongoDB修改oplog大小内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: 分享MongoDB修改oplog大小的4种方法
本文链接: https://lsjlt.com/news/145507.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0