@@ -7,38 +7,43 @@ Add Members to a Replica Set
7
7
Overview
8
8
--------
9
9
10
- This is a tutorial explaining how to add an additional node to an
10
+ This tutorial explains how to add an additional member to an
11
11
existing replica set.
12
12
13
- Before adding new members, note the
14
- :doc:`/administration/replication-architectures` documentation for
15
- more background on replication deployment patterns.
13
+ Before adding a new member, see the :ref:`replica-set-admin-procedure-add-member`
14
+ topic in the :doc:`/administration/replica-sets` document.
15
+
16
+ For background on replication deployment patterns, see the
17
+ :doc:`/administration/replication-architectures` document.
16
18
17
19
Requirements
18
20
------------
19
21
20
22
#. An active replica set.
21
23
22
24
#. A new MongoDB system capable of supporting your dataset, accessible by
23
- the active replica set through the network.
25
+ the active replica set through the network.
24
26
25
27
If neither of these conditions are satisfied, please use the MongoDB
26
28
:ref:`installation tutorial <tutorials-installation>` and the
27
- ":doc:`/tutorial/deploy-replica-set`" guide instead.
29
+ :doc:`/tutorial/deploy-replica-set` guide instead.
30
+
31
+ Procedures
32
+ ----------
28
33
29
- Procedure
30
- ---------
34
+ .. _procedure-assumption-add-member-rs:
31
35
32
- For the following procedure, examples are provided using the following
36
+ The examples in this procedure use the following
33
37
configuration:
34
38
35
- - The active replica set: ``rs0``
39
+ - The active replica set is ``rs0``.
36
40
37
- - The new MongoDB replica set to be added: ``mongodb3.example.net``.
41
+ - The new member to be added is ``mongodb3.example.net``.
38
42
39
- - :program:`mongod` instance running on default port: ``27017``.
43
+ - The :program:`mongod` instance default port is ``27017``.
40
44
41
- - The ``mongodb.conf`` on the new replica set system resembling the following:
45
+ - The ``mongodb.conf`` configuration file exists in the ``/etc``
46
+ directory and contains the following replica set information:
42
47
43
48
.. code-block:: cfg
44
49
@@ -54,53 +59,105 @@ configuration:
54
59
55
60
replSet = rs0
56
61
57
- For more documentation of the configuration options used above refer to:
58
- :setting:`dbpath`, :setting:`port`, :setting:`replSet`,
59
- :setting:`bind_ip`, and :setting:`fork`. Consider any additional
60
- :doc:`configuration options </reference/configuration-options>` that
61
- your deployment may require.
62
+ For more information on configuration options, see
63
+ :doc:`/reference/configuration-options`.
62
64
63
- #. On the primary node, Start the :program:`mongod` process with the
64
- following command:
65
+ .. _replica-set-add-member:
65
66
66
- .. code-block:: sh
67
+ Add a Member to an Existing Replica Set
68
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67
69
68
- mongod --config /etc/mongodb.conf
70
+ This procedure uses the above :ref:`example configuration <procedure-assumption-add-member-rs>`.
69
71
70
- .. note::
72
+ 1. Deploy a new :program:`mongod` instance, specifying the name of the
73
+ replica set. You can do this one of two ways:
71
74
72
- The primary node is the only node which can add or remove
73
- members to the replica set. If you do not know the primary
74
- node, log into any of the existing members of the current
75
- replica set by issuing the following command:
75
+ - Using the ``mongodb.conf`` file. On the :term:`primary`, issue a
76
+ command that resembles the following:
76
77
77
- .. code-block:: sh
78
+ .. code-block:: sh
78
79
79
- mongo mongodb0.example.net
80
-
81
- If this instance is not currently the :term:`primary` node, use
82
- the :method:`db.isMaster()` function to determine which node is in
83
- the :data:`isMaster.primary` field. Issue the following command.
80
+ mongod --config /etc/mongodb.conf
81
+
82
+ - Using command line arguments. On the :term:`primary`, issue command
83
+ that resembles the following:
84
+
85
+ .. code-block:: sh
86
+
87
+ mongod --replSet rs0
88
+
89
+ Take note of the host name and port information for the new
90
+ :program:`mongod` instance.
91
+
92
+ #. Open a :program:`mongo` shell connected to the replica set's primary:
93
+
94
+ .. code-block:: sh
95
+
96
+ mongo
97
+
98
+ .. note::
99
+
100
+ The primary is the only member that can add or remove members from
101
+ the replica set. If you do not know which member is the primary,
102
+ log into any member of the replica set using :program:`mongo` and
103
+ issue the :method:`db.isMaster()` command to determine which
104
+ member is in the :data:`isMaster.primary` field. For example:
84
105
85
106
.. code-block:: javascript
86
107
108
+ mongo mongodb0.example.net
109
+
87
110
db.isMaster()
88
111
89
- Now disconnect from the current client and reconnect to the
90
- primary node .
112
+ If you are not connected to the primary, disconnect from the
113
+ current client and reconnect to the primary .
91
114
92
- #. Now issue the following command to add the new member to the
115
+ #. In the :program:`mongo` shell, issue the following command to add the new member to the
93
116
replica set.
94
117
95
118
.. code-block:: javascript
96
119
97
120
rs.add("mongodb3.example.net")
98
121
99
- Congratulations! You have successfully expanded an existing replica
100
- set. You can use the :method:`rs.status()` function to provide an
101
- overview of :doc:`replica set status </reference/replica-status>`, or
102
- the :method:`rs.conf()` for the complete :doc:`replica set
103
- configuration </reference/replica-configuration>`.
122
+ .. note::
123
+
124
+ You can also include the port number, depending on your setup:
125
+
126
+ .. code-block:: javascript
127
+
128
+ rs.add("mongodb3.example.net:27017")
129
+
130
+ #. Verify that the member is now part of the replica set by
131
+ calling the :method:`rs.config()` method,
132
+ which displays the :doc:`replica set configuration </reference/replica-configuration>`:
133
+
134
+ .. code-block:: javascript
135
+
136
+ rs.config()
137
+
138
+ You can use the :method:`rs.status()` function to provide an
139
+ overview of :doc:`replica set status </reference/replica-status>`.
140
+
141
+ .. _replica-set-add-member-alternate-procedure:
142
+
143
+ Add a Member to an Existing Replica Set (Alternate Procedure)
144
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145
+
146
+ Alternately, you can add a member to a replica set by specifying an
147
+ entire configuration document with some or all of the fields in a
148
+ :data:`members <rs.conf.members>` document. For example:
149
+
150
+ .. code-block:: javascript
151
+
152
+ rs.add({_id: 1, host: "mongodb3.example.net:27017", priority: 0, hidden: true})
153
+
154
+ This configures a :term:`hidden member` that is accessible at
155
+ ``mongodb3.example.net:27017``. See :data:`host <members[n].host>`,
156
+ :data:`priority <members[n].priority>`, and :data:`hidden
157
+ <members[n].hidden>` for more information about these settings. When you
158
+ specify a full configuration object with :method:`rs.add()`, you must
159
+ declare the ``_id`` field, which is not automatically populated in this
160
+ case.
104
161
105
162
Production Notes
106
163
----------------
0 commit comments