@@ -63,59 +63,67 @@ Procedures
63
63
Changing Hostnames while Maintaining the Replica Set's Availability
64
64
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65
65
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``
67
82
68
83
#. For each :term:`secondary` in the replica set, perform the
69
84
following sequence of operations:
70
85
71
- .. todo note about stopping things
86
+ a. Stop the secondary.
72
87
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``:
78
91
79
92
.. code-block:: sh
80
93
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
84
95
85
96
#. 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:
89
99
90
100
.. code-block:: sh
91
101
92
- mongo --port 37017
93
-
94
- .. make clear that its the same host as in a.)
102
+ mongo --port 27017
95
103
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 ``:
98
106
99
107
.. code-block:: javascript
100
-
108
+
101
109
cfg = rs.conf()
102
110
103
- cfg.members[2 ].host = mongodb2.databse. example.net:27017
111
+ cfg.members[1 ].host = mongodb1. example.net:27018
104
112
105
113
rs.reconfigure(cfg)
106
114
107
115
See :doc:`/reference/replica-configuration` for more
108
116
information.
109
117
110
- #. Make sure that your client applications are able to access the
118
+ #. Make sure your client applications are able to access the
111
119
set at the new location and that the secondary has a chance to
112
120
catch up with the other members of the set.
113
121
114
122
Repeat the above steps for each non-primary member of the set.
115
123
116
124
#. Open a :program:`mongo` shell connected to the primary and step
117
125
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,
119
127
as follows:
120
128
121
129
.. code-block:: javascript
@@ -132,7 +140,7 @@ Changing Hostnames while Maintaining the Replica Set's Availability
132
140
133
141
cfg = rs.conf()
134
142
135
- cfg.members[0].host = mongodb0.databse. example.net:27017
143
+ cfg.members[0].host = mongodb0.example.net:27017
136
144
137
145
rs.reconfigure(cfg)
138
146
@@ -143,7 +151,61 @@ Changing Hostnames while Maintaining the Replica Set's Availability
143
151
#. To confirm the new configuration, call :func:`rs.status()` in the
144
152
:program:`mongo` shell.
145
153
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
+ }
147
209
148
210
.. _replica-set-change-hostname-downtime:
149
211
@@ -185,15 +247,15 @@ Changing All Hostnames in Replica Set at Once
185
247
186
248
use local
187
249
188
- cfg = db.system.replset.findOne( { "_id": "rs0 " } )
250
+ cfg = db.system.replset.findOne( { "_id": "rs " } )
189
251
190
252
cfg.members[0].host = "mdb0.example.net:27017"
191
253
192
254
cfg.members[1].host = "mdb1.example.net:27018"
193
255
194
256
cfg.members[2].host = "mdb2.example.net:27019"
195
257
196
- db.system.replset.update( { "_id": "rs0 " } , cfg )
258
+ db.system.replset.update( { "_id": "rs " } , cfg )
197
259
198
260
#. Stop the :program:`mongod` process on the member.
199
261
@@ -204,7 +266,7 @@ Changing All Hostnames in Replica Set at Once
204
266
205
267
.. code-block:: sh
206
268
207
- mongod --dbpath /data/db/ --port 27017 --replSet rs0
269
+ mongod --dbpath /data/db/ --port 27017 --replSet rs
208
270
209
271
#. Connect to one of the :program:`mongod` instances
210
272
using the :program:`mongo` shell. For example:
@@ -213,9 +275,62 @@ Changing All Hostnames in Replica Set at Once
213
275
214
276
mongo --port 27017
215
277
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.
218
280
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
+ }
220
336
221
- rs.status()
0 commit comments