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

mongodb 副本集的维护(1)

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

北京

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

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

看不清楚,换张图片

免费获取短信验证码

mongodb 副本集的维护(1)

一、修改副本集中各成员的优先级:

shard1:PRIMARY> conf=rs.conf()

{

"_id" : "shard1",

"version" : 3,

"protocolVersion" : NumberLong(1),

"members" : [

{

"_id" : 0,

"host" : "mongo01-jp:27027",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 1,

"tags" : {


},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 1,

"host" : "mongo02-jp:27027",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 1,

"tags" : {


},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 2,

"host" : "mongo03-jp:27027",

"arbiterOnly" : true,

"buildIndexes" : true,

"hidden" : false,

"priority" : 1,

"tags" : {


},

"slaveDelay" : NumberLong(0),

"votes" : 1

}

],

"settings" : {

"chainingAllowed" : true,

"heartbeatIntervalMillis" : 2000,

"heartbeatTimeoutSecs" : 10,

"electionTimeoutMillis" : 10000,

"catchUpTimeoutMillis" : 2000,

"getLastErrorModes" : {


},

"getLastErrorDefaults" : {

"w" : 1,

"wtimeout" : 0

},

"replicaSetId" : ObjectId("5850deb0205cd94104cd9a38")

}

}

shard1:PRIMARY> conf.members[0].priority=100

100

shard1:PRIMARY> conf.members[1].priority=90

90

shard1:PRIMARY> rs.reconfig(conf)

{ "ok" : 1 }

shard1:PRIMARY> rs.conf()

{

"_id" : "shard1",

"version" : 4,

"protocolVersion" : NumberLong(1),

"members" : [

{

"_id" : 0,

"host" : "mongo01-jp:27027",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 100,

"tags" : {


},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 1,

"host" : "mongo02-jp:27027",

"arbiterOnly" : false,

"buildIndexes" : true,

"hidden" : false,

"priority" : 90,

"tags" : {


},

"slaveDelay" : NumberLong(0),

"votes" : 1

},

{

"_id" : 2,

"host" : "mongo03-jp:27027",

"arbiterOnly" : true,

"buildIndexes" : true,

"hidden" : false,

"priority" : 1,

"tags" : {


},

"slaveDelay" : NumberLong(0),

"votes" : 1

}

],

"settings" : {

"chainingAllowed" : true,

"heartbeatIntervalMillis" : 2000,

"heartbeatTimeoutSecs" : 10,

"electionTimeoutMillis" : 10000,

"catchUpTimeoutMillis" : 2000,

"getLastErrorModes" : {


},

"getLastErrorDefaults" : {

"w" : 1,

"wtimeout" : 0

},

"replicaSetId" : ObjectId("5850deb0205cd94104cd9a38")

}

}

shard1:PRIMARY>

关于优先级范围从0 至 1000 (3.2以上版本) ,优先级越大,越可能成为primary;若优先级为0,则该节点无资格参与primary的选举。

如果希望某节点不参与primary的选举有两种方法: 1、将该节点优先级设置为0;2、rs.freeze(30) 在cluster选举primary时,将该节点暂时冻结30S。

如果希望将本primary节点降为secondary状态,可以执行 rs.stepDown() 。


二、在副本集中删除成员、重新添加成员

shard2:PRIMARY> rs.status()

{

"set" : "shard2",

"date" : ISODate("2016-12-14T06:12:11.986Z"),

"myState" : 1,

"term" : NumberLong(1),

"heartbeatIntervalMillis" : NumberLong(2000),

"optimes" : {

"lastCommittedOpTime" : {

"ts" : Timestamp(1481695926, 1),

"t" : NumberLong(1)

},

"appliedOpTime" : {

"ts" : Timestamp(1481695926, 1),

"t" : NumberLong(1)

},

"durableOpTime" : {

"ts" : Timestamp(1481695926, 1),

"t" : NumberLong(1)

}

},

"members" : [

{

"_id" : 0,

"name" : "mongo02-jp:27028",

"health" : 1,

"state" : 1,

"stateStr" : "PRIMARY",

"uptime" : 1128,

"optime" : {

"ts" : Timestamp(1481695926, 1),

"t" : NumberLong(1)

},

"optimeDate" : ISODate("2016-12-14T06:12:06Z"),

"electionTime" : Timestamp(1481695445, 2),

"electionDate" : ISODate("2016-12-14T06:04:05Z"),

"configVersion" : 4,

"self" : true

},

{

"_id" : 1,

"name" : "mongo01-jp:27028",

"health" : 1,

"state" : 2,

"stateStr" : "SECONDARY",

"uptime" : 464,

"optime" : {

"ts" : Timestamp(1481695926, 1),

"t" : NumberLong(1)

},

"optimeDurable" : {

"ts" : Timestamp(1481695926, 1),

"t" : NumberLong(1)

},

"optimeDate" : ISODate("2016-12-14T06:12:06Z"),

"optimeDurableDate" : ISODate("2016-12-14T06:12:06Z"),

"lastHeartbeat" : ISODate("2016-12-14T06:12:10.206Z"),

"lastHeartbeatRecv" : ISODate("2016-12-14T06:12:11.202Z"),

"pingMs" : NumberLong(0),

"syncingTo" : "mongo02-jp:27028",

"configVersion" : 4

},

{

"_id" : 2,

"name" : "mongo03-jp:27028",

"health" : 1,

"state" : 7,

"stateStr" : "ARBITER",

"uptime" : 439,

"lastHeartbeat" : ISODate("2016-12-14T06:12:10.205Z"),

"lastHeartbeatRecv" : ISODate("2016-12-14T06:12:10.125Z"),

"pingMs" : NumberLong(0),

"configVersion" : 4

}

],

"ok" : 1

}

shard2:PRIMARY> rs.remove("mongo01-jp:27028")

{ "ok" : 1 }

shard2:PRIMARY> rs.remove("mongo03-jp:27028")

{ "ok" : 1 }

shard2:PRIMARY> rs.status()

{

"set" : "shard2",

"date" : ISODate("2016-12-14T06:13:18.227Z"),

"myState" : 1,

"term" : NumberLong(1),

"heartbeatIntervalMillis" : NumberLong(2000),

"optimes" : {

"lastCommittedOpTime" : {

"ts" : Timestamp(1481695994, 1),

"t" : NumberLong(1)

},

"appliedOpTime" : {

"ts" : Timestamp(1481695994, 1),

"t" : NumberLong(1)

},

"durableOpTime" : {

"ts" : Timestamp(1481695994, 1),

"t" : NumberLong(1)

}

},

"members" : [

{

"_id" : 0,

"name" : "mongo02-jp:27028",

"health" : 1,

"state" : 1,

"stateStr" : "PRIMARY",

"uptime" : 1195,

"optime" : {

"ts" : Timestamp(1481695994, 1),

"t" : NumberLong(1)

},

"optimeDate" : ISODate("2016-12-14T06:13:14Z"),

"electionTime" : Timestamp(1481695445, 2),

"electionDate" : ISODate("2016-12-14T06:04:05Z"),

"configVersion" : 6,

"self" : true

}

],

"ok" : 1

}

shard2:PRIMARY> rs.add("mongo03-jp:27028")

{ "ok" : 1 }

shard2:PRIMARY> rs.addArb("mongo01-jp:27028")

{ "ok" : 1 }

shard2:PRIMARY> rs.status()

{

"set" : "shard2",

"date" : ISODate("2016-12-14T06:39:40.718Z"),

"myState" : 1,

"term" : NumberLong(1),

"heartbeatIntervalMillis" : NumberLong(2000),

"optimes" : {

"lastCommittedOpTime" : {

"ts" : Timestamp(1481697576, 1),

"t" : NumberLong(1)

},

"appliedOpTime" : {

"ts" : Timestamp(1481697576, 1),

"t" : NumberLong(1)

},

"durableOpTime" : {

"ts" : Timestamp(1481697576, 1),

"t" : NumberLong(1)

}

},

"members" : [

{

"_id" : 0,

"name" : "mongo02-jp:27028",

"health" : 1,

"state" : 1,

"stateStr" : "PRIMARY",

"uptime" : 2777,

"optime" : {

"ts" : Timestamp(1481697576, 1),

"t" : NumberLong(1)

},

"optimeDate" : ISODate("2016-12-14T06:39:36Z"),

"electionTime" : Timestamp(1481695445, 2),

"electionDate" : ISODate("2016-12-14T06:04:05Z"),

"configVersion" : 9,

"self" : true

},

{

"_id" : 1,

"name" : "mongo03-jp:27028",

"health" : 1,

"state" : 2,

"stateStr" : "SECONDARY",

"uptime" : 1034,

"optime" : {

"ts" : Timestamp(1481697576, 1),

"t" : NumberLong(1)

},

"optimeDurable" : {

"ts" : Timestamp(1481697576, 1),

"t" : NumberLong(1)

},

"optimeDate" : ISODate("2016-12-14T06:39:36Z"),

"optimeDurableDate" : ISODate("2016-12-14T06:39:36Z"),

"lastHeartbeat" : ISODate("2016-12-14T06:39:38.838Z"),

"lastHeartbeatRecv" : ISODate("2016-12-14T06:39:39.594Z"),

"pingMs" : NumberLong(0),

"syncingTo" : "mongo02-jp:27028",

"configVersion" : 9

},

{

"_id" : 2,

"name" : "mongo01-jp:27028",

"health" : 1,

"state" : 7,

"stateStr" : "ARBITER",

"uptime" : 1128,

"lastHeartbeat" : ISODate("2016-12-14T06:39:39.053Z"),

"lastHeartbeatRecv" : ISODate("2016-12-14T06:39:36.708Z"),

"pingMs" : NumberLong(0),

"configVersion" : 9

}

],

"ok" : 1

}

免责声明:

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

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

mongodb 副本集的维护(1)

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

下载Word文档

猜你喜欢

MongoDB学习笔记:副本集

本文更新于2022-01-08,使用MongoDB 4.4.5。目录单台服务器下创建副本集多台服务器下创建副本集重新启动并连接到副本集维护副本集节点单台服务器下创建副本集确保/data/db目录存在且当前系统用户有读写权限。例如(需根据实际情况设置权限):su
MongoDB学习笔记:副本集
2019-12-08

mongodb如何更换副本集

要更换MongoDB副本集,需要遵循以下步骤:1. 添加新副本集成员:首先,在新服务器上安装MongoDB,并确保它可以连接到现有的副本集。然后,在现有副本集的Primary节点上执行`rs.add()`命令,将新服务器添加为新的副本集成员
2023-08-23

编程热搜

目录