The replica set schema of MongoDB is a log to store write operations, and this log is called Oplog. Oplog.rs is a fixed-length Capped Collection that exists in the local database and is used to log replicasets operations. By default, for 64-bit mongodb,oplog is relatively large, can reach 5% of the disk space, the size of Oplog can be mongod parameter "-oplogsize" to change the Oplog log size.
Oplog Sample content:
> Use Local
> Show Collections
> Db.oplog.rs.find ()
The new version has a problem, can no longer be as direct as the old version of the operation, you must first add an administrator user, then switch to the administrator identity, and then to operate, see the log.
Rs1:primary> Show Dbsshow DBS
2016-07-22t17:44:25.491+0800 E QUERY [thread1] error:listdatabases failed:{
"OK": 0,
"ErrMsg": "Not authorized in Admin to execute command {listdatabases:1.0}",
"Code": 13
} :
[Email protected]/mongo/shell/utils.js:25:13
[Email protected]/mongo/shell/mongo.js:62:1
[Email protected]/mongo/shell/utils.js:761:19
[Email protected]/mongo/shell/utils.js:651:15
@ (SHELLHELP2): 1:1
rs1:primary> Use Localuse Local
Switched to DB Local
Rs1:primary> Show Collectionsshow Collections
2016-07-22t17:44:40.317+0800 E QUERY [Thread1] Error:listcollections failed: {
"OK": 0,
"ErrMsg": "Not authorized on local to execute command {listcollections:1.0, filter: {}}",
"Code": 13
} :
[Email protected]/mongo/shell/utils.js:25:13
[Email protected]/mongo/shell/db.js:773:1
[Email protected]/mongo/shell/db.js:785:19
[Email protected]/mongo/shell/db.js:796:16
[Email Protected]/mongo/shell/utils.js:754:9
[Email protected]/mongo/shell/utils.js:651:15
@ (SHELLHELP2): 1:1
rs1:primary> Use Adminuse Admin
Switched to DB admin
Rs1:primary> Db.createuser (Db.createuser (
... { {
... User: "BBB", User: "BBB",
... pwd: "BBB", pwd: "BBB",
... roles: [{role: "root", DB: "admin"}] roles: [{role: "root", DB: "admin"}]
... } }
... ) )
Successfully added User: {
"User": "BBB",
"Roles": [
{
"Role": "Root",
"DB": "admin"
}
]
}
Rs1:primary> Show Dbsshow DBS
2016-07-22t17:45:54.756+0800 E QUERY [thread1] error:listdatabases failed:{
"OK": 0,
"ErrMsg": "Not authorized in Admin to execute command {listdatabases:1.0}",
"Code": 13
} :
[Email protected]/mongo/shell/utils.js:25:13
[Email protected]/mongo/shell/mongo.js:62:1
[Email protected]/mongo/shell/utils.js:761:19
[Email protected]/mongo/shell/utils.js:651:15
@ (SHELLHELP2): 1:1
rs1:primary> Db.auth (' BBB ', ' BBB ') Db.auth (' BBB ', ' BBB ') // we have certified here to operate.
1
rs1:primary> Use Localuse Local
Switched to DB Local
Rs1:primary> Show Collectionsshow Collections
Me
Oplog.rs
Replset.election
Startup_log
System.replset
Rs1:primary> Db.oplog.rs.find () Db.oplog.rs.find ()
{"TS": Timestamp (1469180416, 1), "H": Numberlong ("6313428569778261950"), "V": 2, "OP": "N", "ns": "", "O": {"MSG" : "Initiating Set"}}
{"TS": Timestamp (1469180428, 2), "T": Numberlong (1), "H": Numberlong ("2174888517165095400"), "V": 2, "OP": "N", "NS" : "", "O": {"msg": "New Primary"}}
{"TS": Timestamp (1469180731, 1), "T": Numberlong (1), "H": Numberlong (" -1515174104405674576"), "V": 2, "OP": "C", "NS ":" admin. $cmd "," O ": {" create ":" System.version "}}
{"TS": Timestamp (1469180731, 2), "T": Numberlong (1), "H": Numberlong ("7948077691112953460"), "V": 2, "OP": "I", "ns" : "Admin.system.version", "O": {"_id": "Authschema", "CurrentVersion": 5}
{"TS": Timestamp (1469180731, 3), "T": Numberlong (1), "H": Numberlong (" -9003778602149648332"), "V": 2, "OP": "C", "NS ":" admin. $cmd "," O ": {" create ":" System.users "}}
{"TS": Timestamp (1469180731, 4), "T": Numberlong (1), "H": Numberlong (" -5105507245190417325"), "V": 2, "OP": "I", "NS ":" Admin.system.users "," O ": {" _id ":" ADMIN.BBB "," User ":" BBB "," DB ":" admin "," credentials ": {" Scram-sha-1 ": { "IterationCount": 10000, "salt": "9hpz67nn1d9zfskfxfpmhw==", "Storedkey": "wbvbdafg3tkpu0qwgoqa93xasfy=", "ServerKey ":" 0fxomrw01niiyr8hnz9p5mghk8k= "}," Roles ": [{" Role ":" Root "," db ":" Admin "}]}}
Rs1:primary>
To view the Oplog metadata information for master:
> Db.printreplicationinfo ()
To view the synchronization status of Salve:
> Db.printslavereplicationinfo ()
Rs1:primary> Db.printreplicationinfo () db.printreplicationinfo ()
Configured Oplog SIZE:2124.869140625MB
Log length start to End:315secs (0.09hrs)
Oplog First Event Time:fri 17:40:16 gmt+0800 (CST)
Oplog last event Time:fri Jul 17:45:31 gmt+0800 (CST)
Now:fri Jul 17:52:59 gmt+0800 (CST)
Rs1:primary> Db.printslavereplicationinfo () db.printslavereplicationinfo ()
source:localhost:28011
Syncedto:fri Jul 17:45:31 gmt+0800 (CST)
0 secs (0 hrs) behind the primary
source:localhost:28012
Syncedto:fri Jul 17:45:31 gmt+0800 (CST)
0 secs (0 hrs) behind the primary
Rs1:primary>
See the master-slave operation log in the MongoDB replication set Oplog