Reputation: 175
I just created replica set within Mongo db, and I am curious when turn off cmd window, or when I type ctrl + c, so in case I want to run replica set again, how am I going to do that ? Which steps are needed ? Hopefully I will not have to start all over again in creating rs?
Thank You.
here is what I got.
MongoDB Enterprise > rs.status()
{
"set" : "rs0",
"date" : ISODate("2017-11-26T03:14:48.098Z"),
"myState" : 1,
"term" : NumberLong(2),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1511666085, 1),
"t" : NumberLong(2)
},
"appliedOpTime" : {
"ts" : Timestamp(1511666085, 1),
"t" : NumberLong(2)
},
"durableOpTime" : {
"ts" : Timestamp(1511666085, 1),
"t" : NumberLong(2)
}
},
"members" : [
{
"_id" : 0,
"name" : "mario:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 818,
"optime" : {
"ts" : Timestamp(1511666085, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2017-11-26T03:14:45Z"),
"electionTime" : Timestamp(1511665273, 1),
"electionDate" : ISODate("2017-11-26T03:01:13Z"),
"configVersion" : 7,
"self" : true
},
{
"_id" : 1,
"name" : "mario:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 804,
"optime" : {
"ts" : Timestamp(1511666085, 1),
"t" : NumberLong(2)
},
"optimeDurable" : {
"ts" : Timestamp(1511666085, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2017-11-26T03:14:45Z"),
"optimeDurableDate" : ISODate("2017-11-26T03:14:45Z"),
"lastHeartbeat" : ISODate("2017-11-26T03:14:46.565Z"),
"lastHeartbeatRecv" : ISODate("2017-11-26T03:14:46.575Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "mario:27017",
"configVersion" : 7
},
{
"_id" : 2,
"name" : "mario:27019",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 39,
"lastHeartbeat" : ISODate("2017-11-26T03:14:46.570Z"),
"lastHeartbeatRecv" : ISODate("2017-11-26T03:14:47.762Z"),
"pingMs" : NumberLong(0),
"configVersion" : 7
}
],
"ok" : 1
}
Upvotes: 0
Views: 5680
Reputation: 4742
Following are the steps to restart MongoDB Replica Set. Start with Secondary nodes first
Step-1 Login to mongo shell on Secondary servers
$ mongo -u user123 -p --authenticationDatabase admin
(If your DB has authentication enabled)
Step-2 Stop the secondary servers by using below command :
> use admin
> db.shutdownServer()
Step-3 Go to Linux shell on secondary servers and type below command :
> sudo service mongod stop
Starting the MongoDB replication
Step-4 Go to Linux shell on secondary servers and type below command :
> sudo service mongod start
Step-5 Check the status
> sudo systemctl status mongod.service
Step-1 Login to primary as in Step-1
Step-2 Step Down Primary Node
> rs.stepDown(120)
Connect mongo shell to the primary node and use rs.stepDown()
to step down the primary and allow one of the secondary to be elected the new primary. Specify a 120-second waiting period to prevent the member from being elected primary again.
Perform step-2, step-3, step-4 and step-5.
Upvotes: 0
Reputation: 2447
If you shut down all the servers, the replication configuration will still be there so that if you restart the servers again, they will continue from the last state. You don't have to reconfigure everything again if you want the same settings like the previous setup.
You just have to start the mongo server using the --replSet parameter the same way how you started in the first place.
mongod --replSet "rs0"
Upvotes: 1