Removing a Member from Replica Set or Replica Set as Whole

Hi Everyone,

If anyone wants to reset their replica set, please follow the steps along.

Removing a Member from Replica Set:

  • Shutdown your node which you want to remove. Two ways to do this:

    • Kill the mongod process by checking pid through the command below. The first column will show pid. Make sure you kill only the respective node process.

       vagrant@m103:~$ ps -ef | grep mongod
         501  2809  2568   0  5:12PM ttys000    0:00.00 grep mongod --port 27002 --dbpath...
         520  2809  2568   0  5:12PM ttys000    0:00.00 grep mongod --port 27001 --dbpath...
       vagrant@m103:~$ kill 501
      
    • Or Connect to the respective node, run:

      > db.shutdownServer()
      
  • Connect to your primary node of your replica set using mongo --port 27xxx

  • Authenticate yourself on admin:

      > use admin
      > db.auth("m103-admin","m103-pass")
    
  • Run rs.remove("..."). Example:

      > rs.remove("192.168.103.100:27027")
    

You can also remove a member using rs.reconfig(). For more details on this topic, check mongodb docs here.
If someone just needs to replace a member of replica set, please see the documentation here.

Removing a Replica Set as Whole:

*Note: During this process, one might lose their data. So, you may want to keep a backup of data files.

  • If you want to keep the data, but start outside a replica set, just restart the mongod process without the --replSet and on a different port. That will give you a standalone mongod.

  • To be completely sure that the replica set configuration is gone from the instance, make sure that the local.system.replset collection is empty.

    • Connect to primary node

    • Authenticate yourself as mentioned above using m103-admin.

    • Run commands:

      use local
      db.system.replset.drop()

  • Once that is done, and you are happy with your standalone instance, you can then restart with a different --replSet argument and go through the replica set configuration process again:
    http://www.mongodb.org/display/DOCS/Replica+Set+Configuration

The other option, as you mention, is to remove all the data files and start completely from scratch.

  • Remove dbPath directory using rm -rf. Example:

       vagrant@m103:~$ rm -rf /var/mongdb/db/node2
    
  • Follow the steps mentioned in the lab again.

Let me know if you have any doubts!

Kanika

5 Likes