设置复制集成员优先级
通常在切换时,我们需要将primary切换到指定db,此时需要指定不同db的优先级,根据优先级的不同在投票时会优先将级别高的切换为primary
登陆到primary
Replset中member的默认优先级为1,区间是1-100,0表示该db只能为secondary,不能变为主
> var c = rs.conf();
rs0:SECONDARY> c
{
"_id" : "rs0",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" :"127.0.0.1:27017"
},
{
"_id" : 1,
"host": "127.0.0.1:27018"
},
{
"_id" : 2,
"host" :"127.0.0.1:27019"
}
]
}
rs0:SECONDARY> c.members[2].priority = 3
3
rs0:PRIMARY> c.members[1].priority = 2
2
rs0:PRIMARY> c.members[0].priority = 1
1
rs0:PRIMARY> c
{
"_id" : "rs0",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" :"127.0.0.1:27017",
"priority" :1
},
{
"_id" : 1,
"host" :"127.0.0.1:27018",
"priority" :2
},
{
"_id" : 2,
"host" :"127.0.0.1:27019",
"priority" :3
}
]
}
rs0:PRIMARY> rs.reconfig(c);
Fri Sep 28 10:56:51 DBClientCursor::initcall() failed
Fri Sep 28 10:56:51 query failed :admin.$cmd { replSetReconfig: { _id: "rs0", version: 2, members: [ {_id: 0, host: "127.0.0.1:27017", priority: 1.0 }, { _id: 1, host:"127.0.0.1:27018", priority: 2.0 }, { _id: 2, host:"127.0.0.1:27019", priority: 3.0 } ] } } to: localhost:27017
Fri Sep 28 10:56:51 trying reconnect tolocalhost:27017
Fri Sep 28 10:56:51 reconnectlocalhost:27017 ok
reconnected to server after rs command(which is normal)