2

I am trying to create replica but unable to proceed

Script to create 3 mongod instance :

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

This executes successfully but after this i try to provide rs1 information about rs2 and rs3 via below script :

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()

Now when i try to run :

mongo --port 27018 < init_replica.js

I am getting :

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

Note : The same command works fine if i try below command :

mongo --port 27017 < init_replica.js

Following tutorials : M101 Mongo Db For Java Developers

dskrvk
  • 1,318
  • 15
  • 24
Neeraj Jain
  • 7,643
  • 6
  • 34
  • 62

2 Answers2

4

It's right about there:

"Attempting to initiate a replica set with name rs1, but command line reports rs2; rejecting"

You should supply all members with the same replica set name as the seed (s1). For the second member:

sudo mongod --replSet rs1 ...

and not

sudo mongod --replSet rs2 ...

Same principal goes for third member

Ori Dar
  • 18,687
  • 5
  • 58
  • 72
  • thanks, got it. but now facing a new problem *No host described in new configuration 1 for replica set rs1 maps to this node* ,tried solution given [here](http://stackoverflow.com/a/30850962/3143670) but no luck – Neeraj Jain Sep 10 '16 at 15:01
  • tried replacing **grit-lenevo-pc** with **localhost** and it's running perfectly fine, thanks pal – Neeraj Jain Sep 10 '16 at 15:07
  • I also had the same code 93 error. I was using a wrong machine name; I corrected and all went fine. I am taking the [**M102: MongoDB for DBAs**](https://university.mongodb.com/courses/M102/about) and there they recommend do not use **localhost** but the machine name instead. – hestellezg Feb 02 '17 at 16:46
0

I had a similar name mismatch issue, but it was a bit more subtle.

In my mongo.conf I used "rs0" (quoted) for the RS name, and then ran rs.initiate({_id : "rs0"...}), which failed with

"Attempting to initiate a replica set with name rs0, but command line reports \"rs0\"; rejecting"

It took a while to notice the extra quotes - don't use them in the RS name in mongo.conf.

dskrvk
  • 1,318
  • 15
  • 24