方法名 | 描述 |
rs.initiate() |
rs.addArb() |
rs.help() |
rs.printReplicationInfo() | 檢視到副本集記錄檔 |
rs.remove() | 減少副本集節點 |
rs.freeze() | “當機”mongodb執行個體 |
rs.status() | 檢視副本集狀态 |
db.printSlaveReplicationInfo | 檢視複制集的同步狀态 |
rs.add() | 增加副本集節點 |
rs.stepDown() | 将目前主庫“降級” |
rs.slaveOk() |
rs.conf() |
rs.syncFrom() |
rs.reconfig() |
glc-test:PRIMARY> rs.help()
rs.status() { replSetGetStatus : 1 } checks repl set status
rs.initiate() { replSetInitiate : null } initiates set with default settings
rs.initiate(cfg) { replSetInitiate : cfg } initiates set with configuration cfg
rs.conf() get the current configuration object from local.system.replset
rs.reconfig(cfg) updates the configuration of a running replica set with cfg (disconnects)
rs.add(hostportstr) add a new member to the set with default attributes (disconnects)
rs.add(membercfgobj) add a new member to the set with extra attributes (disconnects)
rs.addArb(hostportstr) add a new member which is arbiterOnly:true (disconnects)
rs.stepDown([stepdownSecs, catchUpSecs]) step down as primary (disconnects)
rs.syncFrom(hostportstr) make a secondary sync from the given member
rs.freeze(secs) make a node ineligible to become primary for the time specified
rs.remove(hostportstr) remove a host from the replica set (disconnects)
rs.slaveOk() allow queries on secondary nodes
rs.printReplicationInfo() check oplog size and time range
rs.printSlaveReplicationInfo() check replica set members and replication lag
db.isMaster() check who is primary
reconfiguration helpers disconnect from the database so the shell will display
an error, even if the command succeeds.
glc-test:PRIMARY>
glc-test:PRIMARY>
glc-test:PRIMARY> rs.slaveOk()
glc-test:PRIMARY>
glc-test:PRIMARY>
glc-test:PRIMARY> db.isMaster()
{
"hosts" : [
"c3-dba-glc-db03.bj:28042",
"c4-mc-buffer-db41.bj:28042",
"c4-using-glc-db05.bj:28042"
],
"setName" : "glc-test",
"setVersion" : 3,
"ismaster" : true,
"secondary" : false,
"primary" : "c4-mc-buffer-db41.bj:28042",
"me" : "c4-mc-buffer-db41.bj:28042",
"electionId" : ObjectId("7fffffff0000000000000071"),
"lastWrite" : {
"opTime" : {
"ts" : Timestamp(1604998554, 1),
"t" : NumberLong(113)
},
"lastWriteDate" : ISODate("2020-11-10T08:55:54Z"),
"majorityOpTime" : {
"ts" : Timestamp(1604998554, 1),
"t" : NumberLong(113)
},
"majorityWriteDate" : ISODate("2020-11-10T08:55:54Z")
},
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 100000,
"localTime" : ISODate("2020-11-10T08:55:57.034Z"),
"logicalSessionTimeoutMinutes" : 30,
"minWireVersion" : 0,
"maxWireVersion" : 7,
"readOnly" : false,
"ok" : 1,
"operationTime" : Timestamp(1604998554, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1604998554, 1),
"signature" : {
"hash" : BinData(0,"ClLo/8FOOXSQJ0zson/tzskvsOI="),
"keyId" : NumberLong("6856584343653974019")
}
}
}
glc-test:PRIMARY> rs.printReplicationInfo()
configured oplog size: 16384MB
log length start to end: 350295secs (97.3hrs)
oplog first event time: Fri Nov 06 2020 15:37:49 GMT+0800 (CST)
oplog last event time: Tue Nov 10 2020 16:56:04 GMT+0800 (CST)
now: Tue Nov 10 2020 16:56:07 GMT+0800 (CST)
glc-test:PRIMARY> rs.printSlaveReplicationInfo()
source: c3-dba-glc-db03.bj:28042
syncedTo: Tue Nov 10 2020 16:56:04 GMT+0800 (CST)
0 secs (0 hrs) behind the primary
source: c4-using-glc-db05.bj:28042
syncedTo: Tue Nov 10 2020 16:56:04 GMT+0800 (CST)
0 secs (0 hrs) behind the primary
glc-test:PRIMARY> rs.conf()
{
"_id" : "glc-test",
"version" : 3,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "c3-dba-glc-db03.bj:28042",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "c4-mc-buffer-db41.bj:28042",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "c4-using-glc-db05.bj:28042",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5f277b18c13c2cbe19624b2d")
}
}
glc-test:PRIMARY> rs.status()
{
"set" : "glc-test",
"date" : ISODate("2020-11-10T08:56:26.438Z"),
"myState" : 1,
"term" : NumberLong(113),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1604998584, 1),
"t" : NumberLong(113)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1604998584, 1),
"t" : NumberLong(113)
},
"appliedOpTime" : {
"ts" : Timestamp(1604998584, 1),
"t" : NumberLong(113)
},
"durableOpTime" : {
"ts" : Timestamp(1604998584, 1),
"t" : NumberLong(113)
}
},
"lastStableCheckpointTimestamp" : Timestamp(1604998534, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "stepUpRequestSkipDryRun",
"lastElectionDate" : ISODate("2020-10-20T08:13:43.452Z"),
"electionTerm" : NumberLong(113),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(1603181617, 1),
"t" : NumberLong(112)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1603181617, 1),
"t" : NumberLong(112)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"priorPrimaryMemberId" : 0,
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2020-10-20T08:13:43.456Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2020-10-20T08:13:43.458Z")
},
"electionParticipantMetrics" : {
"votedForCandidate" : true,
"electionTerm" : NumberLong(112),
"lastVoteDate" : ISODate("2020-09-22T06:24:36.196Z"),
"electionCandidateMemberId" : 0,
"voteReason" : "",
"lastAppliedOpTimeAtElection" : {
"ts" : Timestamp(1600755874, 1),
"t" : NumberLong(111)
},
"maxAppliedOpTimeInSet" : {
"ts" : Timestamp(1600755874, 1),
"t" : NumberLong(111)
},
"priorityAtElection" : 1
},
"members" : [
{
"_id" : 0,
"name" : "c3-dba-glc-db03.bj:28042",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 4243441,
"optime" : {
"ts" : Timestamp(1604998584, 1),
"t" : NumberLong(113)
},
"optimeDurable" : {
"ts" : Timestamp(1604998584, 1),
"t" : NumberLong(113)
},
"optimeDate" : ISODate("2020-11-10T08:56:24Z"),
"optimeDurableDate" : ISODate("2020-11-10T08:56:24Z"),
"lastHeartbeat" : ISODate("2020-11-10T08:56:24.572Z"),
"lastHeartbeatRecv" : ISODate("2020-11-10T08:56:24.820Z"),
"pingMs" : NumberLong(1),
"lastHeartbeatMessage" : "",
"syncingTo" : "c4-mc-buffer-db41.bj:28042",
"syncSourceHost" : "c4-mc-buffer-db41.bj:28042",
"syncSourceId" : 1,
"infoMessage" : "",
"configVersion" : 3
},
{
"_id" : 1,
"name" : "c4-mc-buffer-db41.bj:28042",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 6401661,
"optime" : {
"ts" : Timestamp(1604998584, 1),
"t" : NumberLong(113)
},
"optimeDate" : ISODate("2020-11-10T08:56:24Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1603181623, 1),
"electionDate" : ISODate("2020-10-20T08:13:43Z"),
"configVersion" : 3,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 2,
"name" : "c4-using-glc-db05.bj:28042",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 4227596,
"optime" : {
"ts" : Timestamp(1604998584, 1),
"t" : NumberLong(113)
},
"optimeDurable" : {
"ts" : Timestamp(1604998584, 1),
"t" : NumberLong(113)
},
"optimeDate" : ISODate("2020-11-10T08:56:24Z"),
"optimeDurableDate" : ISODate("2020-11-10T08:56:24Z"),
"lastHeartbeat" : ISODate("2020-11-10T08:56:25.291Z"),
"lastHeartbeatRecv" : ISODate("2020-11-10T08:56:25.030Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "c4-mc-buffer-db41.bj:28042",
"syncSourceHost" : "c4-mc-buffer-db41.bj:28042",
"syncSourceId" : 1,
"infoMessage" : "",
"configVersion" : 3
}
],
"ok" : 1,
"operationTime" : Timestamp(1604998584, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1604998584, 1),
"signature" : {
"hash" : BinData(0,"Sx7IW3xyv17MwDyskTFJOOQ8IeU="),
"keyId" : NumberLong("6856584343653974019")
}
}
}
glc-test:PRIMARY>