|
Adding a new member to an existing replica set is easy. The new member should either have an empty data directory or a recent copy of the data from another set member. When starting mongod on the new server, provide the replica set name: $ mongod --replSet foo After bringing up the new server (we'll call it broadway:27017) we need to add it to the set – we connect to our primary server using the shell: $ mongo --host our_primary_host MongoDB shell version: ... connecting to: test PRIMARY> rs.add("broadway:27017"); { "ok" : 1 } After adding the node it will synchronize (doing a full initial sync if starting empty, see below) and then come online as a secondary. You can also specify any member configuration options using rs.add(). Some examples: > // add an arbiter > rs.add({_id: 3, host: "broadway:27017", arbiterOnly: true}) > > // add a hidden member > rs.add({_id: 3, host: "broadway:27017", priority: 0, hidden: true}) > > // add a member with tags > rs.add({_id: 3, host: "broadway:27017", tags: {dc : "nyc", rack: "rack1"}}) Adding a former memberA member can be removed from a set and re-added later. If the removed member's data is still relatively fresh, it can recover and catch up from its old data set. See the rs.add() and rs.remove() helpers. If there is any trouble re-adding the member, restart its mongod process. You may also need to add it back with its former _id (although probably not if mongod were restarted). Starting with an existing copy of the datasetIf you have a backup or snapshot of an existing member, you can move the data files to a new machine and use them to quickly add a new member. These files must be:
You do not have to make any modifications to the files before starting up a member. In versions before v2.0, you must start the new member before running rs.add(). In v2.0+ you can do it in either order, although a majority of the new set must be up for the reconfig to work. Two examples:
Additionally with versions before v2.0 you need to restart mongod on the newly added node after the rs.add(). See Also |

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.
blog comments powered by Disqus