复制集节点的优先级影响了 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>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2151347/,如需转载,请注明出处,否则将追究法律责任。