环境:
OS:Centos 7
db:4.4.22
1.查看当前的大小
myrepl:PRIMARY> db.getReplicationInfo() { "logSizeMB" : 10000, "usedMB" : 10013.92, "timeDiff" : 7801, "timeDiffHours" : 2.17, "tFirst" : "Fri Jul 14 2023 00:20:39 GMT-0400 (EDT)", "tLast" : "Fri Jul 14 2023 02:30:40 GMT-0400 (EDT)", "now" : "Fri Jul 14 2023 02:30:41 GMT-0400 (EDT)" }
或是
myrepl:PRIMARY> use local
switched to db local
myrepl:PRIMARY> db.oplog.rs.stats().maxSize
NumberLong("10485760000")
我这里的大小是10GB,下面调整为1GB
2.修改oplog.rs大小
执行顺序:从节点-->主节点
myrepl:SECONDARY> use local
myrepl:SECONDARY> db.adminCommand({replSetResizeOplog:1, size: 1024});
{ "ok" : 1 }
myrepl:PRIMARY> use local
myrepl:PRIMARY> db.adminCommand({replSetResizeOplog:1, size: 1024});
{ "ok" : 1 }
仲裁节点不需要执行.
3.回收空间
从库
myrepl:SECONDARY> use local
myrepl:SECONDARY> db.runCommand({ "compact" : "oplog.rs" })
主库:
myrepl:PRIMARY> use local
myrepl:PRIMARY> db.runCommand({ "compact" : "oplog.rs",force:true })
主库执行需要加上force:true参数
4.重启是否失效
关闭顺序:仲裁节点-->从节点-->主节点
/usr/local/services/mongodb/bin/mongo localhost:29001
use admin
db.auth("test","test123"); ##仲裁节点不需要
db.shutdownServer()
启动
启动顺序:主节点-->从节点-->仲裁节点
/usr/local/services/mongodb/bin/mongod -f /home/middle/mongodb/conf/mongo.cnf
查看是否失效
/usr/local/services/mongodb/bin/mongo localhost:29001 myrepl:PRIMARY> use admin myrepl:PRIMARY> db.auth("test","test123"); myrepl:PRIMARY> db.getReplicationInfo() { "logSizeMB" : 1024, "usedMB" : 997.76, "timeDiff" : 9542, "timeDiffHours" : 2.65, "tFirst" : "Fri Jul 14 2023 00:29:47 GMT-0400 (EDT)", "tLast" : "Fri Jul 14 2023 03:08:49 GMT-0400 (EDT)", "now" : "Fri Jul 14 2023 03:08:52 GMT-0400 (EDT)" }
说明重启后不会失效,依然是我们上面设置的值,这里不会读取配置文件里的oplogSize=10000(我的配置文件里的配置)
标签:在线,rs,db,PRIMARY,EDT,oplog,节点,myrepl From: https://www.cnblogs.com/hxlasky/p/17553798.html