您的位置:首页 > 数据库 > Mongodb

Mongodb复制集切换时设置复制集成员优先级

2013-06-13 15:20 597 查看
设置复制集成员优先级
通常在切换时,我们需要将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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: