Command LineEach mongod participating in the set should have a --replSet parameter on its command line. The syntax is
mongod --replSet setname --rest
setname is the logical name of the set.
Initial SetupWe use the replSetInitiate command for initial configuration of a replica set. Send the initiate command to a single server to christen the set. The member being initiated may have initial data; the other servers in the set should be empty. > db.runCommand( { replSetInitiate : <config_object> } )
A shorthand way to type the above is via a helper method in the shell: > rs.initiate(<config_object>) A quick way to initiate a set is to leave out the config object parameter. The initial set will then consist of the member to which the shell is communicating, along with all the seeds that member knows of. However, see the configuration object details below for more options. > rs.initiate() The Replica Set Config ObjectThe local.system.replset collection holds a singleton object which contains the replica set configuration. The config object automatically propagates among members of the set. The object is not directly manipulated, but rather changed via commands (such as replSetInitiate). Minimum Config - Required ArgumentsAt its simplest, the config object contains the name of the replica set and a list of its members: {
_id : <setname>,
members : [
{_id : 0, host : <host0>},
{_id : 1, host : <host1>},
...
]
}
Every replica set configuration must contain an _id field and a members field with one or more hosts listed.
Advanced Config - Optional ArgumentsThere are many optional settings that can also be configured using the config object. The full set is: {
_id : <setname>,
members: [
{
_id : <ordinal>,
host : <hostname[:port]>
[, arbiterOnly : true]
[, buildIndexes : <bool>]
[, hidden : true]
[, priority: <priority>]
[, tags: {loc1 : desc1, loc2 : desc2, ..., locN : descN}]
[, slaveDelay : <n>]
[, votes : <n>]
}
, ...
],
[settings: {
[getLastErrorDefaults: <lasterrdefaults>]
[, getLastErrorModes : <modes>]
}]
}
Member optionsEach member can be configured to have any of the following options.
Set optionsThe final optional argument, settings, can be used to set options on the set as a whole. Often one can leave out settings completely from the config as the defaults are reasonable.
Shell Example 1> // all at once method > cfg = { ... _id : "acme_a", ... members : [ ... { _id : 0, host : "sf1.acme.com" }, ... { _id : 1, host : "sf2.acme.com" }, ... { _id : 2, host : "sf3.acme.com" } ] } > rs.initiate(cfg) > rs.status() Shell Example 2$ # incremental configuration method $ mongo sf1.acme.com/admin > rs.initiate(); > rs.add("sf2.acme.com"); > rs.add("sf3.acme.com"); > rs.status(); See Also |

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