数据库
首页 > 数据库> > Mongodb副本集--切换主从节点-调整优先级

Mongodb副本集--切换主从节点-调整优先级

作者:互联网

 

思路:
1.为了保证数据的一致性,必须先关闭应用的写服务。
2.提升要升级为Primary节点的Secondary节点的优先级。

操作如下,在主节点上执行:

arps:PRIMARY> config=rs.conf() //查看当前配置,存入config变量中。
arps:PRIMARY> config.members[2].priority = 3 //修改config变量,第三组成员的优先级为3.
arps:PRIMARY> rs.reconfig(config) //配置生效 


arps:SECONDARY> rs.conf() //查看当前配置
{
"_id" : "arps",
"version" : 4,
"members" : [
{
"_id" : 0,
"host" : "172.17.4.37:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {

},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 1,
"host" : "172.17.4.38:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {

},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 2,
"host" : "172.17.4.39:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 3, //优先级变为3
"tags" : {

},
"slaveDelay" : 0,
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatTimeoutSecs" : 10,
"getLastErrorModes" : {

},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
}
}
}

arps:SECONDARY> rs.status()
{
"set" : "arps",
"date" : ISODate("2017-12-22T07:25:04.641Z"),
"myState" : 2,
"syncingTo" : "172.17.4.39:27017",
"members" : [
{
"_id" : 0,
"name" : "172.17.4.37:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 7597536,
"optime" : Timestamp(1513927481, 3),
"optimeDate" : ISODate("2017-12-22T07:24:41Z"),
"syncingTo" : "172.17.4.39:27017",
"configVersion" : 4,
"self" : true
},
{
"_id" : 1,
"name" : "172.17.4.38:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 7597426,
"optime" : Timestamp(1513927481, 3),
"optimeDate" : ISODate("2017-12-22T07:24:41Z"),
"lastHeartbeat" : ISODate("2017-12-22T07:25:02.961Z"),
"lastHeartbeatRecv" : ISODate("2017-12-22T07:25:04.091Z"),
"pingMs" : 0,
"syncingTo" : "172.17.4.39:27017",
"configVersion" : 4
},
{
"_id" : 2,
"name" : "172.17.4.39:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY", //最后一个节点升级为PRIMARY
"uptime" : 3202,
"optime" : Timestamp(1513927481, 3),
"optimeDate" : ISODate("2017-12-22T07:24:41Z"),
"lastHeartbeat" : ISODate("2017-12-22T07:25:02.951Z"),
"lastHeartbeatRecv" : ISODate("2017-12-22T07:25:04.344Z"),
"pingMs" : 0,
"electionTime" : Timestamp(1513927190, 2),
"electionDate" : ISODate("2017-12-22T07:19:50Z"),
"configVersion" : 4
}
],
"ok" : 1
}

 

注:
引用来源,请尽量阅读原来博客:来源: https://blog.csdn.net/zhangshengdongly/article/details/96427716?utm_term=mongodb%E5%89%AF%E6%9C%AC%E9%9B%86%E5%88%87%E6%8D%A2%E4%B8%BB%E4%BB%8E&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-0-96427716&spm=3001.4430

标签:12,优先级,--,Mongodb,27017,ISODate,172.17,22T07,2017
来源: https://www.cnblogs.com/leolzi/p/15962830.html