21.2主從操作日志oplogMongoDB的Replica Set架構(gòu)是通過一個(gè)日志來存儲(chǔ)寫操作的,這個(gè)日志就叫做”oplog”。 oplog.rs 是一個(gè)固定長(zhǎng)度的 capped collection,它存在于”local”數(shù)據(jù)庫(kù)中,用于記錄 Replica Sets 操作日志。在默認(rèn)情況下,對(duì)于64位的MongoDB,oplog是比較大的,可以達(dá)到5%的磁盤空間。oplog的大小是可以通過mongod的參數(shù)”—oplogSize”來改變oplog的日志大小。
Oplog內(nèi)容樣例:
rs1 RIMARY> use local switched to db local rs1 RIMARY> show collections oplog.rs system.replset rs1 RIMARY> db.oplog.rs.find() { "ts" : { "t" : 1338457763000, "i" : 1 }, "h" : NumberLong(0), "op" : "n", "ns" : "", "o" : { "msg" : "initiating set" } } { "ts" : { "t" : 1338459114000, "i" : 1 }, "h" : NumberLong("5493127699725549585" , "op" : "i", "ns" : "test.c1", "o" : { "_id" : ObjectId("4fc743e9aea289af709ac6b5" , "age" : 29, "name" : "Tony" } } rs1 RIMARY> |
字段說明:
l ts: 某個(gè)操作的時(shí)間戳
l op: 操作類型,如下:
u i: insert
u d: delete
u u: update
l ns: 命名空間,也就是操作的collectionname
l o: document的內(nèi)容
查看master的oplog元數(shù)據(jù)信息:
rs1 RIMARY> db.printReplicationInfo() configured oplog size: 47.6837158203125MB log length start to end: 1351secs (0.38hrs) oplog first event time: Thu May 31 2012 17:49:23 GMT+0800 (CST) oplog last event time: Thu May 31 2012 18:11:54 GMT+0800 (CST) now: Thu May 31 2012 18:21:58 GMT+0800 (CST) rs1 RIMARY> |
字段說明:
l configured oplog size: 配置的oplog文件大小
l log length start to end: oplog日志的啟用時(shí)間段
l oplog first event time: 第一個(gè)事務(wù)日志的產(chǎn)生時(shí)間
l oplog last event time: 最后一個(gè)事務(wù)日志的產(chǎn)生時(shí)間
l now: 現(xiàn)在的時(shí)間
查看slave的同步狀態(tài):
rs1 RIMARY> db.printSlaveReplicationInfo() source: localhost:28011 syncedTo: Thu May 31 2012 18:11:54 GMT+0800 (CST) = 884secs ago (0.25hrs) source: localhost:28012 syncedTo: Thu May 31 2012 18:11:54 GMT+0800 (CST) = 884secs ago (0.25hrs) rs1 RIMARY> |
字段說明:
l source: 從庫(kù)的IP及端口
l syncedTo: 目前的同步情況,延遲了多久等信息
免費(fèi)IT培訓(xùn)(ChinaDBA.net)實(shí)踐者!學(xué)費(fèi)1元,全捐公益
![]()