Setting up a replica set
In this section, we will go through the most common deployment procedures to set up a replica set.
Converting a standalone server to a replica set
To convert a standalone server to a replica set, we first need to cleanly shut down the mongo
server:
> use admin > db.shutdownServer()
Then we start the server with the --replSet
configuration option via the command line or using a configuration file, as explained in the next section.
First, we connect via the mongo shell to the new replica set enabled instance as follows:
> rs.initiate()
Now, we have the first server of our replica set. We can add the other servers (which must have also been started with --replSet
) by using the mongo shell as follows:
> rs.add("<hostname><:port>")
Note
Double check the replica set configuration, using rs.conf()
. Verify the replica set status, using rs.status()
.
Creating a replica set
Starting a MongoDB server as part of a replica set is as easy as setting it in the configuration...