Mongodb副本集--切换主从节点-调整优先级
2022/3/4 19:15:18
本文主要是介绍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
这篇关于Mongodb副本集--切换主从节点-调整优先级的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-12Cargo deny安装指路
- 2024-11-02MongoDB项目实战:从入门到初级应用
- 2024-11-01随时随地一键转录,Google Cloud 新模型 Chirp 2 让语音识别更上一层楼
- 2024-10-25Google Cloud动手实验详解:如何在Cloud Run上开发无服务器应用
- 2024-10-24AI ?先驱齐聚 BAAI 2024,发布大规模语言、多模态、具身、生物计算以及 FlagOpen 2.0 等 AI 模型创新成果。
- 2024-10-20goland工具下,如修改一个项目的标准库SDK的版本-icode9专业技术文章分享
- 2024-10-17Go学习:初学者的简单教程
- 2024-10-17Go学习:新手入门完全指南
- 2024-10-17Golang学习:初学者入门教程
- 2024-10-17Golang学习:新手入门教程