MongoDB设置 Replication Sets 复制集(3)


    > rs.initiate()
 {
  "info2" : "no configuration specified. Using a default configuration for the set",
  "me" : "node1.pancou.com:27017",
  "ok" : 1
 }


    rs0:OTHER>
 rs0:PRIMARY> rs.status()
 {
  "set" : "rs0",
  "date" : ISODate("2017-05-18T17:00:49.868Z"),
  "myState" : 1,
  "term" : NumberLong(1),
  "heartbeatIntervalMillis" : NumberLong(2000),
  "optimes" : {
   "lastCommittedOpTime" : {
    "ts" : Timestamp(1495126845, 1),
    "t" : NumberLong(1)
   },
   "appliedOpTime" : {
    "ts" : Timestamp(1495126845, 1),
    "t" : NumberLong(1)
   },
   "durableOpTime" : {
    "ts" : Timestamp(1495126845, 1),
    "t" : NumberLong(1)
   }
  },
  "members" : [
   {
    "_id" : 0,
    "name" : "node1.pancou.com:27017",
    "health" : 1,
    "state" : 1,
    "stateStr" : "PRIMARY",
    "uptime" : 1239,
    "optime" : {
     "ts" : Timestamp(1495126845, 1),
     "t" : NumberLong(1)
    },
    "optimeDate" : ISODate("2017-05-18T17:00:45Z"),
    "infoMessage" : "could not find member to sync from",
    "electionTime" : Timestamp(1495126824, 2),
    "electionDate" : ISODate("2017-05-18T17:00:24Z"),
    "configVersion" : 1,
    "self" : true
   }
  ],
  "ok" : 1
 }


    rs0:PRIMARY> rs.add("node2.pancou.com")
 { "ok" : 1 }
 rs0:PRIMARY> rs.add("node3.pancou.com")
 { "ok" : 1 }
    rs0:PRIMARY> rs.status()
 {
  "set" : "rs0",
  "date" : ISODate("2017-05-18T17:08:47.724Z"),
  "myState" : 1,
  "term" : NumberLong(1),
  "heartbeatIntervalMillis" : NumberLong(2000),
  "optimes" : {
   "lastCommittedOpTime" : {
    "ts" : Timestamp(1495127325, 1),
    "t" : NumberLong(1)
   },
   "appliedOpTime" : {
    "ts" : Timestamp(1495127325, 1),
    "t" : NumberLong(1)
   },
   "durableOpTime" : {
    "ts" : Timestamp(1495127325, 1),
    "t" : NumberLong(1)
   }
  },
  "members" : [
   {
    "_id" : 0,
    "name" : "node1.pancou.com:27017",
    "health" : 1,              //表明状态正常
    "state" : 1,              //1表示是PRIMARY,2表示是slave
    "stateStr" : "PRIMARY",    //表示此机器是主库
    "uptime" : 1717,
    "optime" : {
     "ts" : Timestamp(1495127325, 1),
     "t" : NumberLong(1)
    },
    "optimeDate" : ISODate("2017-05-18T17:08:45Z"),
    "electionTime" : Timestamp(1495126824, 2),
    "electionDate" : ISODate("2017-05-18T17:00:24Z"),
    "configVersion" : 3,
    "self" : true
   },
   {
    "_id" : 1,
    "name" : "node2.pancou.com:27017",
    "health" : 1,
    "state" : 2,
    "stateStr" : "SECONDARY",
    "uptime" : 64,
    "optime" : {
     "ts" : Timestamp(1495127325, 1),
     "t" : NumberLong(1)
    },
    "optimeDurable" : {
     "ts" : Timestamp(1495127325, 1),
     "t" : NumberLong(1)
    },
    "optimeDate" : ISODate("2017-05-18T17:08:45Z"),
    "optimeDurableDate" : ISODate("2017-05-18T17:08:45Z"),
    "lastHeartbeat" : ISODate("2017-05-18T17:08:46.106Z"),
    "lastHeartbeatRecv" : ISODate("2017-05-18T17:08:47.141Z"),
    "pingMs" : NumberLong(0),
    "syncingTo" : "node1.pancou.com:27017",
    "configVersion" : 3
   },
   {
    "_id" : 2,
    "name" : "node3.pancou.com:27017",
    "health" : 1,
    "state" : 2,
    "stateStr" : "SECONDARY",
    "uptime" : 55,
    "optime" : {
     "ts" : Timestamp(1495127325, 1),
     "t" : NumberLong(1)
    },
    "optimeDurable" : {
     "ts" : Timestamp(1495127325, 1),
     "t" : NumberLong(1)
    },
    "optimeDate" : ISODate("2017-05-18T17:08:45Z"),
    "optimeDurableDate" : ISODate("2017-05-18T17:08:45Z"),
    "lastHeartbeat" : ISODate("2017-05-18T17:08:46.195Z"),
    "lastHeartbeatRecv" : ISODate("2017-05-18T17:08:46.924Z"),
    "pingMs" : NumberLong(0),
    "syncingTo" : "node2.pancou.com:27017",
    "configVersion" : 3
   }
  ],
  "ok" : 1
 }
   
    rs0:PRIMARY> db.isMaster()
 {
  "hosts" : [
   "node1.pancou.com:27017",
   "node2.pancou.com:27017",
   "node3.pancou.com:27017"
  ],
  "setName" : "rs0",
  "setVersion" : 3,
  "ismaster" : true,
  "secondary" : false,
  "primary" : "node1.pancou.com:27017",
  "me" : "node1.pancou.com:27017",
  "electionId" : ObjectId("7fffffff0000000000000001"),
  "lastWrite" : {
   "opTime" : {
    "ts" : Timestamp(1495127705, 1),
    "t" : NumberLong(1)
   },
   "lastWriteDate" : ISODate("2017-05-18T17:15:05Z")
  },
  "maxBsonObjectSize" : 16777216,
  "maxMessageSizeBytes" : 48000000,
  "maxWriteBatchSize" : 1000,
  "localTime" : ISODate("2017-05-18T17:15:11.146Z"),
  "maxWireVersion" : 5,
  "minWireVersion" : 0,
  "readOnly" : false,
  "ok" : 1
 }
   
    rs0:PRIMARY> use testdb
    rs0:PRIMARY> show collections
 testcoll
 rs0:PRIMARY> db.testcoll.find()
 { "_id" : ObjectId("591dd9f965cc255a5373aefa"), "name" : "tom", "age" : 25 }


    到从库上查看:


    node2:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d63e6ebf4a92b37e2f81522de35bff98.html