1、需求與現(xiàn)有副本集情況介紹
背景:業(yè)務(wù)側(cè)針對(duì)MongoDB副本集的一個(gè)Secondary節(jié)點(diǎn)B進(jìn)行了改配操作,由于改配后的B節(jié)點(diǎn),配置高,性能好,業(yè)務(wù)想以最短的時(shí)間,最小的代價(jià)把B節(jié)點(diǎn)提升為Primary主節(jié)點(diǎn)。
現(xiàn)有MongoDB 5節(jié)點(diǎn)副本集集群采用UCloud云數(shù)據(jù)庫(kù),節(jié)點(diǎn)信息如下:即節(jié)點(diǎn)A:192.168.0.182 Primary節(jié)點(diǎn);B:192.168.0.240 Secondary節(jié)點(diǎn);C:192.168.0.217 Secondary節(jié)點(diǎn);D:192.168.0.60;E:192.168.0.145 arbiter節(jié)點(diǎn)。
2、配置調(diào)整
(1)查看當(dāng)前副本集角色
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節(jié)點(diǎn)凍結(jié)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節(jié)點(diǎn)凍結(jié)120s { "ok" : 1, "operationTime" : Timestamp(1664603883, 1), "$clusterTime" : { "clusterTime" : Timestamp(1664603883, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
(3)D節(jié)點(diǎn)凍結(jié)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節(jié)點(diǎn)凍結(jié)120s { "ok" : 1, "operationTime" : Timestamp(1664603883, 1), "$clusterTime" : { "clusterTime" : Timestamp(1664603883, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
(4)A節(jié)點(diǎn)降級(jí)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) # 降級(jí)當(dāng)前主節(jié)點(diǎn),120s內(nèi)不參與選舉 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節(jié)點(diǎn)選舉情況
[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>
注:可以看出此時(shí)B節(jié)點(diǎn)已經(jīng)是Primary節(jié)點(diǎn)了,選舉非常迅速!!!
(6)查看控制臺(tái)集群屬性
注:至此,MongoDB副本集節(jié)點(diǎn)切換完畢。
作者:UStarGao
鏈接:https://www.starcto.com/mongodb/310.html
來(lái)源:STARCTO
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.specialneedsforspecialkids.com/yun/127859.html
摘要:版本目前支持和,用戶可以根據(jù)需求選擇相應(yīng)的云數(shù)據(jù)庫(kù)版本。硬盤云數(shù)據(jù)庫(kù)的硬盤大小。云數(shù)據(jù)庫(kù)提供自動(dòng)備份和手動(dòng)備份兩種方式,防止數(shù)據(jù)丟失,避免誤操作帶來(lái)的風(fēng)險(xiǎn)。日志日志是用于記錄云數(shù)據(jù)庫(kù)操作事件的記錄文件。什么是云數(shù)據(jù)庫(kù)MongoDB?云數(shù)據(jù)庫(kù)簡(jiǎn)介: 云數(shù)據(jù)庫(kù)MongoDB是基于成熟云計(jì)算技術(shù)的高可用、高性能的數(shù)據(jù)庫(kù)服務(wù),完全兼容MongoDB 協(xié)議,支持靈活部署,除副本集實(shí)例架構(gòu)外,云數(shù)據(jù)庫(kù)...
摘要:申明本文由筆者首發(fā)于深入淺出復(fù)制中文社區(qū)深入淺出復(fù)制由于自己開(kāi)了,所以將之前比較好的文章挪過(guò)來(lái)便于大家瀏覽。新增由于網(wǎng)絡(luò)問(wèn)題導(dǎo)致失敗重試機(jī)制。 申明 本文由筆者首發(fā)于InfoQ:《深入淺出MongoDB復(fù)制》MongoDB中文社區(qū):《深入淺出MongoDB復(fù)制》 由于自己開(kāi)了blog,所以將之前比較好的文章挪過(guò)來(lái)便于大家瀏覽。 綜述 筆者最近在生產(chǎn)環(huán)境中遇到許多復(fù)制相關(guān)問(wèn)題,查閱網(wǎng)上資...
摘要:優(yōu)志愿張海鵬宋體背景宋體每年月下旬到月下旬期間是高考填志愿的高峰期,也是優(yōu)志愿后端面臨大流量高并發(fā)請(qǐng)求的業(yè)務(wù)高峰期。對(duì)于優(yōu)志愿讀多寫少的場(chǎng)景及其業(yè)務(wù)高峰期,用戶可以按需增刪節(jié)點(diǎn),更好地實(shí)現(xiàn)讀取性能的擴(kuò)展。 隨著用戶規(guī)模的增長(zhǎng),數(shù)據(jù)庫(kù)的壓力也在成倍增加。面對(duì)大流量、高并發(fā),UCloud MongoDB 做到了高效,并展現(xiàn)出了更好的性能體驗(yàn)。 —— 優(yōu)志愿 CTO 張海鵬 背景...
摘要:投票節(jié)點(diǎn)僅僅在選舉中進(jìn)行投票。如下圖所示從節(jié)點(diǎn)無(wú)法升職為主節(jié)點(diǎn)的情況其他概念從節(jié)點(diǎn)還有集中特殊的設(shè)置情況,不同的設(shè)置有不同的需求優(yōu)先級(jí)為設(shè)置,那么該結(jié)點(diǎn)將不能成為主節(jié)點(diǎn),但是其數(shù)據(jù)仍是與主節(jié)點(diǎn)保持一致的而且應(yīng)用程序也可以進(jìn)行讀操作。 介紹 replicattion set 多臺(tái)服務(wù)器維護(hù)相同的數(shù)據(jù)副本,提高服務(wù)器的可用性,總結(jié)下來(lái)有以下好處: 數(shù)據(jù)備份與恢復(fù) 讀寫分離 MongoD...