我正在尝试创建副本,但无法继续
创建 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
最佳答案
就在那里:
block 引用>"Attempting to initiate a replica set with name rs1, but command line reports rs2; rejecting"
您应该为所有成员提供与种子相同的副本集名称 (
s1
)。对于第二个成员:
sudo mongod --replSet rs1 ...
而不是
sudo mongod --replSet rs2 ...
第三位成员采用相同的原则
关于mongodb - 创建副本集时出错 - MongoDb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39426821/