这篇文章主要介绍MongoDB如何修改副本集节点的优先值,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
复制集节点的优先级影响了 elections 的结果。我们通过设置不同的优先级来提高部分节点成为主节点的可能性,也可以让某些节点不能成为主节点。
具体设置如下:
登陆主节点:
test:PRIMARY> cfg = rs.conf()
{
"_id" : "test",
"version" : 4,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "192.168.0.51:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "192.168.0.52:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "192.168.0.53:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 3,
"host" : "192.168.0.52:27019",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 60000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5a94ff92bf8f7ba59f48e552")
}
}
修改节点优先值:
test:PRIMARY> cfg.members[0].priority = 1
1
test:PRIMARY> cfg.members[0].priority = 3
3
test:PRIMARY> cfg.members[1].priority = 2
2
test:PRIMARY> cfg.members[2].priority = 1
1
应用配置:
test:PRIMARY> rs.reconfig(cfg)
{ "ok" : 1 }
test:PRIMARY>
以上是“MongoDB如何修改副本集节点的优先值”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!