基本命令:
config = rs.config()
config.members[1].priority=5
rs.reconfig(config)
上面的命令语法,类似JS
命令解析:
rs.isMaster()
{
"hosts" : [ # 标准节点,可选举,可投票,可升降级
"192.168.100.101:27017",
"192.168.100.101:27018"
],
"passives" : [ # 副本节点
"192.168.100.101:27019"
],
"arbiters" : [ # 仲裁节点,只投票,没有其它事
"192.168.100.101:27020"
],
"setName" : "rs0", # 副本名
"setVersion" : 3, # 配置版本
"ismaster" : true, # 是否为主节点
"secondary" : false, # 是否为从节点
"primary" : "192.168.100.101:27017", # 主节点IP与端口
"me" : "192.168.100.101:27017", # 当前节点IP与端口
"electionId" : ObjectId("7fffffff0000000000000007"),
"lastWrite" : {
"opTime" : {
"ts" : Timestamp(1563156254, 1),
"t" : NumberLong(7)
},
"lastWriteDate" : ISODate("2019-07-15T02:04:14Z"),
"majorityOpTime" : {
"ts" : Timestamp(1563156249, 1),
"t" : NumberLong(6)
},
"majorityWriteDate" : ISODate("2019-07-15T02:04:09Z")
},
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 100000,
"localTime" : ISODate("2019-07-15T02:04:19.817Z"),
"logicalSessionTimeoutMinutes" : 30,
"minWireVersion" : 0,
"maxWireVersion" : 7,
"readOnly" : false,
"ok" : 1,
"operationTime" : Timestamp(1563156254, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1563156254, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
rs.status()
{
"set" : "rs0", # 副本集名称
"date" : ISODate("2019-07-15T02:03:25.399Z"),
"myState" : 1, # 状态
"term" : NumberLong(6),
"syncingTo" : "", # 从哪同步
"syncSourceHost" : "", # 同步主机
"syncSourceId" : -1, # 同步源ID,应该是主机中的:_id 值
"heartbeatIntervalMillis" : NumberLong(2000), # 心跳间隔
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1563156199, 1),
"t" : NumberLong(6)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1563156199, 1),
"t" : NumberLong(6)
},
"appliedOpTime" : {
"ts" : Timestamp(1563156199, 1),
"t" : NumberLong(6)
},
"durableOpTime" : {
"ts" : Timestamp(1563156199, 1),
"t" : NumberLong(6)
}
},
"lastStableCheckpointTimestamp" : Timestamp(1563156169, 1),
"members" : [ # 副本集成员
{
"_id" : 0, # 成员ID,唯一
"name" : "192.168.100.101:27017", # 名称
"health" : 1, # 健康状态
"state" : 2, # 节点类型
"stateStr" : "SECONDARY", # 节点类型
"uptime" : 87, # 更新时间
"optime" : {
"ts" : Timestamp(1563156199, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1563156199, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2019-07-15T02:03:19Z"),
"optimeDurableDate" : ISODate("2019-07-15T02:03:19Z"),
"lastHeartbeat" : ISODate("2019-07-15T02:03:24.226Z"),
"lastHeartbeatRecv" : ISODate("2019-07-15T02:03:24.232Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "192.168.100.101:27018", # 同步源
"syncSourceHost" : "192.168.100.101:27018", # 同步源
"syncSourceId" : 1, # 同步源
"infoMessage" : "",
"configVersion" : 3
},
{
"_id" : 1,
"name" : "192.168.100.101:27018",
"health" : 1,
"state" : 1, # 节点类型
"stateStr" : "PRIMARY", # 节点类型
"uptime" : 95,
"optime" : {
"ts" : Timestamp(1563156199, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2019-07-15T02:03:19Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1563156128, 1),
"electionDate" : ISODate("2019-07-15T02:02:08Z"),
"configVersion" : 3,
"self" : true, # 当前主机
"lastHeartbeatMessage" : ""
},
{
"_id" : 2,
"name" : "192.168.100.101:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 74,
"optime" : {
"ts" : Timestamp(1563156199, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1563156199, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2019-07-15T02:03:19Z"),
"optimeDurableDate" : ISODate("2019-07-15T02:03:19Z"),
"lastHeartbeat" : ISODate("2019-07-15T02:03:24.227Z"),
"lastHeartbeatRecv" : ISODate("2019-07-15T02:03:24.095Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "192.168.100.101:27018",
"syncSourceHost" : "192.168.100.101:27018",
"syncSourceId" : 1,
"infoMessage" : "",
"configVersion" : 3
},
{
"_id" : 3,
"name" : "192.168.100.101:27020",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 65,
"lastHeartbeat" : ISODate("2019-07-15T02:03:24.227Z"),
"lastHeartbeatRecv" : ISODate("2019-07-15T02:03:24.126Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 3
}
],
"ok" : 1,
"operationTime" : Timestamp(1563156199, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1563156199, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}