Skip to main content

Reconfigiure replica set member

Reconfigure replica set member with same coonfiguration as it was earlier:

We have replica set of three node cluster. 

1 Primary  P1:27001
2 Secondary S1:27002 and S2:27003

S1 server got crashed and need to rebuilt so mongoDB reconfiguration  required.

Status at primary looks like this:

"set" : "rep1A",
        "myState" : 1,
        "syncingTo" : "P1:27001",   
    "members" : [
                {
                        "_id" : 0,
                        "name" : "P1:27001",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                 },
                {
                        "_id" : 1,
                        "name" : "S1:27002",
                        "health" : 1,
                        "state" : 8,
                        "stateStr" : "(not reachable)",
                       
                },
                {
                        "_id" : 2,
                        "name" : "S2:27003",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                   }

Secondary node S1 got crashed, so required to reconfigure in order to make it the part of replica again.

Few things need to be taken care here is:
replica set name, the port on which process running and the type (Secondary or Arbiter)

Here we have secondary node.

For the configuration file we have copied the configuration file from the Primary P1 node and make the required changes like Port.

Create all the required directories as mentioned in the conf file.

Conf file may look like this:

dbpath= /data/mongod
pidfilepath = /data/mongod/mongod.pid
logpath = /admin/logs/mongod.log
logappend = true
fork = true
shardsvr = true
port = 27002
replSet = rep1A
auth = true
keyFile = /admin/conf/mongo.key

Key file is something we need to copy from Primary node to the secondary node, so they can communicate.

Once all configuration set, we just need to start the mongod process. 

The secondary node state will change to STARTUP>STARTUP2>SECONDARY

You can check the status from Primary.











Comments

Popular posts from this blog

Recover Recently Deleted documents

use recoverDoc ; for ( i = 0 ; i < 100 ; i ++){ db . col1 . insert ({ _id : i })}; for ( i = 100 ; i < 200 ; i ++){ db . col1 . insert ({ _id : i , name : "some_x_name" })}; > db . col1 . remove ({ "name" : "some_x_name" }) WriteResult ({ "nRemoved" : 100 }) use local ; db . oplog . rs . find ({ op : "i" , ns : "recoverDoc .col1" , "o.name" : "some_x_name" }). count (); 100 db . oplog . rs . find ({ op : "i" , ns : "recoverDoc .col1 " , "o.name" : "some_x_name" }, { "o" : 1 }); { "o" : { "_id" : 100 , "name" : "some_x_name" } } { "o" : { "_id" : 101 , "name" : "some_x_name" } } { "o" : { "_id" : 102 , "name" : "some_x_name" } } { "o" : { ...

Mongod log is growing too large.

We have log append true in config file. Every day log is appended to the single log file. We are facing issue in space and we were also not able to purge the log file completely. So we need logs file for every day, if we have space issue then we can remove the old logs. Only thing we need to do is: In config file make sure we have: logappend = true Then login to mongo shell, run the below command against the admin database. use admin db.runCommand({logRotate:1})