MongoDB Replication副本集命令
一、MongoDB isMaster 命令
mongod 实例的作用由 isMaster 命令返回的文档描述。为了创建特定用户的凭证,使用了一系列 SASL 机制。当 saslSupportMechs 被指定为可选字段时返回。如果实例是副本集的成员,则 isMaster 命令返回副本集的子集。
isMaster 命令在发送到 mongod 实例时返回相关信息,该实例不是副本集的成员。
语法:
db.runCommand( { isMaster: 1 } )
二、MongoDB replySetAbortPrimaryCatchUp 命令
该命令强制副本集的指定主要成员结束同步,然后完成到主要成员的转换。
语法:
{ replSetAbortPrimaryCatchUp: 1 }
三、MongoDB replSetGetConfig 命令
该命令返回一个指定副本集当前配置的文档。要直接获取命令,我们必须使用以下操作:
语法:
db.runCommand( { replSetGetConfig: 1 } );
例如:我们有一个代表副本集配置的文档。它可能仅包括以下设置的子集:
{
_id: <string>,
version: <int>,
protocolVersion: <number>,
writeConcernMajorityJournalDefault: <boolean>,
configsvr: <boolean>,
members: [
{
_id: <int>,
host: <string>,
arbiterOnly: <boolean>,
buildIndexes: <boolean>,
hidden: <boolean>,
priority: <number>,
tags: <document>,
slaveDelay: <int>,
votes: <number>
},
...
],
settings: {
chainingAllowed : <boolean>,
heartbeatIntervalMillis : <int>,
heartbeatTimeoutSecs: <int>,
electionTimeoutMillis : <int>,
catchUpTimeoutMillis : <int>,
getLastErrorModes : <document>,
getLastErrorDefaults : <document>,
replicaSetId: <ObjectId>
}
}
四、MongoDB replSetInitiate 命令
replSetInitiative 命令用于初始化一个新的副本集。
语法:
{ replSetInitiate : <config_document> }
将文档传递给 rs.initiate() 助手的示例:
五、MongoDB replSetGetStatus 命令
该命令将状态返回到副本集。它从用于处理文档的服务器返回它。此命令返回的数据源自集合中其他成员发送给服务器的信号中包含的数据。
语法:
db.adminCommand( { replSetGetStatus: 1 } )
语法:
db.adminCommand( { replSetGetStatus : 1 } )
{
"set" : "replset",
"date" : ISODate("2019-12-04T04:49:18.693Z"),
"myState" : 1,
"term" : NumberLong(3),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"lastCommittedWallTime" : ISODate("2019-12-04T04:49:14.378Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"readConcernMajorityWallTime" : ISODate("2019-12-04T04:49:14.378Z"),
"appliedOpTime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"durableOpTime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"lastAppliedWallTime" : ISODate("2019-12-04T04:49:14.378Z"),
"lastDurableWallTime" : ISODate("2019-12-04T04:49:14.378Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1575434935, 1),
"lastStableCheckpointTimestamp" : Timestamp(1575434935, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "stepUpRequestSkipDryRun",
"lastElectionDate" : ISODate("2019-12-04T04:49:04.085Z"),
"electionTerm" : NumberLong(3),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(1575434935, 1),
"t" : NumberLong(2)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1575434935, 1),
"t" : NumberLong(2)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"priorPrimaryMemberId" : 1,
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2019-12-04T04:49:04.366Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2019-12-04T04:49:04.382Z")
},
"electionParticipantMetrics" : {
"votedForCandidate" : true,
"electionTerm" : NumberLong(2),
"lastVoteDate" : ISODate("2019-12-04T04:16:54.398Z"),
"electionCandidateMemberId" : 1,
"voteReason" : "",
"lastAppliedOpTimeAtElection" : {
"ts" : Timestamp(1575433013, 1),
"t" : NumberLong(1)
},
"maxAppliedOpTimeInSet" : {
"ts" : Timestamp(1575433013, 1),
"t" : NumberLong(1)
},
"priorityAtElection" : 1
},
"members" : [
{
"_id" : 0,
"name" : "m1.example.net:27017",
"ip" : "198.51.100.1",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 2019,
"optime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2019-12-04T04:49:14Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1575434944, 1),
"electionDate" : ISODate("2019-12-04T04:49:04Z"),
"configVersion" : 1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "m2.example.net:27017",
"ip" : "198.51.100.2",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 2016,
"optime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDurable" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2019-12-04T04:49:14Z"),
"optimeDurableDate" : ISODate("2019-12-04T04:49:14Z"),
"lastHeartbeat" : ISODate("2019-12-04T04:49:18.138Z"),
"lastHeartbeatRecv" : ISODate("2019-12-04T04:49:18.460Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "m1.example.net:27017",
"syncSourceHost" : "m1.example.net:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "m3.example.net:27017",
"ip" : "198.51.100.3",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 2016,
"optime" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDurable" : {
"ts" : Timestamp(1575434954, 1),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2019-12-04T04:49:14Z"),
"optimeDurableDate" : ISODate("2019-12-04T04:49:14Z"),
"lastHeartbeat" : ISODate("2019-12-04T04:49:18.138Z"),
"lastHeartbeatRecv" : ISODate("2019-12-04T04:49:17.739Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "m1.example.net:27017",
"syncSourceHost" : "m1.example.net:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1575434954, 1),
"signature" : {
"hash" : BinData(0,"Dz4WAzT3KpB5XHXwy3MgcjL3M8Q="),
"keyId" : NumberLong("6766433010175705091")
}
},
"operationTime" : Timestamp(1575434954, 1)
}
输出结果为:
热门文章
优秀文章