Saeed Akhtar
Saeed Akhtar

Reputation: 261

How to modify replica set config?

I have a mongo 2 node cluster running, with this replica set config.

config = {_id: "repl1", members:[
{_id: 0, host: 'localhost:15000'},
{_id: 1, host: '192.168.2.100:15000'}]
}

I have to move these both nodes on to new servers. I have copied everything from old to new servers, but I'm running into issues while reconfiguring the replica config due to ip change on the 2nd node.

I have tried this.

config = {_id: "repl1", members:[
 {_id: 0, host: 'localhost:15000'},
{_id: 1, host: '192.168.2.200:15000'}]
}
   rs.reconfig(config)  
   {


"startupStatus" : 1,
"errmsg" : "loading local.system.replset config (LOADINGCONFIG)",
"ok" : 0
}

It shows above message, but change is not happening.

I also tried changing replica set name but pointing to the same data dirs. I am getting the following error:

rs.initiate() 
{
"errmsg" : "local.oplog.rs is not empty on the initiating member. cannot initiate.",
"ok" : 0
}

What are the right steps to change the IP but keeping the data on the 2nd node, or do i need to recreate/resync the 2nd node?

Upvotes: 26

Views: 41723

Answers (4)

Experimenter
Experimenter

Reputation: 2478

You can use rs.reconfig option. First retrieve the current configuration with rs.conf(). Modify the configuration document as needed, and then pass the modified document to rs.reconfig()

More info in docs.

Upvotes: 0

Christian P
Christian P

Reputation: 12240

You can use force option when reconfiguring replica set:

rs.reconfig(config, {force: true})

Note that, as Adam already suggested in the comments, you should have at least 3 nodes: 2 full nodes and 1 arbiter (minimum supported configuration) or 3 full nodes (minimum recommended configuration) so that primary node can be elected.

Upvotes: 34

Jim Rippon
Jim Rippon

Reputation: 31

I realise this is an old post, but I discovered I was getting this exact same error when trying to change the port used by secondaries in my replica set.

In my case, I needed to stop the secondary whose config I was changing, and bring it up on its new address and port BEFORE applying the changed config on the Primary.

This is in the mongo documentation, but the order in which I had to bring things up and down was something I'd mis-read on the first pass, so for clarity I've repeated that here:

  1. Shut down the secondary member of the replica set you are moving.
  2. Bring that secondary back up at its new address
  3. Make the configuration change as detailed in the original post above

Upvotes: 3

Erhan A
Erhan A

Reputation: 701

Well , I had the same problem.

I had to delete all replication and oplog.

use local
db.dropDatabase()

restart your mongo with new set name

config = {_id: "repl1", members:[
{_id: 0, host: 'localhost:15000'},
{_id: 1, host: '192.168.2.100:15000'}]
}

rs.initiate(config)

I hope this works for you too

Upvotes: 35

Related Questions