Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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
}
share|improve this question

2 Answers 2

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 use rs.add("hostname:port") to add secondaries to the same replica set.

To fix up your dud secondary to a clean state, you should:

  • stop the secondary using db.shutdownServer() or appropriate command like service mongodb stop (depending on how you installed MongoDB)
  • remove the files in the dbpath directory for the secondary
  • restart the secondary
  • use the mongo shell to connect to the primary, and rs.add() your secondary

If all is well you should see consistent rs.status() information on the primary and new secondary.

share|improve this answer

Have you run the rs.initiate command to kick it all off?

Docs

Also how do you have your replset configured? Is it a single master and a single slave? Do you have a second secondary or an arbiter to provide quorm and ensure clean failover?

share|improve this answer
    
rs.initiate() { "info" : "try querying local.system.replset to see current configuration", "ok" : 0, "errmsg" : "already initialized" } –  user2384694 Aug 12 '13 at 10:07
    
1 master + 1 slave –  user2384694 Aug 12 '13 at 10:08
    
It looks like you have a split brain i.e. both nodes think they are primary. Have you tried rs.stepdown() on one of the nodes Docs –  Mike Birkett Aug 12 '13 at 10:18
    
Also I see you have two versions of rs.config. Have you run rs.reconfig using the newest version? Docs –  Mike Birkett Aug 12 '13 at 10:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.