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
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/127859.html
摘要:版本目前支持和,用户可以根据需求选择相应的云数据库版本。硬盘云数据库的硬盘大小。云数据库提供自动备份和手动备份两种方式,防止数据丢失,避免误操作带来的风险。日志日志是用于记录云数据库操作事件的记录文件。什么是云数据库MongoDB?云数据库简介: 云数据库MongoDB是基于成熟云计算技术的高可用、高性能的数据库服务,完全兼容MongoDB 协议,支持灵活部署,除副本集实例架构外,云数据库...
摘要:申明本文由笔者首发于深入浅出复制中文社区深入浅出复制由于自己开了,所以将之前比较好的文章挪过来便于大家浏览。新增由于网络问题导致失败重试机制。 申明 本文由笔者首发于InfoQ:《深入浅出MongoDB复制》MongoDB中文社区:《深入浅出MongoDB复制》 由于自己开了blog,所以将之前比较好的文章挪过来便于大家浏览。 综述 笔者最近在生产环境中遇到许多复制相关问题,查阅网上资...
摘要:优志愿张海鹏宋体背景宋体每年月下旬到月下旬期间是高考填志愿的高峰期,也是优志愿后端面临大流量高并发请求的业务高峰期。对于优志愿读多写少的场景及其业务高峰期,用户可以按需增删节点,更好地实现读取性能的扩展。 随着用户规模的增长,数据库的压力也在成倍增加。面对大流量、高并发,UCloud MongoDB 做到了高效,并展现出了更好的性能体验。 —— 优志愿 CTO 张海鹏 背景...
摘要:投票节点仅仅在选举中进行投票。如下图所示从节点无法升职为主节点的情况其他概念从节点还有集中特殊的设置情况,不同的设置有不同的需求优先级为设置,那么该结点将不能成为主节点,但是其数据仍是与主节点保持一致的而且应用程序也可以进行读操作。 介绍 replicattion set 多台服务器维护相同的数据副本,提高服务器的可用性,总结下来有以下好处: 数据备份与恢复 读写分离 MongoD...