Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

99 lines (66 sloc) 3.365 kb
=====================================
Convert a Standalone to a Replica Set
=====================================
.. default-domain:: mongodb
This tutorial describes the process for converting a
:term:`standalone` :program:`mongod` instance into a three-member
:term:`replica set`. Use standalone instances for testing and
development, but always use replica sets in production. To install a
standalone instance, see the :ref:`installation tutorials
<tutorials-installation>`.
To deploy a replica set without using a pre-existing :program:`mongod`
instance, see :doc:`/tutorial/deploy-replica-set`.
Procedure
---------
#. Shut down the :term:`standalone` :program:`mongod` instance.
#. Restart the instance. Use the :option:`--replSet <mongod --replSet>`
option to specify the name of the new replica set.
For example, the following command starts a standalone instance as a
member of a new replica set named ``rs0``. The command uses the
standalone's existing database path of ``/srv/mongodb/db0``:
.. code-block:: sh
mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0
.. include:: /includes/fact-unique-replica-set-names.rst
For more information on configuration options, see
:doc:`/reference/configuration-options` and the :program:`mongod`
manual page.
#. Connect to the :program:`mongod` instance.
#. Use :method:`rs.initiate()` to initiate the new replica set:
.. code-block:: javascript
rs.initiate()
The replica set is now operational.
To view the replica set configuration, use :method:`rs.conf()`. To
check the status of the replica set, use :method:`rs.status()`.
.. _expand-the-replica-set:
Expand the Replica Set
~~~~~~~~~~~~~~~~~~~~~~
Add additional replica set members by doing the following:
#. On two distinct systems, start two new standalone :program:`mongod`
instances. For information on starting a standalone instance, see
the :ref:`installation tutorial <tutorials-installation>` specific
to your environment.
#. On your connection to the original :program:`mongod` instance (the
former standalone instance), issue a command in the following form
for each new instance to add to the replica set:
.. code-block:: javascript
rs.add("<hostname><:port>")
Replace ``<hostname>`` and ``<port>`` with the resolvable hostname
and port of the :program:`mongod` instance to add to the set. For
more information on adding a host to a replica set, see
:doc:`/tutorial/expand-replica-set`.
Sharding Considerations
~~~~~~~~~~~~~~~~~~~~~~~
If the new replica set is part of a :term:`sharded cluster`, change
the shard host information in the :term:`config database` by doing
the following:
#. Connect to one of the sharded cluster's :program:`mongos`
instances and issue a command in the following form:
.. code-block:: javascript
db.getSiblingDB("config").shards.save( {_id: "<name>", host: "<replica-set>/<member,><member,><...>" } )
Replace ``<name>`` with the name of the shard. Replace
``<replica-set>`` with the name of the replica set. Replace
``<member,><member,><>`` with the list of the members of the
replica set.
#. Restart all :program:`mongos` instances. If possible, restart all
components of the replica sets (i.e., all :program:`mongos` and
all shard :program:`mongod` instances).
Jump to Line
Something went wrong with that request. Please try again.