# mongoWork **Repository Path**: zhayan/mongo-work ## Basic Information - **Project Name**: mongoWork - **Description**: mongo测试 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-01-27 - **Last Updated**: 2022-01-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### mongo模拟 [运行模拟](doc/mongo分片模拟.zip) #### 安装配置 1. [下载地址](https://www.mongodb.com/try/download/community) 2. 启动过程 ```xml tar -zvxf **.tgz shell1: cd [mongo-path] ./bin/mongod -p mongo.conf shell2: cd [mongo-path] ./bin/mongo --host=[ip] --port=[port] ``` 3. 相关命令 ```xml # 创建库 use lg_resume show dbs # 创建表 db.createCollection('t_resume') show tables ``` ### 集群架构 ![](doc/img/集群架构.png) 1. 分片集群搭建在同一台服务器上:**安装在192.168.174.135** 2. 路由节点:27017端口 3. 配置节点集群:17011/17013/17015端口 4. 分片节点:前3个端口为正常分片,017为仲裁节点 #### 配置节点 ``` mkdir /data/mongo/config17011 -p mkdir /data/mongo/config17013 -p mkdir /data/mongo/config17015 -p ``` ``` vim config_17011.conf #配置节点17011 dbpath=/data/mongo/config17011 port=17011 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/config17011/MongoDB.log replSet=configCluster configsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim config_17013.conf #配置节点17013 dbpath=/data/mongo/config17013 port=17013 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/config17011/MongoDB.log replSet=configCluster configsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim config_17015.conf #配置节点17015 dbpath=/data/mongo/config17015 port=17015 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/config17011/MongoDB.log replSet=configCluster configsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` #启动 ./bin/mongod -f config_17011.conf ./bin/mongod -f config_17013.conf ./bin/mongod -f config_17015.conf ``` ``` # 集群配置 ./bin/mongo --port 17011 use admin var cfg ={"_id":"configCluster", "members":[ {"_id":1,"host":"192.168.174.135:17011"}, {"_id":2,"host":"192.168.174.135:17013"}, {"_id":3,"host":"192.168.174.135:17015"}] }; rs.initiate(cfg) # 等待成为primary rs.status() ``` #### 370**分片 1. 主节点:37011 2. 从节点:37013/37015 3. 仲裁节点:37017 ``` # 创建目录 mkdir /data/mongo/server37011 -p mkdir /data/mongo/server37013 -p mkdir /data/mongo/server37015 -p mkdir /data/mongo/server37017 -p ``` ``` vim mongo_37011.conf #节点37011 dbpath=/data/mongo/server37011 port=37011 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server37011/MongoDB.log replSet=lagouCluster shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim mongo_37013.conf #节点37013 dbpath=/data/mongo/server37013 port=37013 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server37013/MongoDB.log replSet=lagouCluster shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim mongo_37015.conf #节点37015 dbpath=/data/mongo/server37015 port=37015 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server37015/MongoDB.log replSet=lagouCluster logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim mongo_37017.conf #节点37017-仲裁节点 dbpath=/data/mongo/server37017 port=37017 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server37017/MongoDB.log replSet=lagouCluster shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` # 启动 ./bin/mongod -f mongo_37011.conf ./bin/mongod -f mongo_37013.conf ./bin/mongod -f mongo_37015.conf ./bin/mongod -f mongo_37017.conf ``` ``` ./bin/mongo --port 37011 var cfg ={"_id":"lagouCluster", "protocolVersion" : 1, "members":[ {"_id":1,"host":"192.168.174.135:37011"}, {"_id":2,"host":"192.168.174.135:37013"}, {"_id":3,"host":"192.168.174.135:37015"}, {"_id":4,"host":"192.168.174.135:37017","arbiterOnly":true} ] }; rs.initiate(cfg) rs.status() # 动态新增节点 增加节点 rs.add("192.168.174.135:37015") 删除slave 节点 rs.remove("192.168.211.135:37015") # 设置仲裁标识 rs.addArb("192.168.174.135:37017") ``` #### 470**分片 ``` # 创建目录 mkdir /data/mongo/server47011 -p mkdir /data/mongo/server47013 -p mkdir /data/mongo/server47015 -p mkdir /data/mongo/server47017 -p ``` ``` vim mongo_47011.conf #节点47011 dbpath=/data/mongo/server47011 port=47011 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server47011/MongoDB.log replSet=lagouCluster2 shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim mongo_47013.conf #节点47013 dbpath=/data/mongo/server47013 port=47013 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server47013/MongoDB.log replSet=lagouCluster2 shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim mongo_47015.conf #节点47015 dbpath=/data/mongo/server47015 port=47015 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server47015/MongoDB.log replSet=lagouCluster2 shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim mongo_47017.conf #节点47017 dbpath=/data/mongo/server47017 port=47017 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server47017/MongoDB.log replSet=lagouCluster2 shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` # 启动 ./bin/mongod -f mongo_47011.conf ./bin/mongod -f mongo_47013.conf ./bin/mongod -f mongo_47015.conf ./bin/mongod -f mongo_47017.conf ``` ``` #进入任意分片 ./bin/mongo --port 47011 var cfg ={"_id":"lagouCluster2", "protocolVersion" : 1, "members":[ {"_id":1,"host":"192.168.174.135:47011"}, {"_id":2,"host":"192.168.174.135:47013"}, {"_id":3,"host":"192.168.174.135:47015"}, {"_id":4,"host":"192.168.174.135:47017","arbiterOnly":true} ] }; rs.initiate(cfg) rs.status() # 设置仲裁标识 # rs.addArb("192.168.174.135:57017") ``` #### 570**分片 ``` # 创建目录 mkdir /data/mongo/server57011 -p mkdir /data/mongo/server57013 -p mkdir /data/mongo/server57015 -p mkdir /data/mongo/server57017 -p ``` ``` vim mongo_57011.conf #节点57011 dbpath=/data/mongo/server57011 port=57011 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server57011/MongoDB.log replSet=lagouCluster3 shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim mongo_57013.conf #节点57013 dbpath=/data/mongo/server57013 port=57013 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server57013/MongoDB.log replSet=lagouCluster3 shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim mongo_57015.conf #节点57015 dbpath=/data/mongo/server57015 port=57015 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server57015/MongoDB.log replSet=lagouCluster3 shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` vim mongo_57017.conf #节点57017 dbpath=/data/mongo/server57017 port=57017 bind_ip=0.0.0.0 fork=true logpath = /data/mongo/server57015/MongoDB.log replSet=lagouCluster3 shardsvr=true logappend = true auth=true keyFile=/data/mongo/testKeyFile.file ``` ``` # 启动 ./bin/mongod -f mongo_57011.conf ./bin/mongod -f mongo_57013.conf ./bin/mongod -f mongo_57015.conf ./bin/mongod -f mongo_57017.conf ``` ``` #进入任意分片 ./bin/mongo --port 57011 var cfg ={"_id":"lagouCluster3", "protocolVersion" : 1, "members":[ {"_id":1,"host":"192.168.174.135:57011"}, {"_id":2,"host":"192.168.174.135:57013"}, {"_id":3,"host":"192.168.174.135:57015"}, {"_id":4,"host":"192.168.174.135:57017","arbiterOnly":true} ] }; rs.initiate(cfg) rs.status() # 设置仲裁标识 rs.addArb("192.168.174.135:57017") ``` #### 路由节点 ``` mkdir /route/logs -p ``` ``` vim route_27017.conf #路由节点 port=27017 bind_ip=0.0.0.0 fork=true logpath=route/logs/route.log # 配置节点 configdb=configCluster/192.168.174.135:17011,192.168.174.135:17013,192.168.174.135:17015 keyFile=/data/mongo/testKeyFile.file ``` ``` #启动 ./bin/mongos -f route_27017.conf ``` ``` # 进入路由节点进行分片配置 ./bin/mongo --port 27017 sh.status() sh.addShard("lagouCluster/192.168.174.135:37011,192.168.174.135:37013,192.168.174.135:37015,192.168.174.135:37017"); sh.addShard("lagouCluster2/192.168.174.135:47011,192.168.174.135:47013,192.168.174.135:47015,192.168.174.135:47017"); sh.addShard("lagouCluster3/192.168.174.135:57011,192.168.174.135:57013,192.168.174.135:57015,192.168.174.135:57017"); sh.status() ``` ``` #开启分片 use lagou_resume sh.enableSharding("lagou_resume") 为指定集合开启分⽚功能 sh.shardCollection("lagou_resume.lagou_resume_datas",{"name":"hashed"}) db.chunks.remove({ns:'lagou_resume.lagou_resume_datas'}) ``` #### 数据测试 ``` #在路由节点内部进行操作 use lagou_resume db.createCollection("lagou_resume_datas") ``` #### 集群安全 ``` # 各个数据节点里都需要执行 use admin db.createUser( { user:"root", pwd:"123456", roles:[{role:"root",db:"admin"}] } ); #创建后直接验证 db.auth('root','123456') # 各个数据节点里都需要执行 use lagou_resume db.createUser({ user:"lagou_gx", pwd:"abc321", roles:[{role:"readWrite",db:"lagou_resume"}] }) ``` ``` #配置权限 openssl rand -base64 756 > /data/mongo/testKeyFile.file chmod 600 /data/mongo/testKeyFile.file ``` ### 问题与解决 1. 仲裁节点无法启动:删除dbpath,重新启动刷新 2. not master and slaveOk=false:执行rs.slaveOk() 3. 数据未分片成功:size过大或者调整分片key ``` #chunksiz db.集合名称.stats(); db.lagou_resume_datas.stats() #重新设置 use config db.settings.save( { _id:"chunksize", value: 1 } ) db.settings.insertOne( { _id:"chunksize", value: 1 } ) ``` ![](doc/img/chunksize.png) 4. 无法启动:虚拟机死机,无法启动mongo,删除dbpath中的mongo.lock,或者直接删除dbpath ``` Failed to target upsert by query :: could not extract exact shard key 更新数据 ``` ### 集群状态 #### 路由 ``` mongos> sh.status() --- Sharding Status --- sharding version: { "_id" : 1, "minCompatibleVersion" : 5, "currentVersion" : 6, "clusterId" : ObjectId("61f35cd55aae9526b2fde69c") } shards: { "_id" : "lagouCluster", "host" : "lagouCluster/192.168.174.135:37011,192.168.174.135:37013,192.168.174.135:37015", "state" : 1 } { "_id" : "lagouCluster2", "host" : "lagouCluster2/192.168.174.135:47011,192.168.174.135:47013,192.168.174.135:47015", "state" : 1 } { "_id" : "lagouCluster3", "host" : "lagouCluster3/192.168.174.135:57011,192.168.174.135:57013,192.168.174.135:57015", "state" : 1 } active mongoses: "4.2.18" : 1 autosplit: Currently enabled: yes balancer: Currently enabled: yes Currently running: no Failed balancer rounds in last 5 attempts: 5 Last reported error: Could not find host matching read preference { mode: "primary" } for set lagouCluster3 Time of Reported error: Fri Jan 28 2022 13:37:31 GMT+0800 (CST) Migration Results for the last 24 hours: 682 : Success databases: { "_id" : "config", "primary" : "config", "partitioned" : true } config.system.sessions shard key: { "_id" : 1 } unique: false balancing: true chunks: lagouCluster 342 lagouCluster2 341 lagouCluster3 341 too many chunks to print, use verbose if you want to force print { "_id" : "lagou_resume", "primary" : "lagouCluster3", "partitioned" : true, "version" : { "uuid" : UUID("488b630f-a217-43fc-9ebe-722e18f09ca2"), "lastMod" : 1 } } lagou_resume.lagou_resume_datas shard key: { "name" : "hashed" } unique: false balancing: true chunks: lagouCluster 2 lagouCluster2 2 lagouCluster3 2 { "name" : { "$minKey" : 1 } } -->> { "name" : NumberLong("-6148914691236517204") } on : lagouCluster Timestamp(1, 0) { "name" : NumberLong("-6148914691236517204") } -->> { "name" : NumberLong("-3074457345618258602") } on : lagouCluster Timestamp(1, 1) { "name" : NumberLong("-3074457345618258602") } -->> { "name" : NumberLong(0) } on : lagouCluster2 Timestamp(1, 2) { "name" : NumberLong(0) } -->> { "name" : NumberLong("3074457345618258602") } on : lagouCluster2 Timestamp(1, 3) { "name" : NumberLong("3074457345618258602") } -->> { "name" : NumberLong("6148914691236517204") } on : lagouCluster3 Timestamp(1, 4) { "name" : NumberLong("6148914691236517204") } -->> { "name" : { "$maxKey" : 1 } } on : lagouCluster3 Timestamp(1, 5) ``` #### 配置 ``` configCluster:PRIMARY> rs.status() { "set" : "configCluster", "date" : ISODate("2022-01-28T06:33:22.642Z"), "myState" : 1, "term" : NumberLong(3), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "configsvr" : true, "heartbeatIntervalMillis" : NumberLong(2000), "majorityVoteCount" : 2, "writeMajorityCount" : 2, "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1643351601, 1), "t" : NumberLong(3) }, "lastCommittedWallTime" : ISODate("2022-01-28T06:33:21.989Z"), "readConcernMajorityOpTime" : { "ts" : Timestamp(1643351601, 1), "t" : NumberLong(3) }, "readConcernMajorityWallTime" : ISODate("2022-01-28T06:33:21.989Z"), "appliedOpTime" : { "ts" : Timestamp(1643351601, 1), "t" : NumberLong(3) }, "durableOpTime" : { "ts" : Timestamp(1643351601, 1), "t" : NumberLong(3) }, "lastAppliedWallTime" : ISODate("2022-01-28T06:33:21.989Z"), "lastDurableWallTime" : ISODate("2022-01-28T06:33:21.989Z") }, "lastStableRecoveryTimestamp" : Timestamp(1643351593, 1), "lastStableCheckpointTimestamp" : Timestamp(1643351593, 1), "electionCandidateMetrics" : { "lastElectionReason" : "electionTimeout", "lastElectionDate" : ISODate("2022-01-28T05:30:22.875Z"), "electionTerm" : NumberLong(3), "lastCommittedOpTimeAtElection" : { "ts" : Timestamp(0, 0), "t" : NumberLong(-1) }, "lastSeenOpTimeAtElection" : { "ts" : Timestamp(1643347559, 3), "t" : NumberLong(2) }, "numVotesNeeded" : 2, "priorityAtElection" : 1, "electionTimeoutMillis" : NumberLong(10000), "numCatchUpOps" : NumberLong(0), "newTermStartDate" : ISODate("2022-01-28T05:30:22.879Z"), "wMajorityWriteAvailabilityDate" : ISODate("2022-01-28T05:30:23.760Z") }, "members" : [ { "_id" : 1, "name" : "192.168.174.135:17011", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 3792, "optime" : { "ts" : Timestamp(1643351601, 1), "t" : NumberLong(3) }, "optimeDate" : ISODate("2022-01-28T06:33:21Z"), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "electionTime" : Timestamp(1643347822, 1), "electionDate" : ISODate("2022-01-28T05:30:22Z"), "configVersion" : 1, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 2, "name" : "192.168.174.135:17013", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 3783, "optime" : { "ts" : Timestamp(1643351600, 1), "t" : NumberLong(3) }, "optimeDurable" : { "ts" : Timestamp(1643351600, 1), "t" : NumberLong(3) }, "optimeDate" : ISODate("2022-01-28T06:33:20Z"), "optimeDurableDate" : ISODate("2022-01-28T06:33:20Z"), "lastHeartbeat" : ISODate("2022-01-28T06:33:21.809Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:33:20.994Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.174.135:17011", "syncSourceHost" : "192.168.174.135:17011", "syncSourceId" : 1, "infoMessage" : "", "configVersion" : 1 }, { "_id" : 3, "name" : "192.168.174.135:17015", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 3773, "optime" : { "ts" : Timestamp(1643351600, 1), "t" : NumberLong(3) }, "optimeDurable" : { "ts" : Timestamp(1643351600, 1), "t" : NumberLong(3) }, "optimeDate" : ISODate("2022-01-28T06:33:20Z"), "optimeDurableDate" : ISODate("2022-01-28T06:33:20Z"), "lastHeartbeat" : ISODate("2022-01-28T06:33:21.696Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:33:21.053Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.174.135:17013", "syncSourceHost" : "192.168.174.135:17013", "syncSourceId" : 2, "infoMessage" : "", "configVersion" : 1 } ], "ok" : 1, "$gleStats" : { "lastOpTime" : Timestamp(0, 0), "electionId" : ObjectId("7fffffff0000000000000003") }, "lastCommittedOpTime" : Timestamp(1643351601, 1), "$clusterTime" : { "clusterTime" : Timestamp(1643351601, 1), "signature" : { "hash" : BinData(0,"TXUnVDGgJ3kgTh4LIHezCJmV1tk="), "keyId" : NumberLong("7058087110917488672") } }, "operationTime" : Timestamp(1643351601, 1) } ``` #### 分片1-lagouCluster ``` lagouCluster:PRIMARY> rs.status() { "set" : "lagouCluster", "date" : ISODate("2022-01-28T06:32:02.633Z"), "myState" : 1, "term" : NumberLong(4), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "heartbeatIntervalMillis" : NumberLong(2000), "majorityVoteCount" : 3, "writeMajorityCount" : 3, "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1643351517, 1), "t" : NumberLong(4) }, "lastCommittedWallTime" : ISODate("2022-01-28T06:31:57.065Z"), "readConcernMajorityOpTime" : { "ts" : Timestamp(1643351517, 1), "t" : NumberLong(4) }, "readConcernMajorityWallTime" : ISODate("2022-01-28T06:31:57.065Z"), "appliedOpTime" : { "ts" : Timestamp(1643351517, 1), "t" : NumberLong(4) }, "durableOpTime" : { "ts" : Timestamp(1643351517, 1), "t" : NumberLong(4) }, "lastAppliedWallTime" : ISODate("2022-01-28T06:31:57.065Z"), "lastDurableWallTime" : ISODate("2022-01-28T06:31:57.065Z") }, "lastStableRecoveryTimestamp" : Timestamp(1643351497, 1), "lastStableCheckpointTimestamp" : Timestamp(1643351497, 1), "electionCandidateMetrics" : { "lastElectionReason" : "electionTimeout", "lastElectionDate" : ISODate("2022-01-28T05:30:56.433Z"), "electionTerm" : NumberLong(4), "lastCommittedOpTimeAtElection" : { "ts" : Timestamp(0, 0), "t" : NumberLong(-1) }, "lastSeenOpTimeAtElection" : { "ts" : Timestamp(1643347569, 1), "t" : NumberLong(3) }, "numVotesNeeded" : 3, "priorityAtElection" : 1, "electionTimeoutMillis" : NumberLong(10000), "numCatchUpOps" : NumberLong(0), "newTermStartDate" : ISODate("2022-01-28T05:30:56.448Z"), "wMajorityWriteAvailabilityDate" : ISODate("2022-01-28T05:30:57.897Z") }, "members" : [ { "_id" : 1, "name" : "192.168.174.135:37011", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 3678, "optime" : { "ts" : Timestamp(1643351517, 1), "t" : NumberLong(4) }, "optimeDate" : ISODate("2022-01-28T06:31:57Z"), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "electionTime" : Timestamp(1643347856, 1), "electionDate" : ISODate("2022-01-28T05:30:56Z"), "configVersion" : 1, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 2, "name" : "192.168.174.135:37013", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 3671, "optime" : { "ts" : Timestamp(1643351517, 1), "t" : NumberLong(4) }, "optimeDurable" : { "ts" : Timestamp(1643351517, 1), "t" : NumberLong(4) }, "optimeDate" : ISODate("2022-01-28T06:31:57Z"), "optimeDurableDate" : ISODate("2022-01-28T06:31:57Z"), "lastHeartbeat" : ISODate("2022-01-28T06:32:01.789Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:32:02.145Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.174.135:37011", "syncSourceHost" : "192.168.174.135:37011", "syncSourceId" : 1, "infoMessage" : "", "configVersion" : 1 }, { "_id" : 3, "name" : "192.168.174.135:37015", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 3666, "optime" : { "ts" : Timestamp(1643351517, 1), "t" : NumberLong(4) }, "optimeDurable" : { "ts" : Timestamp(1643351517, 1), "t" : NumberLong(4) }, "optimeDate" : ISODate("2022-01-28T06:31:57Z"), "optimeDurableDate" : ISODate("2022-01-28T06:31:57Z"), "lastHeartbeat" : ISODate("2022-01-28T06:32:01.789Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:32:00.886Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.174.135:37013", "syncSourceHost" : "192.168.174.135:37013", "syncSourceId" : 2, "infoMessage" : "", "configVersion" : 1 }, { "_id" : 4, "name" : "192.168.174.135:37017", "health" : 1, "state" : 7, "stateStr" : "ARBITER", "uptime" : 3662, "lastHeartbeat" : ISODate("2022-01-28T06:32:01.148Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:32:00.838Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "configVersion" : 1 } ], "ok" : 1, "$gleStats" : { "lastOpTime" : Timestamp(0, 0), "electionId" : ObjectId("7fffffff0000000000000004") }, "lastCommittedOpTime" : Timestamp(1643351517, 1), "$configServerState" : { "opTime" : { "ts" : Timestamp(1643351514, 1), "t" : NumberLong(3) } }, "$clusterTime" : { "clusterTime" : Timestamp(1643351517, 1), "signature" : { "hash" : BinData(0,"DJ2dK9XYNDCFo+Li3emgyy2HovI="), "keyId" : NumberLong("7058087110917488672") } }, "operationTime" : Timestamp(1643351517, 1) } ``` #### 分片2-lagouCluster2 ``` { "set" : "lagouCluster2", "date" : ISODate("2022-01-28T06:29:45.656Z"), "myState" : 1, "term" : NumberLong(4), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "heartbeatIntervalMillis" : NumberLong(2000), "majorityVoteCount" : 3, "writeMajorityCount" : 3, "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1643351381, 1), "t" : NumberLong(4) }, "lastCommittedWallTime" : ISODate("2022-01-28T06:29:41.325Z"), "readConcernMajorityOpTime" : { "ts" : Timestamp(1643351381, 1), "t" : NumberLong(4) }, "readConcernMajorityWallTime" : ISODate("2022-01-28T06:29:41.325Z"), "appliedOpTime" : { "ts" : Timestamp(1643351381, 1), "t" : NumberLong(4) }, "durableOpTime" : { "ts" : Timestamp(1643351381, 1), "t" : NumberLong(4) }, "lastAppliedWallTime" : ISODate("2022-01-28T06:29:41.325Z"), "lastDurableWallTime" : ISODate("2022-01-28T06:29:41.325Z") }, "lastStableRecoveryTimestamp" : Timestamp(1643351331, 1), "lastStableCheckpointTimestamp" : Timestamp(1643351331, 1), "electionCandidateMetrics" : { "lastElectionReason" : "electionTimeout", "lastElectionDate" : ISODate("2022-01-28T05:35:10.737Z"), "electionTerm" : NumberLong(4), "lastCommittedOpTimeAtElection" : { "ts" : Timestamp(0, 0), "t" : NumberLong(-1) }, "lastSeenOpTimeAtElection" : { "ts" : Timestamp(1643347565, 1), "t" : NumberLong(3) }, "numVotesNeeded" : 3, "priorityAtElection" : 1, "electionTimeoutMillis" : NumberLong(10000), "numCatchUpOps" : NumberLong(0), "newTermStartDate" : ISODate("2022-01-28T05:35:10.764Z"), "wMajorityWriteAvailabilityDate" : ISODate("2022-01-28T05:35:11.972Z") }, "members" : [ { "_id" : 1, "name" : "192.168.174.135:47011", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 3285, "optime" : { "ts" : Timestamp(1643351381, 1), "t" : NumberLong(4) }, "optimeDurable" : { "ts" : Timestamp(1643351381, 1), "t" : NumberLong(4) }, "optimeDate" : ISODate("2022-01-28T06:29:41Z"), "optimeDurableDate" : ISODate("2022-01-28T06:29:41Z"), "lastHeartbeat" : ISODate("2022-01-28T06:29:45.450Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:29:43.914Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.174.135:47015", "syncSourceHost" : "192.168.174.135:47015", "syncSourceId" : 3, "infoMessage" : "", "configVersion" : 1 }, { "_id" : 2, "name" : "192.168.174.135:47013", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 3289, "optime" : { "ts" : Timestamp(1643351381, 1), "t" : NumberLong(4) }, "optimeDate" : ISODate("2022-01-28T06:29:41Z"), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "electionTime" : Timestamp(1643348110, 1), "electionDate" : ISODate("2022-01-28T05:35:10Z"), "configVersion" : 1, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 3, "name" : "192.168.174.135:47015", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 3280, "optime" : { "ts" : Timestamp(1643351381, 1), "t" : NumberLong(4) }, "optimeDurable" : { "ts" : Timestamp(1643351381, 1), "t" : NumberLong(4) }, "optimeDate" : ISODate("2022-01-28T06:29:41Z"), "optimeDurableDate" : ISODate("2022-01-28T06:29:41Z"), "lastHeartbeat" : ISODate("2022-01-28T06:29:45.599Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:29:43.782Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.174.135:47013", "syncSourceHost" : "192.168.174.135:47013", "syncSourceId" : 2, "infoMessage" : "", "configVersion" : 1 }, { "_id" : 4, "name" : "192.168.174.135:47017", "health" : 1, "state" : 7, "stateStr" : "ARBITER", "uptime" : 3270, "lastHeartbeat" : ISODate("2022-01-28T06:29:45.599Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:29:43.750Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "configVersion" : 1 } ], "ok" : 1, "$gleStats" : { "lastOpTime" : Timestamp(0, 0), "electionId" : ObjectId("7fffffff0000000000000004") }, "lastCommittedOpTime" : Timestamp(1643351381, 1), "$configServerState" : { "opTime" : { "ts" : Timestamp(1643351376, 1), "t" : NumberLong(3) } }, "$clusterTime" : { "clusterTime" : Timestamp(1643351381, 1), "signature" : { "hash" : BinData(0,"6DKXomZLEuQjpgiUbb/woGa9Lec="), "keyId" : NumberLong("7058087110917488672") } }, "operationTime" : Timestamp(1643351381, 1) } ``` #### 分片3-lagouCluster3 ``` lagouCluster3:SECONDARY> rs.status() { "set" : "lagouCluster3", "date" : ISODate("2022-01-28T06:31:35.324Z"), "myState" : 2, "term" : NumberLong(5), "syncingTo" : "192.168.174.135:57015", "syncSourceHost" : "192.168.174.135:57015", "syncSourceId" : 3, "heartbeatIntervalMillis" : NumberLong(2000), "majorityVoteCount" : 3, "writeMajorityCount" : 3, "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1643351495, 1), "t" : NumberLong(5) }, "lastCommittedWallTime" : ISODate("2022-01-28T06:31:35.294Z"), "readConcernMajorityOpTime" : { "ts" : Timestamp(1643351495, 1), "t" : NumberLong(5) }, "readConcernMajorityWallTime" : ISODate("2022-01-28T06:31:35.294Z"), "appliedOpTime" : { "ts" : Timestamp(1643351495, 1), "t" : NumberLong(5) }, "durableOpTime" : { "ts" : Timestamp(1643351495, 1), "t" : NumberLong(5) }, "lastAppliedWallTime" : ISODate("2022-01-28T06:31:35.294Z"), "lastDurableWallTime" : ISODate("2022-01-28T06:31:35.294Z") }, "lastStableRecoveryTimestamp" : Timestamp(1643351475, 1), "lastStableCheckpointTimestamp" : Timestamp(1643351475, 1), "members" : [ { "_id" : 1, "name" : "192.168.174.135:57011", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 3262, "optime" : { "ts" : Timestamp(1643351495, 1), "t" : NumberLong(5) }, "optimeDate" : ISODate("2022-01-28T06:31:35Z"), "syncingTo" : "192.168.174.135:57015", "syncSourceHost" : "192.168.174.135:57015", "syncSourceId" : 3, "infoMessage" : "", "configVersion" : 1, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 2, "name" : "192.168.174.135:57013", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 3251, "optime" : { "ts" : Timestamp(1643351485, 1), "t" : NumberLong(5) }, "optimeDurable" : { "ts" : Timestamp(1643351485, 1), "t" : NumberLong(5) }, "optimeDate" : ISODate("2022-01-28T06:31:25Z"), "optimeDurableDate" : ISODate("2022-01-28T06:31:25Z"), "lastHeartbeat" : ISODate("2022-01-28T06:31:34.874Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:31:33.778Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "electionTime" : Timestamp(1643348254, 1), "electionDate" : ISODate("2022-01-28T05:37:34Z"), "configVersion" : 1 }, { "_id" : 3, "name" : "192.168.174.135:57015", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 3245, "optime" : { "ts" : Timestamp(1643351485, 1), "t" : NumberLong(5) }, "optimeDurable" : { "ts" : Timestamp(1643351485, 1), "t" : NumberLong(5) }, "optimeDate" : ISODate("2022-01-28T06:31:25Z"), "optimeDurableDate" : ISODate("2022-01-28T06:31:25Z"), "lastHeartbeat" : ISODate("2022-01-28T06:31:34.504Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:31:34.198Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.174.135:57013", "syncSourceHost" : "192.168.174.135:57013", "syncSourceId" : 2, "infoMessage" : "", "configVersion" : 1 }, { "_id" : 4, "name" : "192.168.174.135:57017", "health" : 1, "state" : 7, "stateStr" : "ARBITER", "uptime" : 3240, "lastHeartbeat" : ISODate("2022-01-28T06:31:34.719Z"), "lastHeartbeatRecv" : ISODate("2022-01-28T06:31:35.112Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "configVersion" : 1 } ], "ok" : 1, "$gleStats" : { "lastOpTime" : Timestamp(0, 0), "electionId" : ObjectId("000000000000000000000000") }, "lastCommittedOpTime" : Timestamp(1643351495, 1), "$configServerState" : { "opTime" : { "ts" : Timestamp(1643351476, 1), "t" : NumberLong(3) } }, "$clusterTime" : { "clusterTime" : Timestamp(1643351495, 1), "signature" : { "hash" : BinData(0,"dvvSHWe9kxh+Vtw0FT0anoo6Cns="), "keyId" : NumberLong("7058087110917488672") } }, "operationTime" : Timestamp(1643351495, 1) } ```