设为首页 收藏本站
查看: 1083|回复: 0

[经验分享] 关于mongodb 的Oplog

[复制链接]

尚未签到

发表于 2018-10-27 07:32:48 | 显示全部楼层 |阅读模式
转载于:http://www.huilog.com/?cat=17
关于mongodb 的Oplog
  发表回复
  mongodb的Replication是通过一个日志来存储写操作的,这个日志就叫做Oplog。
  在默认情况下,对于64位的mongodb,oplogs都相当大-可能是5%的磁盘空间。通常而言,这是一种合理的设置。可以通过mongod –oplogSize来改变Oplog的日志大小。
  Oplog的collectio为:
  local.oplog.$main for master/slave replication;
  local.oplog.rs for replica sets
  如 master/slave replication:
  > use local
  switched to db local
  > db.oplog.$main.help()
  DBCollection help
  db.oplog.$main.find().help() – show DBCursor help
  db.oplog.$main.count()
  db.oplog.$main.dataSize()
  db.oplog.$main.distinct( key ) – eg. db.oplog.$main.distinct( ‘x’ )
  db.oplog.$main.drop() drop the collection
  db.oplog.$main.dropIndex(name)
  db.oplog.$main.dropIndexes()
  db.oplog.$main.ensureIndex(keypattern,options) – options should be an object with these possible fields: name, unique, dropDups
  db.oplog.$main.reIndex()
  db.oplog.$main.find( [query] , [fields]) – first parameter is an optional query filter. second parameter is optional set of fields to return.
  e.g. db.oplog.$main.find( { x : 77 } , { name : 1 , x : 1 } )
  db.oplog.$main.find(…).count()
  db.oplog.$main.find(…).limit(n)
  db.oplog.$main.find(…).skip(n)
  db.oplog.$main.find(…).sort(…)
  db.oplog.$main.findOne([query])
  db.oplog.$main.findAndModify( { update : … , remove : bool [, query: {}, sort: {}, 'new': false] } )
  db.oplog.$main.getDB() get DB object associated with collection
  db.oplog.$main.getIndexes()
  db.oplog.$main.group( { key : …, initial: …, reduce : …[, cond: ...] } )
  db.oplog.$main.mapReduce( mapFunction , reduceFunction ,  )
  db.oplog.$main.remove(query)
  db.oplog.$main.renameCollection( newName ,  ) renames the collection.
  db.oplog.$main.runCommand( name ,  ) runs a db command with the given name where the first param is the collection name
  db.oplog.$main.save(obj)
  db.oplog.$main.stats()
  db.oplog.$main.storageSize() – includes free space allocated to this collection

  db.oplog.$main.totalIndexSize() –>  db.oplog.$main.totalSize() – storage allocated for all data and indexes
  db.oplog.$main.update(query, object[, upsert_bool, multi_bool])
  db.oplog.$main.validate() – SLOW
  db.oplog.$main.getShardVersion() – only for use with sharding
  > db.oplog.$main.find()
  { "ts" : { "t" : 1294582140000, "i" : 14 }, "op" : "d", "ns" : "mixi_top_city.building_90", "b" : true, "o" : { "_id" : "6380690_441_30_29" } }
  { "ts" : { "t" : 1294582140000, "i" : 15 }, "op" : "i", "ns" : "mixi_top_city.building_90", "o" : { "_id" : "6380690_441_24_24", "uid" : "6380690", "x" : 24, "y" : 24, "pos" : 1, "btime" : 1294154452, "ntime" : 1294154452, "bid" : 71, "extprop" : 0, "status" : 0, "ucid" : 441 } }
  { "ts" : { "t" : 1294582140000, "i" : 16 }, "op" : "u", "ns" : "mixi_top_city.building_64", "o2" : { "_id" : "16702364_459_14_14" }, "o" : { "$set" : { "status" : 1 } } }
  { "ts" : { "t" : 1294582140000, "i" : 17 }, "op" : "u", "ns" : "mixi_top_city.building_08", "o2" : { "_id" : "6223408_391_30_28" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
  { "ts" : { "t" : 1294582140000, "i" : 18 }, "op" : "u", "ns" : "mixi_top_city.building_03", "o2" : { "_id" : "9882403_353_28_20" }, "o" : { "$set" : { "ntime" : 1294600141 } } }
  { "ts" : { "t" : 1294582140000, "i" : 19 }, "op" : "u", "ns" : "mixi_top_city.building_24", "o2" : { "_id" : "4162924_365_32_28" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
  { "ts" : { "t" : 1294582141000, "i" : 1 }, "op" : "u", "ns" : "mixi_top_city.building_49", "o2" : { "_id" : "32797749_285_28_30" }, "o" : { "$set" : { "ntime" : 1294583341 } } }
  { "ts" : { "t" : 1294582141000, "i" : 2 }, "op" : "u", "ns" : "mixi_top_city.building_50", "o2" : { "_id" : "33768850_425_28_32" }, "o" : { "$set" : { "ntime" : 1294582561 } } }
  { "ts" : { "t" : 1294582141000, "i" : 3 }, "op" : "u", "ns" : "mixi_top_city.building_35", "o2" : { "_id" : "28235635_333_28_36" }, "o" : { "$set" : { "ntime" : 1294582741 } } }
  { "ts" : { "t" : 1294582141000, "i" : 4 }, "op" : "u", "ns" : "mixi_top_city.building_04", "o2" : { "_id" : "25178304_3_32_28" }, "o" : { "$set" : { "ntime" : 1294594141 } } }
  { "ts" : { "t" : 1294582141000, "i" : 5 }, "op" : "u", "ns" : "mixi_top_city.building_18", "o2" : { "_id" : "7304918_445_32_26" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
  { "ts" : { "t" : 1294582141000, "i" : 6 }, "op" : "u", "ns" : "mixi_top_city.building_93", "o2" : { "_id" : "5003293_453_20_24" }, "o" : { "$set" : { "status" : 1 } } }
  { "ts" : { "t" : 1294582141000, "i" : 7 }, "op" : "u", "ns" : "mixi_top_city.building_59", "o2" : { "_id" : "19601459_485_28_30" }, "o" : { "$set" : { "ntime" : 1294582741 } } }
  { "ts" : { "t" : 1294582141000, "i" : 8 }, "op" : "u", "ns" : "mixi_top_city.building_47", "o2" : { "_id" : "23744647_273_22_46" }, "o" : { "$set" : { "ntime" : 1294582741 } } }
  { "ts" : { "t" : 1294582141000, "i" : 9 }, "op" : "u", "ns" : "mixi_top_city.building_50", "o2" : { "_id" : "3549050_451_20_30" }, "o" : { "$set" : { "ntime" : 1294583041 } } }
  { "ts" : { "t" : 1294582141000, "i" : 10 }, "op" : "d", "ns" : "mixi_top_city.building_77", "b" : true, "o" : { "_id" : "8577977_215_44_38" } }
  { "ts" : { "t" : 1294582141000, "i" : 11 }, "op" : "i", "ns" : "mixi_top_city.building_77", "o" : { "_id" : "8577977_215_44_38", "uid" : "8577977", "x" : 44, "y" : 38, "pos" : 1, "btime" : 1293955498, "ntime" : 1294486420, "bid" : 18, "extprop" : 0, "status" : 0, "ucid" : 215 } }
  { "ts" : { "t" : 1294582141000, "i" : 12 }, "op" : "u", "ns" : "mixi_top_city.building_89", "o2" : { "_id" : "21405489_541_20_24" }, "o" : { "$set" : { "status" : 1 } } }
  { "ts" : { "t" : 1294582141000, "i" : 13 }, "op" : "u", "ns" : "mixi_top_city.building_60", "o2" : { "_id" : "6479060_395_16_32" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
  { "ts" : { "t" : 1294582141000, "i" : 14 }, "op" : "u", "ns" : "mixi_top_city.building_38", "o2" : { "_id" : "12696438_1037_28_40" }, "o" : { "$set" : { "ntime" : 1294583042 } } }
  has more
  >
  Oplog日志中:
  ts:Timestamp 这个操作的时间戳
  op:operation 操作
  i – insert
  d – delete
  u – update
  c – command
  n – no-op
  ns:Namespace也就是操作的collection name
  o:Document
  查看master的Oplog信息:
  [root@tc-03 cacti]# mongo
  MongoDB shell version: 1.6.4
  connecting to: test
  > db.printReplicationInfo();

  configured oplog>  log length start to end: 3566227secs (990.62hrs)
  oplog first event time:  Tue Jan 11 2011 12:17:03 GMT+0900 (KST)
  oplog last event time:   Mon Feb 21 2011 18:54:10 GMT+0900 (KST)
  now:                     Mon Feb 21 2011 18:54:10 GMT+0900 (KST)
  查看slave的同步状态:
  > db.printSlaveReplicationInfo()
  source:   192.168.8.173
  syncedTo: Mon Feb 21 2011 18:55:19 GMT+0900 (KST)
  = 31secs ago (0.01hrs)


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-626923-1-1.html 上篇帖子: mongodb一般操作 下篇帖子: 搭建高可用的MongoDB集群副本集
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表