@@ -58,28 +58,56 @@ availability requirements, you may:
58
58
Procedures
59
59
----------
60
60
61
- .. _replica-set-change-hostname-no-downtime:
62
-
63
- Changing Hostnames while Maintaining the Replica Set's Availability
64
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61
+ .. _givens:
65
62
66
- Given a :term:`replica set` with three members
63
+ Given a :term:`replica set` with three members:
67
64
68
65
- ``database0.example.net:27017`` (the :term:`primary`)
69
66
70
67
- ``database1.example.net:27018``
71
68
72
69
- ``database2.example.net:27019``
73
70
74
- This procedure changes the hostnames to the following, while maintaining
75
- the set's availability:
71
+ And with the following :func:`rs.config()` output:
72
+
73
+ .. code-block:: javascript
74
+
75
+ {
76
+ "_id" : "rs",
77
+ "version" : 3,
78
+ "members" : [
79
+ {
80
+ "_id" : 0,
81
+ "host" : "database0.example.net:27017"
82
+ },
83
+ {
84
+ "_id" : 1,
85
+ "host" : "database1.example.net:27018"
86
+ },
87
+ {
88
+ "_id" : 2,
89
+ "host" : "database2.example.net:27019"
90
+ }
91
+ ]
92
+ }
93
+
94
+ The following procedures change the members' hostnames as follows:
76
95
77
96
- ``mongodb0.example.net:27017`` (the primary)
78
97
79
98
- ``mongodb1.example.net:27018``
80
99
81
100
- ``mongodb2.example.net:27019``
82
101
102
+ Use the procedure appropriate to your situation.
103
+
104
+ .. _replica-set-change-hostname-no-downtime:
105
+
106
+ Changing Hostnames while Maintaining the Replica Set's Availability
107
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108
+
109
+ This procedure uses the above ":ref:`givens <givens>`".
110
+
83
111
#. For each :term:`secondary` in the replica set, perform the
84
112
following sequence of operations:
85
113
@@ -148,81 +176,50 @@ the set's availability:
148
176
149
177
#. Open a :program:`mongo` shell connected to the primary.
150
178
151
- #. To confirm the new configuration, call :func:`rs.status ()` in the
179
+ #. To confirm the new configuration, call :func:`rs.config ()` in the
152
180
:program:`mongo` shell.
153
181
154
- Your output should look similar to this :
182
+ Your output should resemble :
155
183
156
184
.. code-block:: javascript
157
185
158
186
{
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
- }
187
+ "_id" : "rs",
188
+ "version" : 4,
189
+ "members" : [
190
+ {
191
+ "_id" : 0,
192
+ "host" : "mongodb0.example.net:27017"
193
+ },
194
+ {
195
+ "_id" : 1,
196
+ "host" : "mongodb1.example.net:27018"
197
+ },
198
+ {
199
+ "_id" : 2,
200
+ "host" : "mongodb2.example.net:27019"
201
+ }
202
+ ]
203
+ }
209
204
210
205
.. _replica-set-change-hostname-downtime:
211
206
212
207
Changing All Hostnames in Replica Set at Once
213
208
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214
209
210
+ This procedure uses the above ":ref:`givens <givens>`".
211
+
215
212
#. Stop all members in the :term:`replica set`.
216
213
217
214
#. Restart each member *on a different port* and *without* using the
218
215
:option:`--replSet <mongod --replset>` run-time option. Changing
219
216
the port number during maintenance prevents clients from connecting
220
- to this host while you perform maintenance. Use a command that
221
- resembles the following:
217
+ to this host while you perform maintenance. Use the member's usual :option:`--dbpath`, which in this
218
+ example is ``/data/db1``. Use a command that resembles the following:
222
219
223
220
.. code-block:: sh
224
221
225
- mongod --dbpath /data/db / --port 37017
222
+ mongod --dbpath /data/db1 / --port 37017
226
223
227
224
#. For each member of the replica set, perform the following sequence
228
225
of operations:
@@ -249,11 +246,11 @@ Changing All Hostnames in Replica Set at Once
249
246
250
247
cfg = db.system.replset.findOne( { "_id": "rs" } )
251
248
252
- cfg.members[0].host = "mdb0 .example.net:27017"
249
+ cfg.members[0].host = "mongodb0 .example.net:27017"
253
250
254
- cfg.members[1].host = "mdb1 .example.net:27018"
251
+ cfg.members[1].host = "mongodb1 .example.net:27018"
255
252
256
- cfg.members[2].host = "mdb2 .example.net:27019"
253
+ cfg.members[2].host = "mongodb2 .example.net:27019"
257
254
258
255
db.system.replset.update( { "_id": "rs" } , cfg )
259
256
@@ -266,7 +263,7 @@ Changing All Hostnames in Replica Set at Once
266
263
267
264
.. code-block:: sh
268
265
269
- mongod --dbpath /data/db / --port 27017 --replSet rs
266
+ mongod --dbpath /data/db1 / --port 27017 --replSet rs
270
267
271
268
#. Connect to one of the :program:`mongod` instances
272
269
using the :program:`mongo` shell. For example:
@@ -275,62 +272,28 @@ Changing All Hostnames in Replica Set at Once
275
272
276
273
mongo --port 27017
277
274
278
- #. To confirm that the set has reconfigured , call :func:`rs.status ()` in the
275
+ #. To confirm the new configuration , call :func:`rs.config ()` in the
279
276
:program:`mongo` shell.
280
277
281
- Your output should look similar to this :
278
+ Your output should resemble :
282
279
283
280
.. code-block:: javascript
284
281
285
282
{
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
- }
336
-
283
+ "_id" : "rs",
284
+ "version" : 4,
285
+ "members" : [
286
+ {
287
+ "_id" : 0,
288
+ "host" : "mongodb0.example.net:27017"
289
+ },
290
+ {
291
+ "_id" : 1,
292
+ "host" : "mongodb1.example.net:27018"
293
+ },
294
+ {
295
+ "_id" : 2,
296
+ "host" : "mongodb2.example.net:27019"
297
+ }
298
+ ]
299
+ }
0 commit comments