rs.status()
命令用于获取MongoDB副本集的状态信息。它提供了关于副本集中各个节点的详细信息,包括节点的健康状况、角色、选举状态等。
以下是查看一个mongo集群状态返回的参数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | rs0:PRIMARY> rs.status() { "set" : "rs0", "date" : ISODate("2024-09-14T06:44:36.882Z"), "myState" : 1, "term" : NumberLong(510), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "heartbeatIntervalMillis" : NumberLong(2000), "majorityVoteCount" : 2, "writeMajorityCount" : 2, "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(0, 0), "t" : NumberLong(-1) }, "lastCommittedWallTime" : ISODate("1970-01-01T00:00:00Z"), "appliedOpTime" : { "ts" : Timestamp(1726296270, 1), "t" : NumberLong(510) }, "durableOpTime" : { "ts" : Timestamp(1726296270, 1), "t" : NumberLong(510) }, "lastAppliedWallTime" : ISODate("2024-09-14T06:44:30.859Z"), "lastDurableWallTime" : ISODate("2024-09-14T06:44:30.859Z") }, "lastStableRecoveryTimestamp" : Timestamp(1725300368, 3), "lastStableCheckpointTimestamp" : Timestamp(1725300368, 3), "electionCandidateMetrics" : { "lastElectionReason" : "electionTimeout", "lastElectionDate" : ISODate("2024-09-14T06:28:20.630Z"), "electionTerm" : NumberLong(510), "lastCommittedOpTimeAtElection" : { "ts" : Timestamp(0, 0), "t" : NumberLong(-1) }, "lastSeenOpTimeAtElection" : { "ts" : Timestamp(1726284227, 1), "t" : NumberLong(509) }, "numVotesNeeded" : 2, "priorityAtElection" : 2, "electionTimeoutMillis" : NumberLong(10000), "numCatchUpOps" : NumberLong(0), "newTermStartDate" : ISODate("2024-09-14T06:28:20.830Z") }, "members" : [ { "_id" : 0, "name" : "mongo1:27017", "health" : 1, "state" : 9, "stateStr" : "ROLLBACK", "uptime" : 987, "optime" : { "ts" : Timestamp(1726197065, 1), "t" : NumberLong(505) }, "optimeDurable" : { "ts" : Timestamp(1726197065, 1), "t" : NumberLong(505) }, "optimeDate" : ISODate("2024-09-13T03:11:05Z"), "optimeDurableDate" : ISODate("2024-09-13T03:11:05Z"), "lastHeartbeat" : ISODate("2024-09-14T06:44:35.841Z"), "lastHeartbeatRecv" : ISODate("2024-09-14T06:44:36.665Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "mongo2:27017", "syncSourceHost" : "mongo2:27017", "syncSourceId" : 1, "infoMessage" : "", "configVersion" : 1950478 }, { "_id" : 1, "name" : "mongo2:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 990, "optime" : { "ts" : Timestamp(1726296270, 1), "t" : NumberLong(510) }, "optimeDate" : ISODate("2024-09-14T06:44:30Z"), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "electionTime" : Timestamp(1726295300, 1), "electionDate" : ISODate("2024-09-14T06:28:20Z"), "configVersion" : 1950478, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 2, "name" : "mongo3:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 987, "optime" : { "ts" : Timestamp(1726197065, 1), "t" : NumberLong(505) }, "optimeDurable" : { "ts" : Timestamp(1726197065, 1), "t" : NumberLong(505) }, "optimeDate" : ISODate("2024-09-13T03:11:05Z"), "optimeDurableDate" : ISODate("2024-09-13T03:11:05Z"), "lastHeartbeat" : ISODate("2024-09-14T06:44:34.930Z"), "lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"), "pingMs" : NumberLong(1), "lastHeartbeatMessage" : "", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "configVersion" : 1829326 } ], "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1726296270, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } }, "operationTime" : Timestamp(1726296270, 1) } rs0:PRIMARY> |
以下是rs.status()
响应字段的意义及其对应值的整理:
字段 | 意义 | 示例值 |
---|---|---|
set |
副本集的名称 | "rs0" |
date |
响应生成的时间 | ISODate("2024-09-14T06:44:36Z") |
myState |
当前节点的状态(1: PRIMARY, 2: SECONDARY, 3: RECOVERING等):
常见的状态包括:
|
1 |
term |
当前选举周期 | 510 |
lastElectionReason |
最近一次选举的原因 | "electionTimeout" |
members |
副本集成员的详细信息 | 数组,包含各个节点的信息 |
health |
节点的健康状态(1: 健康, 0: 不健康) | 1 |
stateStr |
节点的状态描述(如 PRIMARY, SECONDARY, ROLLBACK等) | "SECONDARY" |
uptime |
节点的运行时间(秒) | 987 |
optime |
最近一次操作的时间戳 | Timestamp(1726197065, 1) |
optimeDurable |
最近一次持久化操作的时间戳 | Timestamp(1726197065, 1) |
optimeDate |
最近一次操作的日期 | ISODate("2024-09-13T03:11:05Z") |
optimeDurableDate |
最近一次持久化操作的日期 | ISODate("2024-09-13T03:11:05Z") |
lastHeartbeat |
最近一次心跳信号的时间 | ISODate("2024-09-14T06:44:34.930Z") |
lastHeartbeatRecv |
最近一次接收到心跳信号的时间 | ISODate("1970-01-01T00:00:00Z") |
pingMs |
节点的延迟(毫秒) | NumberLong(1) |
lastHeartbeatMessage |
最近一次心跳的消息 | "" |
syncingTo |
当前节点正在同步的目标节点 | "" |
syncSourceHost |
当前节点的同步源主机 | "" |
syncSourceId |
当前节点的同步源ID | -1 |
infoMessage |
额外的信息消息 | "" |
configVersion |
配置版本号 | 1829326 |
$clusterTime |
集群时间信息 | 包含 clusterTime 和 signature
|
operationTime |
最近一次操作的时间 | Timestamp(1726296270, 1) |
使用场景
- 故障排查: 当副本集出现问题时,使用
rs.status()
可以快速定位故障节点。 - 性能监控: 定期检查副本集状态,以确保所有节点正常运行并及时发现性能瓶颈。
- 维护操作: 在进行维护或升级操作前,确认副本集的健康状况。
- 选举监控: 监控选举过程,确保主节点的选举和切换正常进行。
到此这篇关于mongodb 中rs.stauts()命令参数解析的文章就介绍到这了,更多相关mongodb rs.stauts()命令参数内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!