I am using MongoDB 3.0.1 version. i am try to setup for mongodb replicaiton in our machine. i have use three mongodb in septate machine for replication.
我使用的是MongoDB 3.0.1版本。我试着在我们的机器上安装mongodb复制机。我用了3个mongodb来进行复制。
machine1 - master
machine2 - slave
machine3 - slave
I refer this url http://docs.mongodb.org/manual/tutorial/deploy-replica-set/
我引用这个url http://docs.mongodb.org/manual/tutorial/deploy-replica-set/。
I have configure for every machine in mongodb.conf file
我已经为mongodb中的每一台机器配置了配置。配置文件
replSet = rs1
fork = true
and i added two members in master machine using this command
我在主机器中使用这个命令添加了两个成员。
rs.add(192.168.1.2)
rs.add(192.168.1.3)
but i insert a document in master machine but not replicate other two slave machine. i did check slave machine throw the following error
但是我在主机器中插入了一个文档,但是没有复制其他两个从机。我确实检查了从机器上的错误。
> show dbs
2015-05-18T12:43:22.020+0530 E QUERY Error: listDatabases failed:{ "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }
at Error (<anonymous>)
at Mongo.getDBs (src/mongo/shell/mongo.js:47:15)
at shellHelper.show (src/mongo/shell/utils.js:630:33)
at shellHelper (src/mongo/shell/utils.js:524:36)
at (shellhelp2):1:1 at src/mongo/shell/mongo.js:47
>
> rs.conf()
2015-05-18T12:43:38.692+0530 E QUERY Error: Could not retrieve replica set config: {
"info" : "run rs.initiate(...) if not yet done for the set",
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94
}
at Function.rs.conf (src/mongo/shell/utils.js:1011:11)
at (shell):1:4 at src/mongo/shell/utils.js:1011
>
Please help me to solve the problem. thanks & Advance.
请帮我解决这个问题。谢谢&。
EDIT:
编辑:
rs1:PRIMARY> rs.conf()
{
"_id" : "rs1",
"version" : 4,
"members" : [
{
"_id" : 0,
"host" : "analyzer-xubuntu:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 1,
"host" : "192.168.1.31:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0.75,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 2,
"host" : "192.168.1.33:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0.5,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatTimeoutSecs" : 10,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
}
}
}
rs1:PRIMARY> rs.status()
{
"set" : "rs1",
"date" : ISODate("2015-05-18T09:07:31.767Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "analyzer-xubuntu:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 9236,
"optime" : Timestamp(1431939509, 2),
"optimeDate" : ISODate("2015-05-18T08:58:29Z"),
"electionTime" : Timestamp(1431931054, 2),
"electionDate" : ISODate("2015-05-18T06:37:34Z"),
"configVersion" : 4,
"self" : true
},
{
"_id" : 1,
"name" : "192.168.1.31:27017",
"health" : 1,
"state" : 0,
"stateStr" : "STARTUP",
"uptime" : 8953,
"optime" : Timestamp(0, 0),
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2015-05-18T09:07:29.831Z"),
"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
"pingMs" : 1,
"configVersion" : -2
},
{
"_id" : 2,
"name" : "192.168.1.33:27017",
"health" : 1,
"state" : 0,
"stateStr" : "STARTUP",
"uptime" : 8946,
"optime" : Timestamp(0, 0),
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2015-05-18T09:07:30.533Z"),
"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
"pingMs" : 1,
"configVersion" : -2
}
],
"ok" : 1
}
1 个解决方案
#1
12
Let us go step by step.
让我们一步一步来。
Your MongoDB config is ok, the rest of work may be done in the shell. I will use machine names instead of IPs.
您的MongoDB配置是可以的,其余的工作可以在shell中完成。我将使用机器名而不是ip。
First connect to machine1
, and run the following there:
首先连接到machine1,并运行以下操作:
> conf = {
_id: "rs1",
members:
[
{_id : 0, host : "machine1:27017"},
{_id : 1, host : "machine2:27017"},
{_id : 2, host : "machine3:27017"}
]
}
> rs.initiate(conf)
Then just run rs.slaveOk()
on the secondaries. The secondaries
will start replicating, and you will be able to query them and see your data, inserted from the primary
.
然后在第二轮上运行rs.slaveOk()。二级将开始复制,您将能够查询它们并查看您的数据,从主服务器中插入。
#1
12
Let us go step by step.
让我们一步一步来。
Your MongoDB config is ok, the rest of work may be done in the shell. I will use machine names instead of IPs.
您的MongoDB配置是可以的,其余的工作可以在shell中完成。我将使用机器名而不是ip。
First connect to machine1
, and run the following there:
首先连接到machine1,并运行以下操作:
> conf = {
_id: "rs1",
members:
[
{_id : 0, host : "machine1:27017"},
{_id : 1, host : "machine2:27017"},
{_id : 2, host : "machine3:27017"}
]
}
> rs.initiate(conf)
Then just run rs.slaveOk()
on the secondaries. The secondaries
will start replicating, and you will be able to query them and see your data, inserted from the primary
.
然后在第二轮上运行rs.slaveOk()。二级将开始复制,您将能够查询它们并查看您的数据,从主服务器中插入。