Database Reference
In-Depth Information
Converting an existing instance to a replica set
There are some straightforward steps to convert a standalone instance to a replica set. As
you already learned in previous chapters, a replica set should have a name. This name is
configurable via a configuration file or command-line parameters for the mongod process.
In order to define the replica set's name, you can use the replSet setting. For instance,
the following configuration file sets the replica set name to rs1 :
logpath = /var/log/mongodb.log
port = 27017
fork = true
replSet = rs1
Also, you can use the following command-line parameters:
mongod --port 27017 --dbpath /var/log/mongodb.log --replSet
rs1
In order to set the name for the replica set, you should shut down the mongod instance and
restart it with a new configuration file (or command-line parameters). At this step, you
have a brief outage since you have to shut down the mongod instance.
After restarting the mongod instance, you should connect to the mongod instance using
the mongo interactive shell and issue the following command:
rs.initiate()
After issuing the preceding command, the replica set is ready. Use the rs.status() to
check the status of the replica set.
For the rest of migration process, we will follow the same method that we followed to mi-
grate replica sets. You can add the new node (the new server) and after completing syn-
chronization, remove the current node from the replica set.
Note
Make sure that you have an odd number of members in your replica set in all the steps you
perform.
Search WWH ::




Custom Search