mongo 复制集重置 命名 OTHER
作者:互联网
rs1:OTHER> rs.status()
{
"operationTime" : Timestamp(1559293558, 1),
"ok" : 0,
"errmsg" : "Our replica set config is invalid or we are not a member of it",
"code" : 93,
"codeName" : "InvalidReplicaSetConfig",
"$clusterTime" : {
"clusterTime" : Timestamp(1559293558, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
初始化发现不行
rs.initiate({
_id :
"rs2"
,
members: [
{ _id: 0, host:
"localhost:51001"
},
{ _id: 1, host:
"localhost:51002"
},
{ _id: 2, host:
"localhost:51003"
}
]
})
解决方案
1. 停止所有实例,使用非复制模式启动
重新启动,去掉--replSet参数
2. 清除复制集信息缓存数据库local
使用mongo shell连接到服务器,对3个实例分别执行以下命令
1 2 |
|
3. 停止所有实例,使用复制模式启动
重新启动,使用--replSet参数指定新的复制集名字
4. 初始化复制集
a. 使用mongo shell连接到其中一个实例,这个实例将作为新的PRIMARY
b. 执行rs.initiate()。不要指定参数,不然会报错。其他配置参数可以在随后使用rs.reconfig()方法来设置
conf=rs.conf()
conf.members[0].host='127.0.0.1:37017'
rs.reconfig(conf)
rs.status()
{
"set" : "adset",
"date" : ISODate("2020-12-21T04:24:23.654Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"members" : [
{
"_id" : 0,
"name" : "127.0.0.1:37017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 341,
"optime" : {
"ts" : Timestamp(1608524659, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-12-21T04:24:19Z"),
"electionTime" : Timestamp(1608524345, 2),
"electionDate" : ISODate("2020-12-21T04:19:05Z"),
"configVersion" : 2,
"self" : true
}
],
"ok" : 1
}
c. 对每一个secondary,使用rs.add({_id:1,host:'127.0.0.1:37018',priority:1})添加到复制集
rs.status()
{
"set" : "adset",
"date" : ISODate("2020-12-21T04:25:23.331Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"members" : [
{
"_id" : 0,
"name" : "127.0.0.1:37017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 401,
"optime" : {
"ts" : Timestamp(1608524718, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-12-21T04:25:18Z"),
"electionTime" : Timestamp(1608524345, 2),
"electionDate" : ISODate("2020-12-21T04:19:05Z"),
"configVersion" : 3,
"self" : true
},
{
"_id" : 1,
"name" : "127.0.0.1:37018",
"health" : 1,
"state" : 5,
"stateStr" : "STARTUP2",
"uptime" : 4,
"optime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2020-12-21T04:25:22.608Z"),
"lastHeartbeatRecv" : ISODate("2020-12-21T04:25:18.664Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "127.0.0.1:37017",
"configVersion" : 3
}
],
"ok" : 1
}
d. 等待secondary同步
e.加入选举节点rs.add({_id:2,host:'127.0.0.1:37019',priority:1,arbiterOnly:true})
这种方式不需要重新导入数据
标签:12,mongo,rs,21T04,重置,NumberLong,OTHER,ISODate,id 来源: https://blog.csdn.net/sinat_41780498/article/details/111473334