Skip to content

Commit 4bee668

Browse files
author
Sam Kleinman
committed
DOCS-54 edits and revisions
1 parent 986e6ab commit 4bee668

File tree

1 file changed

+89
-67
lines changed

1 file changed

+89
-67
lines changed
Lines changed: 89 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1-
=========================================
2-
Change All the Hostnames in a Replica Set
3-
=========================================
1+
=================================
2+
Change Hostnames in a Replica Set
3+
=================================
44

55
.. default-domain:: mongodb
66

77
Synopsis
88
--------
99

10-
As an example, you would change all the hostnames in a :term:`replica set`
11-
if you have a set comprised of local members, all the members use ``localhost``
12-
as the hostname, and you want to add a non-local member to the set. Since
13-
you can use ``localhost`` only when all members are local, you would
14-
have to change the hostnames on all the existing members.
15-
16-
To change the hostnames on all members, choose one of the following procedures:
17-
18-
#. :ref:`replica-set-change-hostname-downtime`
19-
20-
Keeping the set running avoids downtime but is a longer procedure.
21-
22-
#. :ref:`replica-set-change-hostname-downtime`
23-
24-
Shutting down the set is a faster procedure but, of course, takes the
25-
set offline.
26-
27-
This document describes how to change the hostnames or IP addresses for
28-
*all* the members of a replica set.
10+
For most :term:`replica sets <replica set>` the hostnames
11+
[#hostnames-ips-dns]_ in the :data:`members[n].host` field never
12+
change. However, in some cases you must migrate some or all host names
13+
in a replica set as operational needs and organizations change. This
14+
document 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:
17+
18+
#. Make the configuration change without disrupting the availability
19+
of the replica set. While this ensures that your application will
20+
always be able to read and write data to the replica set, this
21+
procedure can take a long time and may incur downtime at the
22+
application layer. [#application-changes]_
23+
24+
See :ref:`replica-set-change-hostname-no-downtime` for this
25+
procedure.
26+
27+
#. Stop all members of the replica set at once running on the "old"
28+
hostnames or interfaces, make the configuration changes, and then
29+
start the members at the new hostnames or interfaces. While the set
30+
will be totally unavailable during the operation, the total
31+
maintenance window is shorter.
32+
33+
See :ref:`replica-set-change-hostname-downtime` for this procedure.
2934

3035
.. seealso::
3136

@@ -38,18 +43,35 @@ This document describes how to change the hostnames or IP addresses for
3843
- :doc:`/tutorial/deploy-replica-set`
3944
- :doc:`/tutorial/expand-replica-set`
4045

41-
Procedure
42-
---------
46+
.. [#hostnames-ips-dns] Always use resolvable hostnames
47+
for the value of the :data:`members[n].host` field in the replica
48+
set configuration to avoid confusion and complexity.
49+
50+
.. [#application-changes] You will have to configure your application
51+
so that they can connect to the replica set at both the old and new
52+
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>`
56+
preferable when you must change the hostnames of *all* members of
57+
the replica set at once.
58+
59+
Procedures
60+
----------
4361

4462
.. _replica-set-change-hostname-no-downtime:
4563

46-
Changing Names for All Members of a Replica Set without Downtime
47-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64+
.. I think these section names can be better still.
4865

49-
#. Make one of the :term:`secondary <secondary>` members of the
50-
:term:`replica set` accessible at the new location.
66+
Maintain Availability for Replica Set while Changing Hostnames
67+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5168

52-
.. QUESTION: I'm unclear on how to perform step 1, above -bg
69+
#. Make one of the :term:`secondary <secondary>` members of the
70+
:term:`replica set` accessible at the new location.
71+
72+
This change may be as straightforward as creating a new DNS record,
73+
or may involve starting the :program:`mongo` instance on a new
74+
:setting:`port`.
5375

5476
#. In a :program:`mongo` shell session, call :func:`rs.reconfigure()` to
5577
reconfigure the set. Wait for the moved secondary to catch up.
@@ -59,66 +81,66 @@ Changing Names for All Members of a Replica Set without Downtime
5981

6082
#. Repeat the above steps for each non-:term:`primary` member of the set.
6183

62-
#. Use :dbcommand:`replSetStepDown` to step down the primary and run :func:`rs.reconfigure()`
63-
for the last time.
84+
#. Use :dbcommand:`replSetStepDown` to step down the primary and run
85+
:func:`rs.reconfigure()` for the last time.
6486

6587
.. _replica-set-change-hostname-downtime:
6688

67-
Changing Names for All Members of a Replica Set with Downtime
68-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69-
70-
.. NOTE: I could not get this procedure to work correctly -bg
71-
72-
.. NOTE: I used port 27017 because I think users are going to copy and paste,
73-
.. as I did myself in testing this, and I'd remember to change 37017 to 37018
74-
.. but forget to change it to 27018
89+
Change All Hostnames in a Replica Set
90+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7591

7692
#. Stop all members in the :term:`replica set`.
7793

78-
#. Restart each member *without* using the :option:`--replSet <mongod --replset>` option.
79-
80-
For example, to restart a member named ``rs0-0`` on port ``27017``:
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:
8199

82100
.. code-block:: sh
83101

84-
mongod --dbpath /data/db/rs0-0 --port 27017
102+
mongod --dbpath /data/db/ --port 37017
85103

86-
#. To change each member's host name, do the following *for each member*:
104+
#. Repeat the following sequence of operations for each member in the
105+
replica set:
87106

88-
#. Open a :program:`mongo` shell listening on the member's port number. For example:
107+
#. Open a :program:`mongo` shell connected to the
108+
:program:`mongod`, as follows:
89109

90-
.. code-block:: sh
110+
.. code-block:: sh
91111

92-
mongo --port 27017
112+
mongo --port 27017
93113

94-
.. QUESTION: is the above command correct?
114+
Modify the :option:`--port <mongo --port>` option as needed
115+
depending on the :program:`mongod` instance's port.
95116

96-
#. Change the member's hostname by editing the ``system.replset``
97-
object in the local database.
98-
99-
For example, for a member of replica set ``rs0``, use the
100-
following series of commands to change the member's host name to ``newHostName0:27017``:
117+
#. Edit the replica set configuration manually. The replica set
118+
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``:
101122

102123
.. code-block:: javascript
103124

104125
use local
105-
cfg = db.system.replset.findOne({_id:"rs0"})
106-
cfg.members[0].host="newHostName0:27017"
107-
db.system.replset.update({_id:"rs0"},cfg)
108-
109-
#. Stop the member.
126+
127+
cfg = db.system.replset.findOne( { "_id": "rs0" } )
128+
129+
cfg.members[0].host = "newHostName0:27017"
130+
131+
db.system.replset.update( { "_id": "rs0" } , cfg )
110132

111-
#. Restart each member using the :option:`--replSet <mongod --replset>` option.
133+
#. Stop the :program:`mongod` process.
112134

113-
For example, to restart member ``rs0-0`` on port ``27017`` in the ``rs0`` replica
114-
set, issue the following command:
135+
#. 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:
115139

116140
.. code-block:: sh
117141

118-
mongod --dbpath /data/db/rs0-0 --port 27017 --replSet rs0
119-
120-
.. QUESTION: Is rs.initiate() needed?
121-
122-
#. To ensure each member has the correct hostname, use the rs.status() helper.
142+
mongod --dbpath /data/db/ --port 27017 --replSet rs0
123143

124-
:func:`rs.satus()`
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.

0 commit comments

Comments
 (0)