<span>mongodb的副本集方法</span>

 

 

 

 

方法名 描述
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> 

 

 

 

 

 

 

 

 

 

##################################

全部评论

相关推荐

uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
06-13 17:33
门头沟学院 Java
顺序不记了,大致顺序是这样的,有的相同知识点写分开了1.基本数据类型2.基本数据类型和包装类型的区别3.==和equals区别4.ArrayList与LinkedList区别5.hashmap底层原理,put操作时会发生什么6.说出几种树型数据结构7.B树和B+树区别8.jvm加载类机制9.线程池核心参数10.创建线程池的几种方式11.callable与runnable区别12.线程池怎么回收线程13.redis三剑客14.布隆过滤器原理,不要背八股,说说真正使用时遇到了问题没有(我说没有,不知道该怎么回答了)15.堆的内存结构16.自己在写项目时有没有遇见过oom,如何处理,不要背八股,根据真实经验,我说不会17.redis死锁怎么办,watchdog机制如何发现是否锁过期18.如何避免redis红锁19.一个表性别与年龄如何加索引20.自己的项目的QPS怎么测的,有没有真正遇到大数量表21.说一说泛型22.springboot自动装配原理23.springmvc与springboot区别24.aop使用过嘛?动态代理与静态代理区别25.spring循环依赖怎么解决26.你说用过es,es如何分片,怎么存的数据,1000万条数据怎么写入库中27.你说用limit,那么在数据量大之后,如何优化28.rabbitmq如何批次发送,批量读取,答了延迟队列和线程池,都不对29.计网知不知道smtp协议,不知道写了对不对,完全听懵了30.springcloud知道嘛?只是了解反问1.做什么的?短信服务,信息量能到千万级2.对我的建议,基础不错,但是不要只背八股,多去实际开发中理解。面试官人不错,虽然没露脸,但是中间会引导我回答问题,不会的也只是说对我要求没那么高。面完问我在济宁生活有没有困难,最快什么时候到,让人事给我聊薪资了。下午人事打电话,问我27届的会不会跑路,还在想办法如何使我不跑路,不想扣我薪资等。之后我再联系吧,还挺想去的😭,我真不跑路哥😢附一张河科大幽默大专图,科大就是大专罢了
查看30道真题和解析
点赞 评论 收藏
分享
白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务