MongoDB中怎么切換副本集

MongoDB中怎么切換副本集,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

成都創(chuàng)新互聯(lián)公司專注于企業(yè)成都全網(wǎng)營(yíng)銷推廣、網(wǎng)站重做改版、泰和網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5建站、商城系統(tǒng)網(wǎng)站開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為泰和等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

MongoDB 副本集切換方法

1、rs.stepDown([stepdownSecs, catchUpSecs])   step down as primary (disconnects)

   操作步驟如下:

   [root@127-0-0-1 conf]# mongo --port 2777

    shard1:PRIMARY> show dbs

    admin   0.000GB

    config  0.000GB

    local   0.001GB

    yoon    0.000GB

    shard1: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.

    shard1:PRIMARY> rs.stepDown()   #這個(gè)命令會(huì)讓primary降級(jí)為Secondary節(jié)點(diǎn)

    shard1:PRIMARY> rs.stepDown(30) #這個(gè)命令會(huì)讓primary降級(jí)為Secondary節(jié)點(diǎn)并維持30S,如果這段時(shí)間沒有新的primary選舉出來,這個(gè)節(jié)點(diǎn)重新加入進(jìn)行選舉

2、通過設(shè)置優(yōu)先級(jí)

   A.為了保證數(shù)據(jù)的一致性,必須先關(guān)閉應(yīng)用的寫服務(wù)

   B.提升要升級(jí)為primary節(jié)點(diǎn)的Secondary節(jié)點(diǎn)的優(yōu)先級(jí)

   操作如下:

   查看當(dāng)前配置信息:

   shard1:PRIMARY> rs.conf()

{

"_id" : "shard1",

"version" : 4,

"protocolVersion" : NumberLong(1),

"writeConcernMajorityJournalDefault" : true,

"members" : [

{

"_id" : 0,

"host" : "127.0.0.1:2777",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 3,

"tags" : {

},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 1,

"host" : "127.0.0.1:3777",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 1,

"tags" : {

},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 2,

"host" : "127.0.0.1:4777",

"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("5f27de76c8d22581cdeb2f2e")

}

}

     shard1:PRIMARY> config=rs.conf()    # 查看當(dāng)前配置,存入config變量中

     shard1:PRIMARY> config.members[2].priority = 3   # 修改config變量,將第三組端口為4777的成員優(yōu)先級(jí)設(shè)置為3

     shard1:PRIMARY> rs.reconfig(config)   # 配置生效

     shard1:PRIMARY> db.isMaster()

{

"hosts" : [

"127.0.0.1:2777",

"127.0.0.1:3777",

"127.0.0.1:4777"

],

"setName" : "shard1",

"setVersion" : 7,

"ismaster" : true,

"secondary" : false,

"primary" : "127.0.0.1:4777",    

"me" : "127.0.0.1:4777",

"electionId" : ObjectId("7fffffff0000000000000004"),

"lastWrite" : {

"opTime" : {

"ts" : Timestamp(1596599298, 1),

"t" : NumberLong(4)

},

"lastWriteDate" : ISODate("2020-08-05T03:48:18Z"),

"majorityOpTime" : {

"ts" : Timestamp(1596599298, 1),

"t" : NumberLong(4)

},

"majorityWriteDate" : ISODate("2020-08-05T03:48:18Z")

}..

...

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。

新聞名稱:MongoDB中怎么切換副本集
標(biāo)題URL:http://bm7419.com/article44/phdiee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、小程序開發(fā)、品牌網(wǎng)站設(shè)計(jì)網(wǎng)站改版、、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司