rs0:SECONDARY> rs.slaveOk()
rs0:SECONDARY> show dbs
admin 0.000GB
local 0.000GB
testdb 0.000GB
rs0:SECONDARY> use testdb
switched to db testdb
rs0:SECONDARY> show collections
testcoll
rs0:SECONDARY> db.testcoll.find()
{ "_id" : ObjectId("591dd9f965cc255a5373aefa"), "name" : "tom", "age" : 25 }
rs0:SECONDARY>
node3:
rs0:SECONDARY> rs.slaveOk()
rs0:SECONDARY> show dbs
admin 0.000GB
local 0.000GB
testdb 0.000GB
rs0:SECONDARY> use testdb
switched to db testdb
rs0:SECONDARY> show collections
testcoll
rs0:SECONDARY> db.testcoll.find()
{ "_id" : ObjectId("591dd9f965cc255a5373aefa"), "name" : "tom", "age" : 25 }
rs0:SECONDARY>
主从操作日志
rs0:PRIMARY> use local
switched to db local
rs0:PRIMARY> show collections
me
oplog.rs
replset.election
replset.minvalid
startup_log
system.replset
rs0:PRIMARY> db.oplog.rs.find()
{ "ts" : Timestamp(1495126824, 1), "h" : NumberLong("3056083863196084673"), "v" : 2, "op" : "n", "ns" : "", "o" : { "msg" : "initiating set" } }
{ "ts" : Timestamp(1495126825, 1), "t" : NumberLong(1), "h" : NumberLong("7195178065440751511"), "v" : 2, "op" : "n", "ns" : "", "o" : { "msg" : "new primary" } }
{ "ts" : Timestamp(1495126835, 1), "t" : NumberLong(1), "h" : NumberLong("5723995478292318850"), "v" : 2, "op" : "n", "ns" : "", "o" : { "msg" : "periodic noop" } }
{ "ts" : Timestamp(1495126845, 1), "t" : NumberLong(1), "h" : NumberLong("-3772304067699003381"), "v" : 2, "op" : "n", "ns" : "", "o"
三、查看配置信息
rs0:PRIMARY> db.printReplicationInfo()
configured oplog size: 1024MB
log length start to end: 2541secs (0.71hrs)
oplog first event time: Fri May 19 2017 01:00:24 GMT+0800 (CST)
oplog last event time: Fri May 19 2017 01:42:45 GMT+0800 (CST)
now: Fri May 19 2017 01:42:48 GMT+0800 (CST)
rs0:PRIMARY>
db.oplog.rs.find():查看复制集产生的日志
db.printReplicationInfo():查看操作日志的一些基本信息,如日志大小、日志启用时间。
db.printSlaveReplicationInfo():查看所有slave延迟情况。