Mongodb

從 mongo 副本集中添加和刪除節點

  • January 30, 2020

我有一個新的備份伺服器,我想添加到我們的 mongo 副本集中。據我所知,它就像登錄到主副本集並添加以下命令一樣簡單:

rs.add( { host: "mongobackup:10003", priority: 0, votes: 0, hidden: true } )

我的理解是,在這樣做之後,主節點應該將其所有配置和數據與新節點同步。

此外,我有一個舊的備份伺服器,我想從副本集中刪除它,我所要做的就是在主副本集中輸入以下命令:

rs.remove( "oldmongobackup:10003" )

還有什麼我想念的嗎?

rs2:PRIMARY> rs.conf()
{
   "_id" : "rs2",
   "version" : 26,
   "members" : [
       {
           "_id" : 7,
           "host" : "mongo03:10001",
           "arbiterOnly" : false,
           "buildIndexes" : true,
           "hidden" : false,
           "priority" : 20,
           "tags" : {
               "dc" : "maid"
           },
           "slaveDelay" : 0,
           "votes" : 1
       },
       {
           "_id" : 8,
           "host" : "mongo01:10002",
           "arbiterOnly" : false,
           "buildIndexes" : true,
           "hidden" : false,
           "priority" : 10,
           "tags" : {
               "dc" : "maid"
           },
           "slaveDelay" : 0,
           "votes" : 1
       },
       {
           "_id" : 9,
           "host" : "mongo02:10003",
           "arbiterOnly" : true,
           "buildIndexes" : true,
           "hidden" : false,
           "priority" : 1,
           "tags" : {

           },
           "slaveDelay" : 0,
           "votes" : 1
       },
       {
           "_id" : 10,
           "host" : "oldmongobackup:10003",
           "arbiterOnly" : false,
           "buildIndexes" : true,
           "hidden" : true,
           "priority" : 0,
           "tags" : {

           },
           "slaveDelay" : 0,
           "votes" : 1
       }
   ],
   "settings" : {
       "chainingAllowed" : true,
       "heartbeatTimeoutSecs" : 10,
       "getLastErrorModes" : {

       },
       "getLastErrorDefaults" : {
           "w" : 1,
           "wtimeout" : 0
       }
   }
}

該命令應該可以正常執行。為什麼 ???

每一個都rs.add()應該rs.remove()觸發一次選舉。由於剩餘節點的優先級具有唯一值:

  • _id : 7作為priority : 20
  • _id : 8作為priority : 10
  • _id : 9作為priority : 1

你可以說選舉是被操縱的。主節點應保持為主節點。

引用自:https://dba.stackexchange.com/questions/258423