|
| 1 | +========================================= |
| 2 | +Change All the Hostnames in a Replica Set |
| 3 | +========================================= |
| 4 | + |
| 5 | +.. default-domain:: mongodb |
| 6 | + |
| 7 | +Synopsis |
| 8 | +-------- |
| 9 | + |
| 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. |
| 29 | + |
| 30 | +.. seealso:: |
| 31 | + |
| 32 | + - :doc:`/reference/replica-configuration` |
| 33 | + - :ref:`Replica Set Reconfiguration Process <replica-set-reconfiguration-usage>` |
| 34 | + - :func:`rs.conf()` and :func:`rs.reconfig()` |
| 35 | + |
| 36 | + And the following tutorials: |
| 37 | + |
| 38 | + - :doc:`/tutorial/deploy-replica-set` |
| 39 | + - :doc:`/tutorial/expand-replica-set` |
| 40 | + |
| 41 | +Procedure |
| 42 | +--------- |
| 43 | + |
| 44 | +.. _replica-set-change-hostname-no-downtime: |
| 45 | + |
| 46 | +Changing Names for All Members of a Replica Set without Downtime |
| 47 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 48 | + |
| 49 | +#. Make one of the :term:`secondary <secondary>` members of the |
| 50 | + :term:`replica set` accessible at the new location. |
| 51 | + |
| 52 | +.. QUESTION: I'm unclear on how to perform step 1, above -bg |
| 53 | + |
| 54 | +#. In a :program:`mongo` shell session, call :func:`rs.reconfigure()` to |
| 55 | + reconfigure the set. Wait for the moved secondary to catch up. |
| 56 | + |
| 57 | +#. Make sure that the clients are able to access the set at the new |
| 58 | + location. |
| 59 | + |
| 60 | +#. Repeat the above steps for each non-:term:`primary` member of the set. |
| 61 | + |
| 62 | +#. Use :dbcommand:`replSetStepDown` to step down the primary and run :func:`rs.reconfigure()` |
| 63 | + for the last time. |
| 64 | + |
| 65 | +.. _replica-set-change-hostname-downtime: |
| 66 | + |
| 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 |
| 75 | + |
| 76 | +#. Stop all members in the :term:`replica set`. |
| 77 | + |
| 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``: |
| 81 | + |
| 82 | + .. code-block:: sh |
| 83 | + |
| 84 | + mongod --dbpath /data/db/rs0-0 --port 27017 |
| 85 | + |
| 86 | +#. To change each member's host name, do the following *for each member*: |
| 87 | + |
| 88 | + #. Open a :program:`mongo` shell listening on the member's port number. For example: |
| 89 | + |
| 90 | + .. code-block:: sh |
| 91 | + |
| 92 | + mongo --port 27017 |
| 93 | + |
| 94 | +.. QUESTION: is the above command correct? |
| 95 | + |
| 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``: |
| 101 | + |
| 102 | + .. code-block:: javascript |
| 103 | + |
| 104 | + 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. |
| 110 | + |
| 111 | +#. Restart each member using the :option:`--replSet <mongod --replset>` option. |
| 112 | + |
| 113 | + For example, to restart member ``rs0-0`` on port ``27017`` in the ``rs0`` replica |
| 114 | + set, issue the following command: |
| 115 | + |
| 116 | + .. code-block:: sh |
| 117 | + |
| 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. |
| 123 | + |
| 124 | + :func:`rs.satus()` |
0 commit comments