1、需求與現有副本集情況介紹
背景:業務側針對MongoDB副本集的一個Secondary節點B進行了改配操作,由于改配后的B節點,配置高,性能好,業務想以最短的時間,最小的代價把B節點提升為Primary主節點。
現有MongoDB 5節點副本集集群采用UCloud云數據庫,節點信息如下:即節點A:192.168.0.182 Primary節點;B:192.168.0.240 Secondary節點;C:192.168.0.217 Secondary節點;D:192.168.0.60;E:192.168.0.145 arbiter節點。
2、配置調整
(1)查看當前副本集角色
udb-a0r3omr444m:PRIMARY> rs.status() { "set" : "udb-a0r3omr444m", "date" : ISODate("2022-10-01T05:53:11.213Z"), "myState" : 1, "term" : NumberLong(1), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "heartbeatIntervalMillis" : NumberLong(2000), "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "readConcernMajorityOpTime" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "appliedOpTime" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "durableOpTime" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) } }, "lastStableCheckpointTimestamp" : Timestamp(1664603543, 1), "members" : [ { "_id" : 0, "name" : "192.168.0.182:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 786, "optime" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-10-01T05:53:03Z"), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "electionTime" : Timestamp(1664602821, 2), "electionDate" : ISODate("2022-10-01T05:40:21Z"), "configVersion" : 5, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 1, "name" : "192.168.0.240:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 729, "optime" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "optimeDurable" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-10-01T05:53:03Z"), "optimeDurableDate" : ISODate("2022-10-01T05:53:03Z"), "lastHeartbeat" : ISODate("2022-10-01T05:53:09.400Z"), "lastHeartbeatRecv" : ISODate("2022-10-01T05:53:09.907Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.0.182:27017", "syncSourceHost" : "192.168.0.182:27017", "syncSourceId" : 0, "infoMessage" : "", "configVersion" : 5 }, { "_id" : 2, "name" : "192.168.0.145:27017", "health" : 1, "state" : 7, "stateStr" : "ARBITER", "uptime" : 724, "lastHeartbeat" : ISODate("2022-10-01T05:53:09.384Z"), "lastHeartbeatRecv" : ISODate("2022-10-01T05:53:09.410Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "", "configVersion" : 5 }, { "_id" : 3, "name" : "192.168.0.217:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 686, "optime" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "optimeDurable" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-10-01T05:53:03Z"), "optimeDurableDate" : ISODate("2022-10-01T05:53:03Z"), "lastHeartbeat" : ISODate("2022-10-01T05:53:09.379Z"), "lastHeartbeatRecv" : ISODate("2022-10-01T05:53:09.910Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.0.182:27017", "syncSourceHost" : "192.168.0.182:27017", "syncSourceId" : 0, "infoMessage" : "", "configVersion" : 5 }, { "_id" : 4, "name" : "192.168.0.60:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 685, "optime" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "optimeDurable" : { "ts" : Timestamp(1664603583, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-10-01T05:53:03Z"), "optimeDurableDate" : ISODate("2022-10-01T05:53:03Z"), "lastHeartbeat" : ISODate("2022-10-01T05:53:09.408Z"), "lastHeartbeatRecv" : ISODate("2022-10-01T05:53:09.956Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "192.168.0.240:27017", "syncSourceHost" : "192.168.0.240:27017", "syncSourceId" : 1, "infoMessage" : "", "configVersion" : 5 } ], "ok" : 1, "operationTime" : Timestamp(1664603583, 1), "$clusterTime" : { "clusterTime" : Timestamp(1664603583, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
(2)C節點凍結120s
[root@blogs-v2 ~]# mongo 192.168.0.217:27017/admin -u root -p MongoDB shell version v4.0.27 Enter password: connecting to: mongodb://192.168.0.217:27017/admin?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("b0714374-1a2a-41f5-9592-9a5ee8f18c2d") } MongoDB server version: 4.0.3 udb-a0r3omr444m:SECONDARY> udb-a0r3omr444m:SECONDARY> rs.freeze(120) # C節點凍結120s { "ok" : 1, "operationTime" : Timestamp(1664603883, 1), "$clusterTime" : { "clusterTime" : Timestamp(1664603883, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
(3)D節點凍結120s
[root@blogs-v2 ~]# mongo 192.168.0.60:27017/admin -u root -p MongoDB shell version v4.0.27 Enter password: connecting to: mongodb://192.168.0.60:27017/admin?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("184f5eff-bfa9-4db9-87ab-54911a6897ff") } MongoDB server version: 4.0.3 udb-a0r3omr444m:SECONDARY> udb-a0r3omr444m:SECONDARY> rs.freeze(120) # D節點凍結120s { "ok" : 1, "operationTime" : Timestamp(1664603883, 1), "$clusterTime" : { "clusterTime" : Timestamp(1664603883, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
(4)A節點降級120s
[root@blogs-v2 ~]# mongo 192.168.0.182:27017/admin -u root -p MongoDB shell version v4.0.27 Enter password: connecting to: mongodb://192.168.0.182:27017/admin?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("cf937160-092d-4073-8788-562e7b928d50") } MongoDB server version: 4.0.3 udb-a0r3omr444m:PRIMARY> udb-a0r3omr444m:PRIMARY> rs.stepDown(120) # 降級當前主節點,120s內不參與選舉 2022-10-01T13:57:13.566+0800 I NETWORK [js] DBClientConnection failed to receive message from 192.168.0.182:27017 - HostUnreachable: Connection closed by peer 2022-10-01T13:57:13.566+0800 E QUERY [js] Error: error doing query: failed: network error while attempting to run command 'replSetStepDown' on host '192.168.0.182:27017' : DB.prototype.runCommand@src/mongo/shell/db.js:170:1 DB.prototype.adminCommand@src/mongo/shell/db.js:187:1 rs.stepDown@src/mongo/shell/utils.js:1505:12 @(shell):1:1 2022-10-01T13:57:13.568+0800 I NETWORK [js] trying reconnect to 192.168.0.182:27017 failed 2022-10-01T13:57:13.572+0800 I NETWORK [js] reconnect 192.168.0.182:27017 ok
(5)查看B節點選舉情況
[root@blogs-v2 ~]# mongo 192.168.0.240:27017/admin -u root -p MongoDB shell version v4.0.27 Enter password: connecting to: mongodb://192.168.0.240:27017/admin?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("3416021c-089e-4927-9c60-775a9a692b22") } MongoDB server version: 4.0.3 udb-a0r3omr444m:PRIMARY>
注:可以看出此時B節點已經是Primary節點了,選舉非常迅速!!!
(6)查看控制臺集群屬性
注:至此,MongoDB副本集節點切換完畢。
作者:UStarGao
鏈接:https://www.starcto.com/mongodb/310.html
來源:STARCTO
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/127859.html
摘要:版本目前支持和,用戶可以根據需求選擇相應的云數據庫版本。硬盤云數據庫的硬盤大小。云數據庫提供自動備份和手動備份兩種方式,防止數據丟失,避免誤操作帶來的風險。日志日志是用于記錄云數據庫操作事件的記錄文件。什么是云數據庫MongoDB?云數據庫簡介: 云數據庫MongoDB是基于成熟云計算技術的高可用、高性能的數據庫服務,完全兼容MongoDB 協議,支持靈活部署,除副本集實例架構外,云數據庫...
摘要:申明本文由筆者首發于深入淺出復制中文社區深入淺出復制由于自己開了,所以將之前比較好的文章挪過來便于大家瀏覽。新增由于網絡問題導致失敗重試機制。 申明 本文由筆者首發于InfoQ:《深入淺出MongoDB復制》MongoDB中文社區:《深入淺出MongoDB復制》 由于自己開了blog,所以將之前比較好的文章挪過來便于大家瀏覽。 綜述 筆者最近在生產環境中遇到許多復制相關問題,查閱網上資...
摘要:優志愿張海鵬宋體背景宋體每年月下旬到月下旬期間是高考填志愿的高峰期,也是優志愿后端面臨大流量高并發請求的業務高峰期。對于優志愿讀多寫少的場景及其業務高峰期,用戶可以按需增刪節點,更好地實現讀取性能的擴展。 隨著用戶規模的增長,數據庫的壓力也在成倍增加。面對大流量、高并發,UCloud MongoDB 做到了高效,并展現出了更好的性能體驗。 —— 優志愿 CTO 張海鵬 背景...
摘要:投票節點僅僅在選舉中進行投票。如下圖所示從節點無法升職為主節點的情況其他概念從節點還有集中特殊的設置情況,不同的設置有不同的需求優先級為設置,那么該結點將不能成為主節點,但是其數據仍是與主節點保持一致的而且應用程序也可以進行讀操作。 介紹 replicattion set 多臺服務器維護相同的數據副本,提高服務器的可用性,總結下來有以下好處: 數據備份與恢復 讀寫分離 MongoD...