How to perform maintenance on replica sets

If we have some maintenance tasks that we have to perform in every member in a replica set, we always start with the secondaries. We perform maintenance by performing the following steps:

  1. First, we connect to one of the secondaries via the mongo shell. Then, we stop that secondary:
> use admin
> db.shutdownServer()
  1. Then, using the same user that was connected to the mongo shell in the previous step, we restart the mongo server as a standalone server in a different port:
> mongod --port 95658 --dbpath <wherever our mongoDB data resides in this host>
  1. The next step is to connect to this mongod server (which is using dbpath):
> mongo --port 37017
  1. At this point, we can safely perform all of the administrative tasks on our standalone server without affecting our replica set operations. When we are done, we shut down the standalone server in the same way that we did in the first step.
  2. We can then restart our server in the replica set by using the command line or the configuration script that we normally use. The final step is to verify that everything works fine by connecting to the replica set server and getting its replica set status:
> rs.status()

The server should initially be in state: RECOVERING, and, once it has caught up with the secondary, it should be back in state: SECONDARY, like it was before starting the maintenance.

We will repeat the same process for every secondary server. In the end, we have to perform maintenance on the primary. The only difference in the process for the primary is that we will start by stepping down our primary server into a secondary server before every other step:

> rs.stepDown(600)

By using the above argument, we prevent our secondary from being elected as a master for 10 minutes. This should be enough time to shut down the server and continue with our maintenance, like we did with the secondaries.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset