Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify replica set config?

Tags:

mongodb

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?

like image 782
Saeed Akhtar Avatar asked Sep 10 '25 16:09

Saeed Akhtar


2 Answers

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

like image 83
Erhan A Avatar answered Sep 13 '25 04:09

Erhan A


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.

like image 41
Christian P Avatar answered Sep 13 '25 06:09

Christian P