I setup master/slave replication of mongodb on EC2. But I see not replication happening. When I do "show dbs" on master, it shows all dbs expected.
But when I do the same on replica, it does not show me any db.
Please help me troubleshoot.
rs.config()
{
"_id" : "ittw",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" : "ip-10-304-48-93:27017"
}
]
}
rs.config()
{
"_id" : "ittw",
"version" : 2,
"members" : [
{
"_id" : 0,
"host" : "domU-17-31-19-16-88-5F:27017"
},
{
"_id" : 1,
"host" : "ec2-50-321-52-908.compute-1.amazonaws.com:27017"
}
]
}
rs.status() // replica
{
"set" : "ittw",
"date" : ISODate("2013-08-12T06:55:57Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "$ip:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 356039,
"optime" : Timestamp(1375934685, 1),
"optimeDate" : ISODate("2013-08-08T04:04:45Z"),
"self" : true
}
],
"ok" : 1
}
rs.status() //Master
{
"set" : "ittw",
"date" : ISODate("2013-08-12T06:57:19Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "PRI_IP:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 356543,
"optime" : Timestamp(1376289725, 1),
"optimeDate" : ISODate("2013-08-12T06:42:05Z"),
"self" : true
},
{
"_id" : 1,
"name" : "REP_IP:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 355869,
"optime" : Timestamp(1375934685, 1),
"optimeDate" : ISODate("2013-08-08T04:04:45Z"),
"lastHeartbeat" : ISODate("2013-08-12T06:57:17Z"),
"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
"pingMs" : 1
}
],
"ok" : 1
}
Best Answer
It looks like what you have done is run
rs.initiate()
on both the primary and the secondary server.In this case the outcome is that you have two different replica sets called
ittw
rather than a single replica set with replication. The primary knows about both nodes, but the "secondary" you setup is also configured as a primary for a replica set only containing itself. This definitely won't work.As per the instructions on Deploying a replica set, you should only run
rs.initiate()
on the primary, and then users.add("hostname:port")
to add secondaries to the same replica set.To fix up your dud secondary to a clean state, you should:
db.shutdownServer()
or appropriate command likeservice mongodb stop
(depending on how you installed MongoDB)dbpath
directory for the secondarymongo
shell to connect to the primary, andrs.add()
your secondaryIf all is well you should see consistent
rs.status()
information on the primary and new secondary.