@@ -10,27 +10,26 @@ Synopsis
1010For most :term:`replica sets <replica set>` the hostnames
1111[#hostnames-ips-dns]_ in the :data:`members[n].host` field never
1212change. However, in some cases you must migrate some or all host names
13- in a replica set as operational needs and organizations change. This
13+ in a replica set as organizational needs change. This
1414document presents two possible procedures for changing the hostnames
15- in the :data:`members[n].host` field, depending on your environments
16- availability requirements. You may:
15+ in the :data:`members[n].host` field. Depending on your environments
16+ availability requirements, you may:
1717
1818#. Make the configuration change without disrupting the availability
1919 of the replica set. While this ensures that your application will
2020 always be able to read and write data to the replica set, this
2121 procedure can take a long time and may incur downtime at the
2222 application layer. [#application-changes]_
2323
24- See :ref:`replica-set-change-hostname-no-downtime` for this
25- procedure.
24+ For this procedure, see :ref:`replica-set-change-hostname-no-downtime`.
2625
2726#. Stop all members of the replica set at once running on the "old"
2827 hostnames or interfaces, make the configuration changes, and then
2928 start the members at the new hostnames or interfaces. While the set
3029 will be totally unavailable during the operation, the total
3130 maintenance window is shorter.
3231
33- See :ref:`replica-set-change-hostname-downtime` for this procedure .
32+ For this procedure, see :ref:`replica-set-change-hostname-downtime`.
3433
3534.. seealso::
3635
@@ -47,12 +46,12 @@ availability requirements. You may:
4746 for the value of the :data:`members[n].host` field in the replica
4847 set configuration to avoid confusion and complexity.
4948
50- .. [#application-changes] You will have to configure your application
49+ .. [#application-changes] You will have to configure your applications
5150 so that they can connect to the replica set at both the old and new
5251 locations. This often requires a restart and reconfiguration at the
53- application layer which may affect the availability of your
54- application . This re-configuration is beyond the scope of this
55- document, and makes the :ref:`second option <replica-set-change-hostname-downtime>`
52+ application layer, which may affect the availability of your
53+ applications . This re-configuration is beyond the scope of this
54+ document and makes the :ref:`second option <replica-set-change-hostname-downtime>`
5655 preferable when you must change the hostnames of *all* members of
5756 the replica set at once.
5857
@@ -63,8 +62,8 @@ Procedures
6362
6463.. I think these section names can be better still.
6564
66- Maintain Availability for Replica Set while Changing Hostnames
67- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65+ Changing Hostnames while Maintaining the Replica Set's Availability
66+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6867
6968#. Make one of the :term:`secondary <secondary>` members of the
7069 :term:`replica set` accessible at the new location.
@@ -73,74 +72,140 @@ Maintain Availability for Replica Set while Changing Hostnames
7372 or may involve starting the :program:`mongo` instance on a new
7473 :setting:`port`.
7574
76- #. In a :program:`mongo` shell session, call :func:`rs.reconfigure()` to
77- reconfigure the set. Wait for the moved secondary to catch up.
75+ For example, given a secondary with hostname ``localhost:27018``,
76+ you could change the hostname by starting the secondary on a new port,
77+ as shown here:
7878
79- #. Make sure that the clients are able to access the set at the new
80- location.
79+ .. code-block:: sh
80+
81+ mongod --dbpath /data/db/ --port 37018 --replSet rs0
82+
83+ #. Open a :program:`mongo` shell connected to the replica set's
84+ :term:`primary` and then call :func:`rs.reconfigure()` to
85+ reconfigure the set, and then wait for the moved secondary
86+ to catch up. For example, for a primary running on port
87+ ``27107``, you would issue the following commands:
88+
89+ .. code-block:: sh
90+
91+ mongo --port 27017
92+
93+ rs.reconfigure()
94+
95+ #. Make sure that your client applications are able to access the set
96+ at the new location.
97+
98+ #. Repeat the above steps for each non-primary member of the set.
99+
100+ #. Open a :program:`mongo` shell connected to the primary and step
101+ down the primary using :dbcommand:`replSetStepDown`. You can do
102+ so by issuing the :func:`rs.stepDown()` command, as shown here:
103+
104+ .. code-block:: sh
105+
106+ mongo --port 27017
107+
108+ rs.stepDown()
109+
110+ #. Shut down the primary.
111+
112+ #. Open a :program:`mongo` shell connected to the new primary and
113+ call :func:`rs.reconfigure()` to reconfigure the set for the last
114+ time. For example:
115+
116+ .. code-block:: sh
117+
118+ mongo --port 37018
119+
120+ rs.reconfigure()
121+
122+ #. Restart the original primary.
81123
82- #. Repeat the above steps for each non-:term:`primary` member of the set.
124+ #. Open a :program:`mongo` shell connected to the primary.
125+ For example:
83126
84- #. Use :dbcommand:`replSetStepDown` to step down the primary and run
85- :func:`rs.reconfigure()` for the last time.
127+ .. code-block:: sh
128+
129+ mongo --port 27017
130+
131+ #. Run :func:`rs.stdatus()` to confirm that the set has reconfigured.
132+ For example:
133+
134+ .. code-block:: sh
135+
136+ rs.stdatus()
86137
87138.. _replica-set-change-hostname-downtime:
88139
89- Change All Hostnames in a Replica Set
90- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140+ Changing Hostnames by Making the Replica Set Unavailable
141+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91142
92143#. Stop all members in the :term:`replica set`.
93144
94- #. Restart each member *without* using the :option:`--replSet <mongod --replset>`
95- run-time option. Also run the :program:`mongod` on a different
96- port, ``37017`` in this example, to prevent clients from connecting
97- to this host while you preform maintenance. Start each
98- :program:`mongod` with a command that resembles the following:
145+ #. Restart each member *on a different port* and *without* using the
146+ :option:`--replSet <mongod --replset>` run-time option. Running on
147+ a different port prevents clients from connecting to this host while you perform
148+ maintenance. Use a command that
149+ resembles the following:
99150
100151 .. code-block:: sh
101152
102153 mongod --dbpath /data/db/ --port 37017
103154
104- #. Repeat the following sequence of operations for each member in the
105- replica set:
155+ #. For each member in the replica set, perform the following sequence of operations:
106156
107- #. Open a :program:`mongo` shell connected to the
108- :program:`mongod`, as follows:
157+ #. Open a :program:`mongo` shell connected to the member's
158+ :program:`mongod` running on the new, temporary port. For example,
159+ for a member running on a temporary port of ``37017``, you would issue
160+ this command:
109161
110162 .. code-block:: sh
111163
112- mongo --port 27017
113-
114- Modify the :option:`--port <mongo --port>` option as needed
115- depending on the :program:`mongod` instance's port.
164+ mongo --port 37017
116165
117166 #. Edit the replica set configuration manually. The replica set
118167 configuration is the only document in the ``system.replset``
119- collection in the ``local`` database. Consider the following
120- sequence of commands to change the hostname to
121- ``newHostName0:27017``:
168+ collection in the ``local`` database. Edit the replica set
169+ configuration with the new hostnames and correct ports for all
170+ the members of the replica set. Consider the following sequence of
171+ commands to change the hostnames in a three-member set:
122172
123173 .. code-block:: javascript
124174
125175 use local
126176
127177 cfg = db.system.replset.findOne( { "_id": "rs0" } )
128-
129- cfg.members[0].host = "newHostName0:27017"
130-
178+
179+ cfg.members[0].host = "mdb0.example.net:27017"
180+
181+ cfg.members[1].host = "mdb1.example.net:27018"
182+
183+ cfg.members[2].host = "mdb2.example.net:27019"
184+
131185 db.system.replset.update( { "_id": "rs0" } , cfg )
132186
133- #. Stop the :program:`mongod` process.
187+ #. Stop the :program:`mongod` process on the member .
134188
135189#. After re-configuring all members of the set, start each
136- :program:`mongod` instance using the :option:`--replSet <mongod --replset>`
137- option you normally would. This command would resemble the
138- following:
190+ :program:`mongod` instance in the normal way: use the usual port
191+ number and use the :option:`--replSet <mongod --replset>` option. For
192+ example:
139193
140194 .. code-block:: sh
141195
142196 mongod --dbpath /data/db/ --port 27017 --replSet rs0
143197
144- #. You can now connect to the one of the :program:`mongod` instances
145- using the :program:`mongo` shell, and run the :func:`rs.satus()` to
146- confirm that the set has reconfigured.
198+ #. Connect to one of the :program:`mongod` instances
199+ using the :program:`mongo` shell. For example:
200+
201+ .. code-block:: sh
202+
203+ mongo --port 27017
204+
205+ #. Run :func:`rs.stdatus()` to confirm that the set has reconfigured.
206+ For example:
207+
208+ .. code-block:: sh
209+
210+ rs.stdatus()
211+
0 commit comments