|
| 1 | +================================= |
| 2 | +Convert a Secondary to an Arbiter |
| 3 | +================================= |
| 4 | + |
| 5 | +.. default-domain:: mongodb |
| 6 | + |
| 7 | +You can convert a secondary member to an arbiter either by shutting down |
| 8 | +the secondary and restarting it as an arbiter, or by starting the |
| 9 | +arbiter on a new port and then shutting down the instance of the |
| 10 | +secondary. This document describes both procedures. |
| 11 | + |
| 12 | +Synopsis |
| 13 | +-------- |
| 14 | + |
| 15 | +To convert a secondary to an arbiter you have two options: |
| 16 | + |
| 17 | +#. Run the arbiter on the same port number as you ran the secondary. |
| 18 | + In this option, you must shut down the secondary and remove its data |
| 19 | + before restarting and reconfiguring it as an arbiter. |
| 20 | + |
| 21 | + For this procedure, see :ref:`replica-set-convert-secondary-to-arbiter-same-port`. |
| 22 | + |
| 23 | +#. Run the arbiter on a new port number. In this option, you can |
| 24 | + reconfigure the server as an arbiter before shutting down the |
| 25 | + instance running as a secondary. |
| 26 | + |
| 27 | + For this procedure, see :ref:`replica-set-convert-secondary-to-arbiter`. |
| 28 | + |
| 29 | +.. seealso:: |
| 30 | + |
| 31 | + - :ref:`replica-set-arbiters` |
| 32 | + - :ref:`replica-set-arbiter-nodes` |
| 33 | + - :method:`rs.addArb()` |
| 34 | + |
| 35 | +Procedures |
| 36 | +---------- |
| 37 | + |
| 38 | +.. _replica-set-convert-secondary-to-arbiter-same-port: |
| 39 | + |
| 40 | +Convert a Secondary to an Arbiter and Reuse the Port Number |
| 41 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 42 | + |
| 43 | +#. Remove the :term:`secondary` from the :term:`replica set` by calling |
| 44 | + the :method:`rs.remove()` method while connected to the current |
| 45 | + :term:`primary` in the :program:`mongo` shell: |
| 46 | + |
| 47 | + .. code-block:: javascript |
| 48 | + |
| 49 | + rs.remove("<hostname>:<port>") |
| 50 | + |
| 51 | +#. Verify that the replica set no longer includes the secondary by |
| 52 | + calling the :method:`rs.config()` method in the :program:`mongo` shell: |
| 53 | + |
| 54 | + .. code-block:: javascript |
| 55 | + |
| 56 | + rs.config() |
| 57 | + |
| 58 | +#. Shut down the secondary. |
| 59 | + |
| 60 | +#. Move the secondary's data directory to an archive folder. For example: |
| 61 | + |
| 62 | + .. code-block:: sh |
| 63 | + |
| 64 | + mv /data/db /data/db-old |
| 65 | + |
| 66 | + .. optional:: You may remove the data instead. |
| 67 | + |
| 68 | +#. Modify your application so that MongoDB queries don't reach |
| 69 | + the secondary. |
| 70 | + |
| 71 | +#. Create a new, empty data directory to point to when restarting the |
| 72 | + :program:`mongod` instance. You can reuse the previous name. For |
| 73 | + example: |
| 74 | + |
| 75 | + .. code-block:: sh |
| 76 | + |
| 77 | + mkdir /data/db |
| 78 | + |
| 79 | +#. Restart the :program:`mongod` instance for the secondary, specifying |
| 80 | + the port number, the empty data directory, and the replica set. You |
| 81 | + can use the same port number you used before. Issue a command similar |
| 82 | + to the following: |
| 83 | + |
| 84 | + .. code-block:: sh |
| 85 | + |
| 86 | + mongod --port 27021 --dbpath /data/db --replSet rs |
| 87 | + |
| 88 | +#. In the :program:`mongo` shell convert the secondary to an arbiter |
| 89 | + using the :method:`rs.addArb()` method: |
| 90 | + |
| 91 | + .. code-block:: javascript |
| 92 | + |
| 93 | + rs.addArb("<hostname>:<port>") |
| 94 | + |
| 95 | +#. Verify the arbiter belongs to the replica set by calling the |
| 96 | + :method:`rs.config()` method in the :program:`mongo` shell. |
| 97 | + |
| 98 | + .. code-block:: javascript |
| 99 | + |
| 100 | + rs.config() |
| 101 | + |
| 102 | + The arbiter member should include the following: |
| 103 | + |
| 104 | + .. code-block:: javascript |
| 105 | + |
| 106 | + "arbiterOnly" : true |
| 107 | + |
| 108 | +.. _replica-set-convert-secondary-to-arbiter: |
| 109 | + |
| 110 | +Convert a Secondary to an Arbiter Running on a New Port Number |
| 111 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 112 | + |
| 113 | +#. Create a new, empty data directory. For example: |
| 114 | + |
| 115 | + .. code-block:: sh |
| 116 | + |
| 117 | + mkdir /data/db-temp |
| 118 | + |
| 119 | +#. Start a new :program:`mongod` instance on a different port from the |
| 120 | + secondary, specifying the new data directory and the existing replica |
| 121 | + set. Issue a command similar to the following: |
| 122 | + |
| 123 | + .. code-block:: sh |
| 124 | + |
| 125 | + mongod --port 27021 --dbpath /data/db --replSet rs |
| 126 | + |
| 127 | +#. In the :program:`mongo` shell connected to the current primary, |
| 128 | + convert the secondary to an arbiter using the :method:`rs.addArb()` |
| 129 | + method: |
| 130 | + |
| 131 | + .. code-block:: javascript |
| 132 | + |
| 133 | + rs.addArb("<hostname>:<port>") |
| 134 | + |
| 135 | +#. Verify the arbiter belongs to the replica set by calling the |
| 136 | + :method:`rs.config()` method in the :program:`mongo` shell. |
| 137 | + |
| 138 | + .. code-block:: javascript |
| 139 | + |
| 140 | + rs.config() |
| 141 | + |
| 142 | + The arbiter member should include the following: |
| 143 | + |
| 144 | + .. code-block:: javascript |
| 145 | + |
| 146 | + "arbiterOnly" : true |
| 147 | + |
| 148 | +#. Shut down the secondary. |
| 149 | + |
| 150 | +#. If you have an application connection string referencing the old |
| 151 | + secondary, remove the reference. |
| 152 | + |
| 153 | +#. Remove the :term:`secondary` from the :term:`replica set` by calling |
| 154 | + the :method:`rs.remove()` method in the :program:`mongo` shell: |
| 155 | + |
| 156 | + .. code-block:: javascript |
| 157 | + |
| 158 | + rs.remove("<hostname>:<port>") |
| 159 | + |
| 160 | +#. Verify that the replica set no longer includes the secondary by |
| 161 | + calling the :method:`rs.config()` method in the :program:`mongo` shell: |
| 162 | + |
| 163 | + .. code-block:: javascript |
| 164 | + |
| 165 | + rs.config() |
| 166 | + |
| 167 | +#. Move the secondary's data directory to an archive folder. For example: |
| 168 | + |
| 169 | + .. code-block:: sh |
| 170 | + |
| 171 | + mv /data/db /data/db-old |
| 172 | + |
| 173 | + .. optional:: You may remove the data instead. |
0 commit comments