环境:
OS:Centos7
mongodb:4.4.22
我们在副本集扩容的情况下,新加入节点一般设置priority和votes都为0,待新节点数据同步完成后再进行修改:
主库上执行新增新的节点:
myrepl:PRIMARY>rs.add({ host: "192.168.1.107:29001", priority: 0, votes: 0 })
待同步完成后查看副本集配置
myrepl:PRIMARY> rs.config() { "_id" : "myrepl", "version" : 23819, "protocolVersion" : NumberLong(1), "writeConcernMajorityJournalDefault" : true, "members" : [ { "_id" : 0, "host" : "192.168.1.102:29001", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 3, "host" : "192.168.1.105:29001", "arbiterOnly" : true, "buildIndexes" : true, "hidden" : false, "priority" : 0, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 4, "host" : "192.168.1.107:29001", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 0, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 0 } ], "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : -1, "catchUpTakeoverDelayMillis" : 30000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("64b0a3f881b811c4931d4d4c") } }
可以看到id=4的节点,priority和votes都为0,下面进行修改
members的下标数字对对应数组的序号(这里是0,1,2),我们这里是要修改数组序号为2的member
myrepl:PRIMARY>var cfg = rs.conf() myrepl:PRIMARY>cfg.members[2].priority = 1 myrepl:PRIMARY>cfg.members[2].votes = 1 myrepl:PRIMARY> rs.reconfig(cfg) { "ok" : 0, "errmsg" : "Rejecting reconfig where the new config has a PSA topology and the secondary is electable, but the old config contains only one writable node. Refer to https://docs.mongodb.com/manual/reference/method/rs.reconfigForPSASet/ for next steps on reconfiguring a PSA set.", "code" : 103, "codeName" : "NewReplicaSetConfigurationIncompatible" }
这里报错误了,提示说明psa拓扑不能使用这种方式修改,尝试使用如下方式修改
myrepl:PRIMARY>cfg = rs.conf(); myrepl:PRIMARY>cfg["members"] = [ { "_id" : 0, "host" : "192.168.1.102:29001", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 3, "host" : "192.168.1.105:29001", "arbiterOnly" : true, "buildIndexes" : true, "hidden" : false, "priority" : 0, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 4, "host" : "192.168.1.107:29001", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 } ] myrepl:PRIMARY> rs.reconfigForPSASet(2, cfg); Running first reconfig to give member at index 2 { votes: 1, priority: 0 } Running second reconfig to give member at index 2 { priority: 1 } { "ok" : 1 }
rs.reconfigForPSASet( memberIndex, config, { options } )的使用方法
memberIndex为member数组的序号
查看新配置
myrepl:PRIMARY> rs.conf() { "_id" : "myrepl", "version" : 23821, "protocolVersion" : NumberLong(1), "writeConcernMajorityJournalDefault" : true, "members" : [ { "_id" : 0, "host" : "192.168.1.102:29001", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 3, "host" : "192.168.1.105:29001", "arbiterOnly" : true, "buildIndexes" : true, "hidden" : false, "priority" : 0, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 4, "host" : "192.168.1.107:29001", "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("64b0a3f881b811c4931d4d4c") } }
标签:votes,副本,false,mongodb,PSA,priority,true,id,myrepl From: https://www.cnblogs.com/hxlasky/p/17559209.html