MongoDB: Change replica set name

This is just a quick reference guide for change the replica set name, for anyone who wish to give this a try, simply replace mongo-n to your own hostname,


We will first find and kill the mongod processes running on each host then we will start them individually without the --replSet keyword, which simply means we will start each mongod as standalone database. They are started as follows:
Note: if /etc/mongod.conf is used, simply remove --replSet in the config file and start mongod

Node1:
sudo -u mongodb mongod --port 27017 --dbpath /data/db --logpath /data/db/log/mongod.log --bind_ip localhost,mongo-1 --keyFile /etc/mongo.keyfile --fork


Node2:
sudo -u mongodb mongod --port 27017 --dbpath /data/db --logpath /data/db/log/mongod.log --bind_ip localhost,mongo-2 --keyFile /etc/mongo.keyfile --fork


Node3:
sudo -u mongodb mongod --port 27017 --dbpath /data/db --logpath /data/db/log/mongod.log --bind_ip localhost,mongo-3 --keyFile /etc/mongo.keyfile --fork


Once all mongod's are started, log into each box
Assuming you have user:admin, password:admin, created in database:admin, with admin privileges

mongo -u admin -p admin admin

Issue the following in each "standalone" mongod instance:

use local
db.dropDatabase()

Once all local database are dropped in each mongod instance, find and kill all mongod processes running on each host.


Now restarted all mongod with the replica set name you would like to use
Note: if /etc/mongod.conf is used, simply add --replSet newName in the config file and start mongod

Node1:
sudo -u mongodb mongod --port 27017 --dbpath /data/db --logpath /data/db/log/mongod.log --bind_ip localhost,mongo-1 --replSet=newName --keyFile /etc/mongo.keyfile --fork


Node2:
sudo -u mongodb mongod --port 27017 --dbpath /data/db --logpath /data/db/log/mongod.log --bind_ip localhost,mongo-2 --replSet=newName  --keyFile /etc/mongo.keyfile --fork


Node3:
sudo -u mongodb mongod --port 27017 --dbpath /data/db --logpath /data/db/log/mongod.log --bind_ip localhost,mongo-3 --replSet=newName  --keyFile /etc/mongo.keyfile --fork


Once all mongod's are started,

Choose a host and run the following, in my case, I had chosen mongo-1 to re-initiate the replica set

mongo -u admin -p admin admin

rs.initiate()

rs.add("mongo-2:27017")
rs.add("mongo-3:27017")

Run rs.status() to verify the status of the other nodes

the secondary nodes' status should soon change from "STARTUP" to "SECONDARY".  In the meantime, we can also verify the new replica set by running

rs.conf()._id

it should return "newName"





Comments

Popular posts from this blog

MongoDB Tips: Kill long running processes

Oracle Goldengate Extract, Pump, and Replicat

MongoDB Ops Manager Basic Installation and Configuration