|
1 | 1 | .. _server-replica-set-deploy-convert:
|
2 | 2 |
|
3 |
| -===================================== |
4 |
| -Convert a Standalone to a Replica Set |
5 |
| -===================================== |
| 3 | +================================================ |
| 4 | +Convert a Standalone mongod to a Replica Set |
| 5 | +================================================ |
6 | 6 |
|
7 | 7 | .. default-domain:: mongodb
|
8 | 8 |
|
9 | 9 |
|
10 |
| -This tutorial describes the process for converting a :term:`standalone` |
11 |
| -:binary:`~bin.mongod` instance into a :term:`replica set`. Use |
12 |
| -standalone instances for testing and development, but always use |
13 |
| -replica sets in production. |
| 10 | +A :term:`standalone` :binary:`mongod` instance is useful for testing and |
| 11 | +development. A standalone instance isn't a good choice for a production |
| 12 | +deployment because it can be a single point of failure. A :ref:`replica |
| 13 | +set <replication>`, also known as a *cluster*, provides redundancy and |
| 14 | +availability. Always use a replica set in production. |
14 | 15 |
|
15 |
| -To deploy a replica set without using a pre-existing |
16 |
| -:binary:`~bin.mongod` instance, see :doc:`/tutorial/deploy-replica-set` |
17 |
| -instead. |
| 16 | +If you have a standalone server with data that you want to use in |
| 17 | +production, convert the standalone server to a replica set first. |
| 18 | + |
| 19 | +.. important:: |
| 20 | + |
| 21 | + If you convert a development server to a replica set for production |
| 22 | + use, consult the :ref:`security checklist <security-checklist>` |
| 23 | + before you expose your cluster to the internet. |
| 24 | + |
| 25 | +Before You Begin |
| 26 | +---------------- |
| 27 | + |
| 28 | +Before you convert your standalone instance, consider whether a |
| 29 | +:ref:`replica set <replication>` or a :ref:`sharded cluster |
| 30 | +<sharding-background>` is more appropriate for your workload. |
| 31 | + |
| 32 | +A sharded cluster is a special kind of cluster. A sharded cluster |
| 33 | +provides redundancy and availability; it also distributes data across |
| 34 | +:ref:`shards <shards-concepts>`. Shards are usually hosted on multiple |
| 35 | +servers and allow for horizontal scaling. |
18 | 36 |
|
19 |
| -To install a standalone instance, see the :ref:`installation tutorials |
20 |
| -<tutorials-installation>`. |
21 | 37 |
|
22 | 38 | Procedure
|
23 | 39 | ---------
|
24 | 40 |
|
25 |
| -.. include:: /includes/important-hostnames.rst |
| 41 | +.. procedure:: |
| 42 | + :style: normal |
| 43 | + |
| 44 | + .. step:: Shut down the standalone instance. |
| 45 | + |
| 46 | + Use :binary:`mongosh` to :ref:`connect <mdb-shell-connect>` to |
| 47 | + your ``mongod`` instance. |
| 48 | + |
| 49 | + .. code-block:: shell |
| 50 | + |
| 51 | + mongosh |
| 52 | + |
| 53 | + Switch to the ``admin`` database and run :dbcommand:`shutdown`. |
| 54 | + |
| 55 | + .. code-block:: javascript |
| 56 | + |
| 57 | + use admin |
| 58 | + db.adminCommand( |
| 59 | + { |
| 60 | + shutdown: 1, |
| 61 | + comment: "Convert to cluster" |
| 62 | + } |
| 63 | + ) |
| 64 | + |
| 65 | + .. step:: Name the replica set. |
| 66 | + |
| 67 | + If you configure your ``mongod`` instance from the command line, |
| 68 | + use the :option:`--replSet <mongod --replSet>` option to set a |
| 69 | + name for your replica set. |
| 70 | + |
| 71 | + A typical command line invocation might include: |
| 72 | + |
| 73 | + .. list-table:: |
| 74 | + :header-rows: 1 |
| 75 | + |
| 76 | + * - Purpose |
| 77 | + - Option |
| 78 | + |
| 79 | + * - Cluster name |
| 80 | + - :option:`--replSet <mongod --replSet>` |
| 81 | + |
| 82 | + * - Network details |
| 83 | + - :option:`--port <mongod --port>` |
| 84 | + |
| 85 | + * - Data path |
| 86 | + - :option:`--dbpath <mongod --dbpath>` |
| 87 | + |
| 88 | + * - Authentication details |
| 89 | + - :option:`--authenticationDatabase <mongosh |
| 90 | + --authenticationDatabase>`, :option:`--username |
| 91 | + <mongosh --username>`, :option:`--password <mongosh |
| 92 | + --password>` |
| 93 | + |
| 94 | + Update the example code with the settings for your deployment. |
| 95 | + |
| 96 | + .. code-block:: shell |
| 97 | + |
| 98 | + mongod --replSet rs0 \ |
| 99 | + --port 27017 \ |
| 100 | + --dbpath /path/to/your/mongodb/dataDirectory \ |
| 101 | + --authenticationDatabase "admin" \ |
| 102 | + --username "adminUserName" \ |
| 103 | + --password |
26 | 104 |
|
27 |
| -#. Shut down the :term:`standalone` :binary:`~bin.mongod` instance. |
| 105 | + If you use a configuration file to start ``mongodb``, add a |
| 106 | + ``replication`` section to your configuration file. Edit the |
| 107 | + ``replSetName`` value to set the name of your replica set. |
28 | 108 |
|
29 |
| -#. Restart the instance. Use the :option:`--replSet <mongod --replSet>` |
30 |
| - option to specify the name of the new replica set. |
| 109 | + .. code-block:: shell |
31 | 110 |
|
32 |
| - For example, the following command starts a standalone instance as a |
33 |
| - member of a new replica set named ``rs0``. The command uses the |
34 |
| - standalone's existing database path of ``/srv/mongodb/db0``: |
| 111 | + replication: |
| 112 | + replSetName: rs0 |
35 | 113 |
|
36 |
| - .. include:: /includes/warning-bind-ip-security-considerations.rst |
| 114 | + .. step:: Initialize the replica set. |
| 115 | + |
| 116 | + To initialize the replica set, use ``mongosh`` to reconnect to |
| 117 | + your server instance. Then, run :method:`rs.initiate() |
| 118 | + <rs.initiate>`. |
37 | 119 |
|
38 |
| - .. code-block:: bash |
| 120 | + .. code-block:: javascript |
39 | 121 |
|
40 |
| - mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0 --bind_ip localhost,<hostname(s)|ip address(es)> |
| 122 | + rs.initiate() |
41 | 123 |
|
42 |
| - .. include:: /includes/fact-unique-replica-set-names.rst |
| 124 | + You only have to initiate the replica set once. |
43 | 125 |
|
44 |
| - For more information on configuration options, see |
45 |
| - :doc:`/reference/configuration-options` and the :binary:`~bin.mongod` |
46 |
| - manual page. |
| 126 | + To view the replica set configuration, use :method:`rs.conf()`. |
| 127 | + |
| 128 | + To check the status of the replica set, use :method:`rs.status()`. |
47 | 129 |
|
48 |
| -#. Connect :binary:`~bin.mongosh` to the :binary:`~bin.mongod` instance. |
| 130 | + .. step:: Add nodes to the replica set. |
49 | 131 |
|
50 |
| -#. Use :method:`rs.initiate()` to initiate the new replica set: |
| 132 | + The new replica set has a single, primary node. The next step is |
| 133 | + to add new nodes to the replica set. Review the documentation on |
| 134 | + clusters before you add additional nodes: |
51 | 135 |
|
52 |
| - .. code-block:: javascript |
| 136 | + - :ref:`Replica set architectures |
| 137 | + <replica-set-deployment-overview>` |
| 138 | + - :ref:`Adding members to a replica set |
| 139 | + <server-replica-set-deploy-expand>` |
53 | 140 |
|
54 |
| - rs.initiate() |
| 141 | + When you are ready to add nodes, use :method:`rs.add()`. |
55 | 142 |
|
56 |
| - The replica set is now operational. To view the replica set |
57 |
| - configuration, use :method:`rs.conf()`. To check the status of the |
58 |
| - replica set, use :method:`rs.status()`. |
59 | 143 |
|
60 |
| -To add members to this replica set, use the :method:`rs.add()` method. |
61 |
| -For more information on adding members to a replica set, see |
62 |
| -:doc:`/tutorial/expand-replica-set`. |
| 144 | +Learn More |
| 145 | +---------- |
63 | 146 |
|
| 147 | +- :ref:`Configuration options <configuration-options>` |
| 148 | +- :ref:`Deploy a standalone instance <tutorials-installation>` |
| 149 | +- :ref:`Deploy a new replica set <server-replica-set-deploy>` |
0 commit comments