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:SECONDARY> db.isMaster()
{
"hosts" : [
"node1.pancou.com:27017",
"node2.pancou.com:27017",
"node3.pancou.com:27017",
"node4.pancou.com:27017"
],
"setName" : "rs0",
"setVersion" : 4,
"ismaster" : false,
"secondary" : true,
"primary" : "node3.pancou.com:27017",
"me" : "node4.pancou.com:27017",
"lastWrite" : {
"opTime" : {
"ts" : Timestamp(1495196261, 1),
"t" : NumberLong(8)
},
"lastWriteDate" : ISODate("2017-05-19T12:17:41Z")
},
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 1000,
"localTime" : ISODate("2017-05-19T12:17:44.104Z"),
"maxWireVersion" : 5,
"minWireVersion" : 0,
"readOnly" : false,
"ok" : 1
}
rs0:SECONDARY>
2、减少节点
rs0:PRIMARY> rs.remove("node4.pancou.com:27017")
{ "ok" : 1 }
rs0:PRIMARY> db.isMaster()
{
"hosts" : [
"node1.pancou.com:27017",
"node2.pancou.com:27017",
"node3.pancou.com:27017"
],
"setName" : "rs0",
"setVersion" : 5,
"ismaster" : true,
"secondary" : false,
"primary" : "node3.pancou.com:27017",
"me" : "node3.pancou.com:27017",
"electionId" : ObjectId("7fffffff0000000000000008"),
"lastWrite" : {
"opTime" : {
"ts" : Timestamp(1495196531, 1),
"t" : NumberLong(8)
},
"lastWriteDate" : ISODate("2017-05-19T12:22:11Z")
},
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 1000,
"localTime" : ISODate("2017-05-19T12:22:19.874Z"),
"maxWireVersion" : 5,
"minWireVersion" : 0,
"readOnly" : false,
"ok" : 1
}
rs0:PRIMARY>