创建副本集时出错 - MongoDb
Error while creating Replica set - MongoDb
我正在尝试创建副本但无法继续
创建 3 个 mongod 实例的脚本:
sudo mkdir -p /data/rs1 /data/rs2 /data/rs3
sudo mongod --replSet rs1 --logpath "1.log" --dbpath /data/rs1 --port 27017 --fork
sudo mongod --replSet rs2 --logpath "2.log" --dbpath /data/rs2 --port 27018 --fork
sudo mongod --replSet rs3 --logpath "3.log" --dbpath /data/rs3 --port 27019 --fork
执行成功,但之后我尝试通过以下脚本提供有关 rs2 和 rs3 的 rs1 信息:
init_replica.js :
config = {
_id:"rs1",members:[
{_id:0,host:"grit-lenevo-pc:27017",priority:0,slaveDelay:5},
{_id:1,host:"grit-lenevo-pc:27018"},
{_id:2,host:"grit-lenevo-pc:27019"}]
}
rs.initiate(config)
rs.status()
现在当我尝试 运行 :
mongo --port 27018 < init_replica.js
我得到:
MongoDB shell version: 3.2.8
connecting to: 127.0.0.1:27018/test
{
"_id" : "rs1",
"members" : [
{
"_id" : 0,
"host" : "grit-lenevo-pc:27017",
"priority" : 0,
"slaveDelay" : 5
},
{
"_id" : 1,
"host" : "grit-lenevo-pc:27018"
},
{
"_id" : 2,
"host" : "grit-lenevo-pc:27019"
}
]
}
{
"ok" : 0,
"errmsg" : "Attempting to initiate a replica set with name rs1, but command line reports rs2; rejecting",
"code" : 93
}
{
"info" : "run rs.initiate(...) if not yet done for the set",
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94
}
bye
注意:如果我尝试以下命令,相同的命令工作正常:
mongo --port 27017 < init_replica.js
就在那里:
"Attempting to initiate a replica set with name rs1, but command line reports rs2; rejecting"
您应该为所有成员提供 相同的 副本集名称作为种子 (s1
)。对于第二个成员:
sudo mongod --replSet rs1 ...
而不是
sudo mongod --replSet rs2 ...
第三个成员的委托人相同
我有一个类似的名称不匹配问题,但它更微妙一些。
在我的 mongo.conf
中,我使用 "rs0"
(引号)作为 RS 名称,然后是 运行 rs.initiate({_id : "rs0"...})
,但失败了
"Attempting to initiate a replica set with name rs0, but command line reports \"rs0\"; rejecting"
花了一段时间才注意到额外的引号 - 不要在 mongo.conf
的 RS 名称中使用它们。
我正在尝试创建副本但无法继续
创建 3 个 mongod 实例的脚本:
sudo mkdir -p /data/rs1 /data/rs2 /data/rs3
sudo mongod --replSet rs1 --logpath "1.log" --dbpath /data/rs1 --port 27017 --fork
sudo mongod --replSet rs2 --logpath "2.log" --dbpath /data/rs2 --port 27018 --fork
sudo mongod --replSet rs3 --logpath "3.log" --dbpath /data/rs3 --port 27019 --fork
执行成功,但之后我尝试通过以下脚本提供有关 rs2 和 rs3 的 rs1 信息:
init_replica.js :
config = {
_id:"rs1",members:[
{_id:0,host:"grit-lenevo-pc:27017",priority:0,slaveDelay:5},
{_id:1,host:"grit-lenevo-pc:27018"},
{_id:2,host:"grit-lenevo-pc:27019"}]
}
rs.initiate(config)
rs.status()
现在当我尝试 运行 :
mongo --port 27018 < init_replica.js
我得到:
MongoDB shell version: 3.2.8
connecting to: 127.0.0.1:27018/test
{
"_id" : "rs1",
"members" : [
{
"_id" : 0,
"host" : "grit-lenevo-pc:27017",
"priority" : 0,
"slaveDelay" : 5
},
{
"_id" : 1,
"host" : "grit-lenevo-pc:27018"
},
{
"_id" : 2,
"host" : "grit-lenevo-pc:27019"
}
]
}
{
"ok" : 0,
"errmsg" : "Attempting to initiate a replica set with name rs1, but command line reports rs2; rejecting",
"code" : 93
}
{
"info" : "run rs.initiate(...) if not yet done for the set",
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94
}
bye
注意:如果我尝试以下命令,相同的命令工作正常:
mongo --port 27017 < init_replica.js
就在那里:
"Attempting to initiate a replica set with name rs1, but command line reports rs2; rejecting"
您应该为所有成员提供 相同的 副本集名称作为种子 (s1
)。对于第二个成员:
sudo mongod --replSet rs1 ...
而不是
sudo mongod --replSet rs2 ...
第三个成员的委托人相同
我有一个类似的名称不匹配问题,但它更微妙一些。
在我的 mongo.conf
中,我使用 "rs0"
(引号)作为 RS 名称,然后是 运行 rs.initiate({_id : "rs0"...})
,但失败了
"Attempting to initiate a replica set with name rs0, but command line reports \"rs0\"; rejecting"
花了一段时间才注意到额外的引号 - 不要在 mongo.conf
的 RS 名称中使用它们。