Skip to content

Change host rs 2 #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 116 additions & 38 deletions draft/tutorial/change-hostnames-in-a-replica-set.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,64 +58,100 @@ availability requirements, you may:
Procedures
----------

.. _givens:

Given a :term:`replica set` with three members:

- ``database0.example.net:27017`` (the :term:`primary`)

- ``database1.example.net:27018``

- ``database2.example.net:27019``

And with the following :func:`rs.config()` output:

.. code-block:: javascript

{
"_id" : "rs",
"version" : 3,
"members" : [
{
"_id" : 0,
"host" : "database0.example.net:27017"
},
{
"_id" : 1,
"host" : "database1.example.net:27018"
},
{
"_id" : 2,
"host" : "database2.example.net:27019"
}
]
}

The following procedures change the members' hostnames as follows:

- ``mongodb0.example.net:27017`` (the primary)

- ``mongodb1.example.net:27018``

- ``mongodb2.example.net:27019``

Use the procedure appropriate to your situation.

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

Changing Hostnames while Maintaining the Replica Set's Availability
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. todo given a dummy config.
This procedure uses the above ":ref:`givens <givens>`".

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

.. todo note about stopping things
a. Stop the secondary.

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

.. code-block:: sh

mongod --dbpath /data/db/ --port 37017

.. make it clear that the db path is the same.
mongod --dbpath /data/db1 --port 37018

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

.. code-block:: sh

mongo --port 37017

.. make clear that its the same host as in a.)
mongo --port 27017

#. Then run the following reconfiguration option, for the
:data:`members[n].host` value where ``n`` is ``2``:
#. Run the following reconfigure option, for the
:data:`members[n].host` value where ``n`` is ``1``:

.. code-block:: javascript

cfg = rs.conf()

cfg.members[2].host = mongodb2.databse.example.net:27017
cfg.members[1].host = mongodb1.example.net:27018

rs.reconfigure(cfg)

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

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

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

#. Open a :program:`mongo` shell connected to the primary and step
down the primary using :dbcommand:`replSetStepDown`. In the
:program:`mongo` shell, use the the :func:`rs.stepDown()` wrapper,
:program:`mongo` shell, use the :func:`rs.stepDown()` wrapper,
as follows:

.. code-block:: javascript
Expand All @@ -132,35 +168,58 @@ Changing Hostnames while Maintaining the Replica Set's Availability

cfg = rs.conf()

cfg.members[0].host = mongodb0.databse.example.net:27017
cfg.members[0].host = mongodb0.example.net:27017

rs.reconfigure(cfg)

#. Start the original primary.

#. Open a :program:`mongo` shell connected to the primary.

#. To confirm the new configuration, call :func:`rs.status()` in the
#. To confirm the new configuration, call :func:`rs.config()` in the
:program:`mongo` shell.

.. output ofchanged rsconfig.
Your output should resemble:

.. code-block:: javascript

{
"_id" : "rs",
"version" : 4,
"members" : [
{
"_id" : 0,
"host" : "mongodb0.example.net:27017"
},
{
"_id" : 1,
"host" : "mongodb1.example.net:27018"
},
{
"_id" : 2,
"host" : "mongodb2.example.net:27019"
}
]
}

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

Changing All Hostnames in Replica Set at Once
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This procedure uses the above ":ref:`givens <givens>`".

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

#. Restart each member *on a different port* and *without* using the
:option:`--replSet <mongod --replset>` run-time option. Changing
the port number during maintenance prevents clients from connecting
to this host while you perform maintenance. Use a command that
resembles the following:
to this host while you perform maintenance. Use the member's usual :option:`--dbpath`, which in this
example is ``/data/db1``. Use a command that resembles the following:

.. code-block:: sh

mongod --dbpath /data/db/ --port 37017
mongod --dbpath /data/db1/ --port 37017

#. For each member of the replica set, perform the following sequence
of operations:
Expand All @@ -185,15 +244,15 @@ Changing All Hostnames in Replica Set at Once

use local

cfg = db.system.replset.findOne( { "_id": "rs0" } )
cfg = db.system.replset.findOne( { "_id": "rs" } )

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

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

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

db.system.replset.update( { "_id": "rs0" } , cfg )
db.system.replset.update( { "_id": "rs" } , cfg )

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

Expand All @@ -204,7 +263,7 @@ Changing All Hostnames in Replica Set at Once

.. code-block:: sh

mongod --dbpath /data/db/ --port 27017 --replSet rs0
mongod --dbpath /data/db1/ --port 27017 --replSet rs

#. Connect to one of the :program:`mongod` instances
using the :program:`mongo` shell. For example:
Expand All @@ -213,9 +272,28 @@ Changing All Hostnames in Replica Set at Once

mongo --port 27017

#. Run :func:`rs.stdatus()` to confirm that the set has reconfigured.
For example:
#. To confirm the new configuration, call :func:`rs.config()` in the
:program:`mongo` shell.

Your output should resemble:

.. code-block:: sh
.. code-block:: javascript

rs.status()
{
"_id" : "rs",
"version" : 4,
"members" : [
{
"_id" : 0,
"host" : "mongodb0.example.net:27017"
},
{
"_id" : 1,
"host" : "mongodb1.example.net:27018"
},
{
"_id" : 2,
"host" : "mongodb2.example.net:27019"
}
]
}