我的编程空间,编程开发者的网络收藏夹
学习永远不晚

MongoDB中怎么切换副本集故障

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

MongoDB中怎么切换副本集故障

MongoDB中怎么切换副本集故障,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

默认情况下主节点和从节点的优先级都为1,仲裁者为0,因为它不可参加选举。

查看集群配置

cjcmonset:PRIMARY> rs.conf()

{

"_id" : "cjcmonset",

"version" : 1,

"protocolVersion" : NumberLong(1),

"writeConcernMajorityJournalDefault" : true,

"members" : [

{

"_id" : 0,

"host" : "192.168.2.222:27017",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 1,

"tags" : {

},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 1,

"host" : "192.168.2.187:27017",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 1,

"tags" : {

},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 2,

"host" : "192.168.2.188:27017",

"arbiterOnly" : true,

"buildIndexes" : true,

"hidden" : false,

"priority" : 0,

"tags" : {

},

"slaveDelay" : NumberLong(0),

"votes" : 1

}

],

"settings" : {

"chainingAllowed" : true,

"heartbeatIntervalMillis" : 2000,

"heartbeatTimeoutSecs" : 10,

"electionTimeoutMillis" : 10000,

"catchUpTimeoutMillis" : -1,

"catchUpTakeoverDelayMillis" : 30000,

"getLastErrorModes" : {

},

"getLastErrorDefaults" : {

"w" : 1,

"wtimeout" : 0

},

"replicaSetId" : ObjectId("5e77148837ae69b4ab9b4870")

}

}

我将现有主节点2.222的优先级提高为5,目的是在主库故障恢复后可以自动将主库角色切换回来。

cjcmonset:PRIMARY> var rscfg=rs.conf()

cjcmonset:PRIMARY> rscfg.members[0].priority = 5

5

cjcmonset:PRIMARY> rs.reconfig(rscfg)

{

"ok" : 1,

"$clusterTime" : {

"clusterTime" : Timestamp(1584881617, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

},

"operationTime" : Timestamp(1584881617, 1)

}

查看一下状态,主库优先级别已经调到5

cjcmonset:PRIMARY> rs.conf()

{

"_id" : "cjcmonset",

"version" : 2,

"protocolVersion" : NumberLong(1),

"writeConcernMajorityJournalDefault" : true,

"members" : [

{

"_id" : 0,

"host" : "192.168.2.222:27017",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 5,

"tags" : {

},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 1,

"host" : "192.168.2.187:27017",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 1,

"tags" : {

},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 2,

"host" : "192.168.2.188:27017",

"arbiterOnly" : true,

"buildIndexes" : true,

"hidden" : false,

"priority" : 0,

"tags" : {

},

"slaveDelay" : NumberLong(0),

"votes" : 1

}

],

"settings" : {

"chainingAllowed" : true,

"heartbeatIntervalMillis" : 2000,

"heartbeatTimeoutSecs" : 10,

"electionTimeoutMillis" : 10000,

"catchUpTimeoutMillis" : -1,

"catchUpTakeoverDelayMillis" : 30000,

"getLastErrorModes" : {

},

"getLastErrorDefaults" : {

"w" : 1,

"wtimeout" : 0

},

"replicaSetId" : ObjectId("5e77148837ae69b4ab9b4870")

}

}

手动将将主节点(2.222)mongodo停掉,测试故障转移功能

cjcmonset:PRIMARY> use admin

switched to db admin

cjcmonset:PRIMARY> db.shutdownServer()

2020-03-22T20:59:39.419+0800 I  NETWORK  [js] DBClientConnection failed to receive message from 127.0.0.1:27017 - HostUnreachable: Connection closed by peer

server should be down...

2020-03-22T20:59:39.422+0800 I  NETWORK  [js] trying reconnect to 127.0.0.1:27017 failed

2020-03-22T20:59:39.423+0800 I  NETWORK  [js] reconnect 127.0.0.1:27017 failed failed 

在2.187节点查看集群状态,原主库187提示Connection refused,原从库2.187已经自动切换成主库。

查看集群状态

cjcmonset:PRIMARY> rs.status()

{

"set" : "cjcmonset",

"date" : ISODate("2020-03-22T13:00:33.838Z"),

"myState" : 1,

"term" : NumberLong(2),

"syncingTo" : "",

"syncSourceHost" : "",

"syncSourceId" : -1,

"heartbeatIntervalMillis" : NumberLong(2000),

"majorityVoteCount" : 2,

"writeMajorityCount" : 2,

"optimes" : {

"lastCommittedOpTime" : {

"ts" : Timestamp(1584881969, 1),

"t" : NumberLong(1)

},

"lastCommittedWallTime" : ISODate("2020-03-22T12:59:29.481Z"),

"readConcernMajorityOpTime" : {

"ts" : Timestamp(1584881969, 1),

"t" : NumberLong(1)

},

"readConcernMajorityWallTime" : ISODate("2020-03-22T12:59:29.481Z"),

"appliedOpTime" : {

"ts" : Timestamp(1584882028, 1),

"t" : NumberLong(2)

},

"durableOpTime" : {

"ts" : Timestamp(1584882028, 1),

"t" : NumberLong(2)

},

"lastAppliedWallTime" : ISODate("2020-03-22T13:00:28.344Z"),

"lastDurableWallTime" : ISODate("2020-03-22T13:00:28.344Z")

},

"lastStableRecoveryTimestamp" : Timestamp(1584881969, 1),

"lastStableCheckpointTimestamp" : Timestamp(1584881969, 1),

"electionCandidateMetrics" : {

"lastElectionReason" : "stepUpRequestSkipDryRun",

"lastElectionDate" : ISODate("2020-03-22T12:59:37.752Z"),

"electionTerm" : NumberLong(2),

"lastCommittedOpTimeAtElection" : {

"ts" : Timestamp(1584881969, 1),

"t" : NumberLong(1)

},

"lastSeenOpTimeAtElection" : {

"ts" : Timestamp(1584881969, 1),

"t" : NumberLong(1)

},

"numVotesNeeded" : 2,

"priorityAtElection" : 1,

"electionTimeoutMillis" : NumberLong(10000),

"priorPrimaryMemberId" : 0,

"numCatchUpOps" : NumberLong(0),

"newTermStartDate" : ISODate("2020-03-22T12:59:38.313Z")

},

"electionParticipantMetrics" : {

"votedForCandidate" : true,

"electionTerm" : NumberLong(1),

"lastVoteDate" : ISODate("2020-03-22T07:32:34.460Z"),

"electionCandidateMemberId" : 0,

"voteReason" : "",

"lastAppliedOpTimeAtElection" : {

"ts" : Timestamp(1584862345, 1),

"t" : NumberLong(-1)

},

"maxAppliedOpTimeInSet" : {

"ts" : Timestamp(1584862345, 1),

"t" : NumberLong(-1)

},

"priorityAtElection" : 1

},

"members" : [

{

"_id" : 0,

"name" : "192.168.2.222:27017",

"health" : 0,

"state" : 8,

"stateStr" : "(not reachable/healthy)",

"uptime" : 0,

"optime" : {

"ts" : Timestamp(0, 0),

"t" : NumberLong(-1)

},

"optimeDurable" : {

"ts" : Timestamp(0, 0),

"t" : NumberLong(-1)

},

"optimeDate" : ISODate("1970-01-01T00:00:00Z"),

"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),

"lastHeartbeat" : ISODate("2020-03-22T13:00:31.874Z"),

"lastHeartbeatRecv" : ISODate("2020-03-22T12:59:36.547Z"),

"pingMs" : NumberLong(0),

"lastHeartbeatMessage" : "Error connecting to 192.168.2.222:27017 :: caused by :: Connection refused",

"syncingTo" : "",

"syncSourceHost" : "",

"syncSourceId" : -1,

"infoMessage" : "",

"configVersion" : -1

},

{

"_id" : 1,

"name" : "192.168.2.187:27017",

"health" : 1,

"state" : 1,

"stateStr" : "PRIMARY",

"uptime" : 19745,

"optime" : {

"ts" : Timestamp(1584882028, 1),

"t" : NumberLong(2)

},

"optimeDate" : ISODate("2020-03-22T13:00:28Z"),

"syncingTo" : "",

"syncSourceHost" : "",

"syncSourceId" : -1,

"infoMessage" : "",

"electionTime" : Timestamp(1584881977, 1),

"electionDate" : ISODate("2020-03-22T12:59:37Z"),

"configVersion" : 2,

"self" : true,

"lastHeartbeatMessage" : ""

},

{

"_id" : 2,

"name" : "192.168.2.188:27017",

"health" : 1,

"state" : 7,

"stateStr" : "ARBITER",

"uptime" : 19689,

"lastHeartbeat" : ISODate("2020-03-22T13:00:31.872Z"),

"lastHeartbeatRecv" : ISODate("2020-03-22T13:00:32.657Z"),

"pingMs" : NumberLong(0),

"lastHeartbeatMessage" : "",

"syncingTo" : "",

"syncSourceHost" : "",

"syncSourceId" : -1,

"infoMessage" : "",

"configVersion" : 2

}

],

"ok" : 1,

"$clusterTime" : {

"clusterTime" : Timestamp(1584882028, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

},

"operationTime" : Timestamp(1584882028, 1)

}

手动启动2.222节点MongoDB

[root@cjcos conf]# mongod --config /usr/local/mongodb/conf/mongodb.conf

cjcmonset:SECONDARY> rs.status()

{

"set" : "cjcmonset",

"date" : ISODate("2020-03-22T13:02:32.499Z"),

"myState" : 2,

"term" : NumberLong(2),

"syncingTo" : "192.168.2.187:27017",

"syncSourceHost" : "192.168.2.187:27017",

"syncSourceId" : 1,

"heartbeatIntervalMillis" : NumberLong(2000),

"majorityVoteCount" : 2,

"writeMajorityCount" : 2,

"optimes" : {

"lastCommittedOpTime" : {

"ts" : Timestamp(1584882148, 1),

"t" : NumberLong(2)

},

"lastCommittedWallTime" : ISODate("2020-03-22T13:02:28.367Z"),

"readConcernMajorityOpTime" : {

"ts" : Timestamp(1584882148, 1),

"t" : NumberLong(2)

},

"readConcernMajorityWallTime" : ISODate("2020-03-22T13:02:28.367Z"),

"appliedOpTime" : {

"ts" : Timestamp(1584882148, 1),

"t" : NumberLong(2)

},

"durableOpTime" : {

"ts" : Timestamp(1584882148, 1),

"t" : NumberLong(2)

},

"lastAppliedWallTime" : ISODate("2020-03-22T13:02:28.367Z"),

"lastDurableWallTime" : ISODate("2020-03-22T13:02:28.367Z")

},

"lastStableRecoveryTimestamp" : Timestamp(1584881969, 1),

"lastStableCheckpointTimestamp" : Timestamp(1584881969, 1),

"members" : [

{

"_id" : 0,

"name" : "192.168.2.222:27017",

"health" : 1,

"state" : 2,

"stateStr" : "SECONDARY",

"uptime" : 13,

"optime" : {

"ts" : Timestamp(1584882148, 1),

"t" : NumberLong(2)

},

"optimeDate" : ISODate("2020-03-22T13:02:28Z"),

"syncingTo" : "192.168.2.187:27017",

"syncSourceHost" : "192.168.2.187:27017",

"syncSourceId" : 1,

"infoMessage" : "",

"configVersion" : 2,

"self" : true,

"lastHeartbeatMessage" : ""

},

{

"_id" : 1,

"name" : "192.168.2.187:27017",

"health" : 1,

"state" : 1,

"stateStr" : "PRIMARY",

"uptime" : 10,

"optime" : {

"ts" : Timestamp(1584882148, 1),

"t" : NumberLong(2)

},

"optimeDurable" : {

"ts" : Timestamp(1584882148, 1),

"t" : NumberLong(2)

},

"optimeDate" : ISODate("2020-03-22T13:02:28Z"),

"optimeDurableDate" : ISODate("2020-03-22T13:02:28Z"),

"lastHeartbeat" : ISODate("2020-03-22T13:02:31.498Z"),

"lastHeartbeatRecv" : ISODate("2020-03-22T13:02:31.261Z"),

"pingMs" : NumberLong(0),

"lastHeartbeatMessage" : "",

"syncingTo" : "",

"syncSourceHost" : "",

"syncSourceId" : -1,

"infoMessage" : "",

"electionTime" : Timestamp(1584881977, 1),

"electionDate" : ISODate("2020-03-22T12:59:37Z"),

"configVersion" : 2

},

{

"_id" : 2,

"name" : "192.168.2.188:27017",

"health" : 1,

"state" : 7,

"stateStr" : "ARBITER",

"uptime" : 10,

"lastHeartbeat" : ISODate("2020-03-22T13:02:31.496Z"),

"lastHeartbeatRecv" : ISODate("2020-03-22T13:02:32.014Z"),

"pingMs" : NumberLong(0),

"lastHeartbeatMessage" : "",

"syncingTo" : "",

"syncSourceHost" : "",

"syncSourceId" : -1,

"infoMessage" : "",

"configVersion" : 2

}

],

"ok" : 1,

"$clusterTime" : {

"clusterTime" : Timestamp(1584882148, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

},

"operationTime" : Timestamp(1584882148, 1)

}

因为设置了优先级,所以在启动2.222节点mongo后,很快2.222节点又会被重新选举为主节点,而2.187节点又变成从节点。

cjcmonset:SECONDARY> 

cjcmonset:PRIMARY> 

cjcmonset:PRIMARY> 

cjcmonset:PRIMARY> 

---2.222日志如下:

2020-03-22T21:02:33.946+0800 I  CONNPOOL [Replication] Connecting to 192.168.2.187:27017

2020-03-22T21:02:33.949+0800 I  REPL     [replexec-0] Member 192.168.2.187:27017 is now in state SECONDARY

2020-03-22T21:02:33.949+0800 I  REPL     [replexec-0] Caught up to the latest optime known via heartbeats after becoming primary. Target optime: { ts: Timestamp(1584882148, 1), t: 2 }. My Last Applied: { ts: Timestamp(1584882148, 1), t: 2 }

2020-03-22T21:02:33.949+0800 I  REPL     [replexec-0] Exited primary catch-up mode.

2020-03-22T21:02:33.949+0800 I  REPL     [replexec-0] Stopping replication producer

2020-03-22T21:02:33.949+0800 I  REPL     [rsBackgroundSync] Replication producer stopped after oplog fetcher finished returning a batch from our sync source.  Abandoning this batch of oplog entries and re-evaluating our sync source.

2020-03-22T21:02:34.592+0800 I  REPL     [ReplBatcher] Oplog buffer has been drained in term 3

2020-03-22T21:02:34.592+0800 I  REPL     [RstlKillOpThread] Starting to kill user operations

2020-03-22T21:02:34.592+0800 I  REPL     [RstlKillOpThread] Stopped killing user operations

2020-03-22T21:02:34.592+0800 I  REPL     [RstlKillOpThread] State transition ops metrics: { lastStateTransition: "stepUp", userOpsKilled: 0, userOpsRunning: 0 }

2020-03-22T21:02:34.593+0800 I  REPL     [rsSync-0] transition to primary complete; database writes are now permitted

2020-03-22T21:02:34.712+0800 I  REPL     [SyncSourceFeedback] SyncSourceFeedback error sending update to 192.168.2.187:27017: InvalidSyncSource: Sync source was cleared. Was 192.168.2.187:27017

2020-03-22T21:02:35.459+0800 I  NETWORK  [listener] connection accepted from 192.168.2.187:41810 #13 (6 connections now open)

2020-03-22T21:02:35.460+0800 I  NETWORK  [conn13] received client metadata from 192.168.2.187:41810 conn13: { driver: { name: "NetworkInterfaceTL", version: "4.2.3" }, os: { type: "Linux", name: "CentOS Linux release 7.5.1804 (Core) ", architecture: "x86_64", version: "Kernel 3.10.0-862.el7.x86_64" } }

2020-03-22T21:02:39.711+0800 I  CONNPOOL [RS] Ending connection to host 192.168.2.187:27017 due to bad connection status: CallbackCanceled: Callback was canceled; 1 connections to that host remain open

2020-03-22T21:02:43.944+0800 I  CONNPOOL [Replication] Ending connection to host 192.168.2.187:27017 due to bad connection status: CallbackCanceled: Callback was canceled; 1 connections to that host remain open

查看集群状态,2.187又重新变成主节点

cjcmonset:PRIMARY> rs.status()

{

"set" : "cjcmonset",

"date" : ISODate("2020-03-22T13:04:24.678Z"),

"myState" : 1,

"term" : NumberLong(3),

"syncingTo" : "",

"syncSourceHost" : "",

"syncSourceId" : -1,

"heartbeatIntervalMillis" : NumberLong(2000),

"majorityVoteCount" : 2,

"writeMajorityCount" : 2,

"optimes" : {

"lastCommittedOpTime" : {

"ts" : Timestamp(1584882264, 1),

"t" : NumberLong(3)

},

"lastCommittedWallTime" : ISODate("2020-03-22T13:04:24.632Z"),

"readConcernMajorityOpTime" : {

"ts" : Timestamp(1584882264, 1),

"t" : NumberLong(3)

},

"readConcernMajorityWallTime" : ISODate("2020-03-22T13:04:24.632Z"),

"appliedOpTime" : {

"ts" : Timestamp(1584882264, 1),

"t" : NumberLong(3)

},

"durableOpTime" : {

"ts" : Timestamp(1584882264, 1),

"t" : NumberLong(3)

},

"lastAppliedWallTime" : ISODate("2020-03-22T13:04:24.632Z"),

"lastDurableWallTime" : ISODate("2020-03-22T13:04:24.632Z")

},

"lastStableRecoveryTimestamp" : Timestamp(1584882254, 1),

"lastStableCheckpointTimestamp" : Timestamp(1584882254, 1),

"electionCandidateMetrics" : {

"lastElectionReason" : "priorityTakeover",

"lastElectionDate" : ISODate("2020-03-22T13:02:33.880Z"),

"electionTerm" : NumberLong(3),

"lastCommittedOpTimeAtElection" : {

"ts" : Timestamp(1584882148, 1),

"t" : NumberLong(2)

},

"lastSeenOpTimeAtElection" : {

"ts" : Timestamp(1584882148, 1),

"t" : NumberLong(2)

},

"numVotesNeeded" : 2,

"priorityAtElection" : 5,

"electionTimeoutMillis" : NumberLong(10000),

"priorPrimaryMemberId" : 1,

"numCatchUpOps" : NumberLong(0),

"newTermStartDate" : ISODate("2020-03-22T13:02:34.593Z"),

"wMajorityWriteAvailabilityDate" : ISODate("2020-03-22T13:02:35.462Z")

},

"members" : [

{

"_id" : 0,

"name" : "192.168.2.222:27017",

"health" : 1,

"state" : 1,

"stateStr" : "PRIMARY",

"uptime" : 125,

"optime" : {

"ts" : Timestamp(1584882264, 1),

"t" : NumberLong(3)

},

"optimeDate" : ISODate("2020-03-22T13:04:24Z"),

"syncingTo" : "",

"syncSourceHost" : "",

"syncSourceId" : -1,

"infoMessage" : "",

"electionTime" : Timestamp(1584882153, 1),

"electionDate" : ISODate("2020-03-22T13:02:33Z"),

"configVersion" : 2,

"self" : true,

"lastHeartbeatMessage" : ""

},

{

"_id" : 1,

"name" : "192.168.2.187:27017",

"health" : 1,

"state" : 2,

"stateStr" : "SECONDARY",

"uptime" : 122,

"optime" : {

"ts" : Timestamp(1584882254, 1),

"t" : NumberLong(3)

},

"optimeDurable" : {

"ts" : Timestamp(1584882254, 1),

"t" : NumberLong(3)

},

"optimeDate" : ISODate("2020-03-22T13:04:14Z"),

"optimeDurableDate" : ISODate("2020-03-22T13:04:14Z"),

"lastHeartbeat" : ISODate("2020-03-22T13:04:24.023Z"),

"lastHeartbeatRecv" : ISODate("2020-03-22T13:04:23.967Z"),

"pingMs" : NumberLong(0),

"lastHeartbeatMessage" : "",

"syncingTo" : "192.168.2.222:27017",

"syncSourceHost" : "192.168.2.222:27017",

"syncSourceId" : 0,

"infoMessage" : "",

"configVersion" : 2

},

{

"_id" : 2,

"name" : "192.168.2.188:27017",

"health" : 1,

"state" : 7,

"stateStr" : "ARBITER",

"uptime" : 122,

"lastHeartbeat" : ISODate("2020-03-22T13:04:24.019Z"),

"lastHeartbeatRecv" : ISODate("2020-03-22T13:04:24.112Z"),

"pingMs" : NumberLong(0),

"lastHeartbeatMessage" : "",

"syncingTo" : "",

"syncSourceHost" : "",

"syncSourceId" : -1,

"infoMessage" : "",

"configVersion" : 2

}

],

"ok" : 1,

"$clusterTime" : {

"clusterTime" : Timestamp(1584882264, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

},

"operationTime" : Timestamp(1584882264, 1)

}

187节点自动变成从节点

cjcmonset:PRIMARY> 

cjcmonset:PRIMARY> 

cjcmonset:SECONDARY> 

cjcmonset:SECONDARY> 

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

MongoDB中怎么切换副本集故障

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

MongoDB中怎么配置副本集

MongoDB中怎么配置副本集,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。环境准备三台服务器,地址分别是:192.168.248.128192.168.248.13519
2023-06-19

MongoDB的副本集与自动故障转移怎么配置

在MongoDB中配置副本集和自动故障转移需要以下步骤:配置副本集的成员:打开MongoDB配置文件(通常是mongod.conf),配置副本集的成员信息,包括每个成员的IP地址、端口号等。例如:replication:replSetNam
MongoDB的副本集与自动故障转移怎么配置
2024-05-07

springboot怎么连接mongodb副本集

要连接MongoDB副本集,需要在Spring Boot应用程序中配置MongoDB的副本集连接。以下是连接MongoDB副本集的步骤:首先,确保MongoDB副本集已经设置并运行。您可以在MongoDB的配置文件中指定副本集的名称和成员。
springboot怎么连接mongodb副本集
2024-04-17

java怎么连接mongodb副本集

建立连接副本集确定副本集名称和成员地址。创建MongoClient对象,指定副本集名称和成员地址。连接到副本集,并使用readPreference()方法选择主节点。处理副本集故障驱动程序自动处理单个成员故障、主节点切换和副本集配置更改。正确关闭连接使用close()方法关闭连接以释放资源。注意事项驱动程序管理连接池以优化连接性能。可通过readPreference()方法指定读偏好。可自定义故障超时和重试策略。
java怎么连接mongodb副本集
2024-04-10

mongodb中副本集集群技术怎么使用

在MongoDB中,副本集集群技术用于提供高可用性和故障容错的解决方案。副本集是由多个MongoDB实例组成的集群,其中包括一个主节点和多个从节点。以下是使用副本集集群技术的步骤:1. 安装MongoDB:在每个节点上安装MongoDB,并
2023-08-23

怎么在MongoDB中添加分片副本集

这篇文章将为大家详细讲解有关怎么在MongoDB中添加分片副本集,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。流程:1、新建分片副本集2、使用addShard命令将分片副本集添加到集群中3、
2023-06-14

怎么搭建一个MongoDB 副本集

怎么搭建一个MongoDB 副本集?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。1、创建节点目录mkdir -p /data/mongo_28018/{data,log}m
2023-06-14

mongodb副本集同步问题怎么解决

解决MongoDB副本集同步问题可以通过以下几种方式:1. 检查网络连接:确保主节点和副本节点之间的网络连接良好,避免网络问题导致同步延迟或失败。可以使用ping命令或其他网络工具来测试网络连接质量。2. 调整心跳间隔:MongoDB副本集
2023-08-24

MongoDB副本集成员宕机会怎么样

当MongoDB副本集的某个成员宕机时,集群会自动进行故障转移,将宕机节点的数据复制到其他健康的节点上,确保集群的数据一致性和可用性。具体来说,MongoDB会根据副本集配置中的优先级和投票权重等参数来选择新的主节点,而其他节点则会成为从节
MongoDB副本集成员宕机会怎么样
2024-04-19

Cassandra数据副本故障怎么恢复

在Cassandra中,如果数据副本出现故障,可以通过以下步骤来恢复:检查故障的副本:首先需要确定哪个数据副本出现了故障。可以通过查看日志或使用nodetool status命令来查看数据副本的状态。修复故障的副本:使用nodetool r
Cassandra数据副本故障怎么恢复
2024-03-15

apache中的php版本该怎么切换

本篇内容主要讲解“apache中的php版本该怎么切换”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“apache中的php版本该怎么切换”吧!1 查询官网打开官网,找到FAQhttps://ww
2023-06-20

编程热搜

目录