Mongodb – Create a second Replica set on same 3 nodes as another Replica set


Can a second 3 node Replica set be installed on the same 3 nodes with another 3 node Replica set without interference?

Best Answer

Yes, for testing and development. Not for production, obviously. Note below, the different port numbers and data paths for each mongod instance.

If you had the first replica set like this:

mkdir -p /srv/mongodb/rs0-0 /srv/mongodb/rs0-1 /srv/mongodb/rs0-2

mongod --port 27017 --dbpath /srv/mongodb/rs0-0 --replSet rs0 --smallfiles --oplogSize 128 --fork

mongod --port 27018 --dbpath /srv/mongodb/rs0-1 --replSet rs0 --smallfiles --oplogSize 128 --fork

mongod --port 27019 --dbpath /srv/mongodb/rs0-2 --replSet rs0 --smallfiles --oplogSize 128 --fork

You could add a second replica set like this to the same localhost with the following:

mkdir -p /srv/mongodb/rs1-0 /srv/mongodb/rs1-1 /srv/mongodb/rs1-2

mongod --port 37017 --dbpath /srv/mongodb/rs1-0 --replSet rs1 --smallfiles --oplogSize 128 --fork

mongod --port 37018 --dbpath /srv/mongodb/rs1-1 --replSet rs1 --smallfiles --oplogSize 128 --fork

mongod --port 37019 --dbpath /srv/mongodb/rs1-2 --replSet rs1 --smallfiles --oplogSize 128 --fork

Reference: Deploy a Replica Set for Testing and Development