Nosql Mongodb之旅(23)—MongoDB Replica oplog

前端之家收集整理的这篇文章主要介绍了Nosql Mongodb之旅(23)—MongoDB Replica oplog前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

主从操作日志oplog

MongoDB的Replica Set架构是通过一个日志来存储写操作的,这个日志就叫做"oplog"。oplog.rs是一个固定长度的capped collection,它存在于"local"数据库中,用于记录Replica Sets操作日志。在默认情况下,对于64位的MongoDB,oplog是比较大的,可以达到5%的磁盘空间。oplog的大小是可以通过mongod的参数“--oplogSize”来设置。

  1. rs1:PRIMARY>uselocal
  2. switchedtodblocal
  3. rs1:PRIMARY>showcollections
  4. oplog.rs
  5. system.replset
  6. rs1:PRIMARY>db.oplog.rs.find()
  7. {"ts":{"t":1338457763000,"i":1},"h":NumberLong(0),"op":"n","ns":"","o":{"msg":
  8. "initiatingset"}}
  9. {"ts":{"t":1338459114000,"h":NumberLong("5493127699725549585"),"op":"i",
  10. "ns":"test.c1","o":{"_id":ObjectId("4fc743e9aea289af709ac6b5"),"age":29,"name":
  11. "Tony"}}
  12. rs1:PRIMARY>
字段说明

ts: 某个操作的时间戳
 op: 操作类型,如下:
 i: insert
 d: delete
 u: update
 ns: 命名空间,也就是操作的collection name
 o: document 的内容

查看master 的oplog 元数据信息:

  1. rs1:PRIMARY>db.printReplicationInfo()
  2. configuredoplogsize:47.6837158203125MB
  3. loglengthstarttoend:1351secs(0.38hrs)
  4. oplogfirsteventtime:ThuMay31201217:49:23GMT+0800(CST)
  5. oploglasteventtime:ThuMay31201218:11:54GMT+0800(CST)
  6. now:ThuMay31201218:21:58GMT+0800(CST)
  7. rs1:PRIMARY>
 configured oplog size: 配置的oplog 文件大小
 log length start to end: oplog 日志的启用时间段
 oplog first event time: 第一个事务日志的产生时间
 oplog last event time: 最后一个事务日志的产生时间

now: 现在的时间

查看slave 的同步状态

  1. rs1:PRIMARY>db.printSlaveReplicationInfo()
  2. source:localhost:28011
  3. syncedTo:ThuMay31201218:11:54GMT+0800(CST)
  4. =884secsago(0.25hrs)
  5. source:localhost:28012
  6. syncedTo:ThuMay31201218:11:54GMT+0800(CST)
  7. =884secsago(0.25hrs)
  8. rs1:PRIMARY>
字段说明

source: 从库的IP 及端口
 syncedTo: 目前的同步情况,延迟了多久等信息

主从配置信息

在local库中不仅有主从日志oplog集合,还有一个集合用于记录主从配置信息,即:system.replset

  1. rs1:PRIMARY>db.system.replset.find()
  2. {"_id":"rs1","version":1,"members":[
  3. {
  4. "_id":0,108); list-style:decimal-leading-zero outside; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "host":"localhost:28010"
  5. },108); list-style:decimal-leading-zero outside; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "_id":1,108); list-style:decimal-leading-zero outside; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "host":"localhost:28011"
  6. "_id":2,108); list-style:decimal-leading-zero outside; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "host":"localhost:28012"
  7. }
  8. ]}
  9. rs1:PRIMARY>
从这个集合中可以看出,Replica Sets 的配置信息,也可以在任何一个成员实例上执行rs.conf()来查看配置信息。 原文链接:https://www.f2er.com/nosql/204153.html

猜你在找的NoSQL相关文章