Skip to content

Commit 6bede5e

Browse files
author
Bob Grabar
committed
DOCS-54 edits, including rs.status output
1 parent 708c0d7 commit 6bede5e

File tree

1 file changed

+146
-31
lines changed

1 file changed

+146
-31
lines changed

draft/tutorial/change-hostnames-in-a-replica-set.txt

Lines changed: 146 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,59 +63,67 @@ Procedures
6363
Changing Hostnames while Maintaining the Replica Set's Availability
6464
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6565

66-
.. todo given a dummy config.
66+
Given a :term:`replica set` with three members
67+
68+
- ``database0.example.net:27017`` (the :term:`primary`)
69+
70+
- ``database1.example.net:27018``
71+
72+
- ``database2.example.net:27019``
73+
74+
This procedure changes the hostnames to the following, while maintaining
75+
the set's availability:
76+
77+
- ``mongodb0.example.net:27017`` (the primary)
78+
79+
- ``mongodb1.example.net:27018``
80+
81+
- ``mongodb2.example.net:27019``
6782

6883
#. For each :term:`secondary` in the replica set, perform the
6984
following sequence of operations:
7085

71-
.. todo note about stopping things
86+
a. Stop the secondary.
7287

73-
a. For example, given a secondary with hostname
74-
``database0.example.net:27017`` that you want to change to
75-
``mongodb0.database.example.net:27017``, you could change the
76-
hostname by starting this secondary on a different port for
77-
maintenance, as shown here:
88+
#. Restart the secondary on a different port, such as a maintenance
89+
port. Use the secondary's usual :option:`--dbpath`, which in this
90+
example is ``/data/db1``:
7891

7992
.. code-block:: sh
8093

81-
mongod --dbpath /data/db/ --port 37017
82-
83-
.. make it clear that the db path is the same.
94+
mongod --dbpath /data/db1 --port 37018
8495

8596
#. Open a :program:`mongo` shell connected to the replica set's
86-
:term:`primary` and then call :func:`rs.reconfigure()` to
87-
reconfigure the set. For example, for a primary running on port
88-
``37107``, you would issue the following command:
97+
primary. In our example, the primary runs on port ``27017`` so you
98+
would issue the following command:
8999

90100
.. code-block:: sh
91101

92-
mongo --port 37017
93-
94-
.. make clear that its the same host as in a.)
102+
mongo --port 27017
95103

96-
#. Then run the following reconfiguration option, for the
97-
:data:`members[n].host` value where ``n`` is ``2``:
104+
#. Run the following reconfigure option, for the
105+
:data:`members[n].host` value where ``n`` is ``1``:
98106

99107
.. code-block:: javascript
100-
108+
101109
cfg = rs.conf()
102110

103-
cfg.members[2].host = mongodb2.databse.example.net:27017
111+
cfg.members[1].host = mongodb1.example.net:27018
104112

105113
rs.reconfigure(cfg)
106114

107115
See :doc:`/reference/replica-configuration` for more
108116
information.
109117

110-
#. Make sure that your client applications are able to access the
118+
#. Make sure your client applications are able to access the
111119
set at the new location and that the secondary has a chance to
112120
catch up with the other members of the set.
113121

114122
Repeat the above steps for each non-primary member of the set.
115123

116124
#. Open a :program:`mongo` shell connected to the primary and step
117125
down the primary using :dbcommand:`replSetStepDown`. In the
118-
:program:`mongo` shell, use the the :func:`rs.stepDown()` wrapper,
126+
:program:`mongo` shell, use the :func:`rs.stepDown()` wrapper,
119127
as follows:
120128

121129
.. code-block:: javascript
@@ -132,7 +140,7 @@ Changing Hostnames while Maintaining the Replica Set's Availability
132140

133141
cfg = rs.conf()
134142

135-
cfg.members[0].host = mongodb0.databse.example.net:27017
143+
cfg.members[0].host = mongodb0.example.net:27017
136144

137145
rs.reconfigure(cfg)
138146

@@ -143,7 +151,61 @@ Changing Hostnames while Maintaining the Replica Set's Availability
143151
#. To confirm the new configuration, call :func:`rs.status()` in the
144152
:program:`mongo` shell.
145153

146-
.. output ofchanged rsconfig.
154+
Your output should look similar to this:
155+
156+
.. code-block:: javascript
157+
158+
{
159+
"set" : "rs",
160+
"date" : ISODate("2012-08-17T20:55:59Z"),
161+
"myState" : 1,
162+
"members" : [
163+
{
164+
"_id" : 0,
165+
"name" : "mongodb0.example.net:27017",
166+
"health" : 1,
167+
"state" : 1,
168+
"stateStr" : "PRIMARY",
169+
"optime" : {
170+
"t" : 1345235703000,
171+
"i" : 1
172+
},
173+
"optimeDate" : ISODate("2012-08-17T20:35:03Z"),
174+
"self" : true
175+
},
176+
{
177+
"_id" : 1,
178+
"name" : "mongodb1.example.net:27018",
179+
"health" : 1,
180+
"state" : 2,
181+
"stateStr" : "SECONDARY",
182+
"uptime" : 1260,
183+
"optime" : {
184+
"t" : 1345235703000,
185+
"i" : 1
186+
},
187+
"optimeDate" : ISODate("2012-08-17T20:35:03Z"),
188+
"lastHeartbeat" : ISODate("2012-08-17T20:55:58Z"),
189+
"pingMs" : 0
190+
},
191+
{
192+
"_id" : 2,
193+
"name" : "mongodb2.example.net:27019",
194+
"health" : 1,
195+
"state" : 2,
196+
"stateStr" : "SECONDARY",
197+
"uptime" : 1256,
198+
"optime" : {
199+
"t" : 1345235703000,
200+
"i" : 1
201+
},
202+
"optimeDate" : ISODate("2012-08-17T20:35:03Z"),
203+
"lastHeartbeat" : ISODate("2012-08-17T20:55:58Z"),
204+
"pingMs" : 0
205+
}
206+
],
207+
"ok" : 1
208+
}
147209

148210
.. _replica-set-change-hostname-downtime:
149211

@@ -185,15 +247,15 @@ Changing All Hostnames in Replica Set at Once
185247

186248
use local
187249

188-
cfg = db.system.replset.findOne( { "_id": "rs0" } )
250+
cfg = db.system.replset.findOne( { "_id": "rs" } )
189251

190252
cfg.members[0].host = "mdb0.example.net:27017"
191253

192254
cfg.members[1].host = "mdb1.example.net:27018"
193255

194256
cfg.members[2].host = "mdb2.example.net:27019"
195257

196-
db.system.replset.update( { "_id": "rs0" } , cfg )
258+
db.system.replset.update( { "_id": "rs" } , cfg )
197259

198260
#. Stop the :program:`mongod` process on the member.
199261

@@ -204,7 +266,7 @@ Changing All Hostnames in Replica Set at Once
204266

205267
.. code-block:: sh
206268

207-
mongod --dbpath /data/db/ --port 27017 --replSet rs0
269+
mongod --dbpath /data/db/ --port 27017 --replSet rs
208270

209271
#. Connect to one of the :program:`mongod` instances
210272
using the :program:`mongo` shell. For example:
@@ -213,9 +275,62 @@ Changing All Hostnames in Replica Set at Once
213275

214276
mongo --port 27017
215277

216-
#. Run :func:`rs.stdatus()` to confirm that the set has reconfigured.
217-
For example:
278+
#. To confirm that the set has reconfigured, call :func:`rs.status()` in the
279+
:program:`mongo` shell.
218280

219-
.. code-block:: sh
281+
Your output should look similar to this:
282+
283+
.. code-block:: javascript
284+
285+
{
286+
"set" : "rs",
287+
"date" : ISODate("2012-08-17T20:55:59Z"),
288+
"myState" : 1,
289+
"members" : [
290+
{
291+
"_id" : 0,
292+
"name" : "mdb0.example.net:27017",
293+
"health" : 1,
294+
"state" : 1,
295+
"stateStr" : "PRIMARY",
296+
"optime" : {
297+
"t" : 1345235703000,
298+
"i" : 1
299+
},
300+
"optimeDate" : ISODate("2012-08-17T20:35:03Z"),
301+
"self" : true
302+
},
303+
{
304+
"_id" : 1,
305+
"name" : "mdb1.example.net:27018",
306+
"health" : 1,
307+
"state" : 2,
308+
"stateStr" : "SECONDARY",
309+
"uptime" : 1260,
310+
"optime" : {
311+
"t" : 1345235703000,
312+
"i" : 1
313+
},
314+
"optimeDate" : ISODate("2012-08-17T20:35:03Z"),
315+
"lastHeartbeat" : ISODate("2012-08-17T20:55:58Z"),
316+
"pingMs" : 0
317+
},
318+
{
319+
"_id" : 2,
320+
"name" : "mdb2.example.net:27019",
321+
"health" : 1,
322+
"state" : 2,
323+
"stateStr" : "SECONDARY",
324+
"uptime" : 1256,
325+
"optime" : {
326+
"t" : 1345235703000,
327+
"i" : 1
328+
},
329+
"optimeDate" : ISODate("2012-08-17T20:35:03Z"),
330+
"lastHeartbeat" : ISODate("2012-08-17T20:55:58Z"),
331+
"pingMs" : 0
332+
}
333+
],
334+
"ok" : 1
335+
}
220336

221-
rs.status()

0 commit comments

Comments
 (0)