设置隐藏节点和不可投票节点
2023-04-24 08:53 abce 阅读(118) 评论(0) 编辑 收藏 举报配置隐藏节点
复制集中隐藏节点不能变成主,但是可以参加选举。
隐藏节点,最常用的场景是延迟复制。如果不想某个节点变成主节点,将priority设置成0即可
如果设置了settings.chainingAllowed,支持辅助节点从另外的复制节点做数据同步,mongodb默认是优先讯在非隐藏节点来做数据同步。如果想让辅助节点从隐藏节点同步数据,就要设置replSetSyncFrom做相应的修改。
设置隐藏节点,要将members[n].priority设置为0;members[n].hidden设置成true:
{ "_id" : <num> "host" : <hostname:port>, "priority" : 0, "hidden" : true }
配置过程:
cfg = rs.conf() cfg.members[0].priority = 0 cfg.members[0].hidden = true rs.reconfig(cfg)
members的数组下表是从0开始,不要与members[n]._id混淆了。
如果是新加成员
rs.add( { host: "192.168.137.11:27017", priority: 0, hidden: true } )
配置非不可投票节点
设置不可投票节点,要将members[n].priority设置为0;members[n].votes设置为0
cfg = rs.conf(); cfg.members[n].votes = 0; cfg.members[n].priority = 0; rs.reconfig(cfg);
如果是新加成员
rs.add( { host: "192.168.137.11:27017", priority: 0, votes: 0 } )
其它:
> cfg=rs.conf() { "_id" : "lq_mongo_rs", "version" : 1, "term" : 9, "members" : [ { "_id" : 0, "host" : "192.168.137.54:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "secondaryDelaySecs" : NumberLong(0), "votes" : 1 }, { "_id" : 1, "host" : "192.168.137.55:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "secondaryDelaySecs" : NumberLong(0), "votes" : 1 }, { "_id" : 2, "host" : "192.168.137.56:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "secondaryDelaySecs" : NumberLong(0), "votes" : 1 } ], "protocolVersion" : NumberLong(1), "writeConcernMajorityJournalDefault" : true, "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : -1, "catchUpTakeoverDelayMillis" : 30000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("63103236dd0aac4d38f820c0") } }