Database Reference
In-Depth Information
To keep things simple, this example will rely on only one address. The next step is to get the other members up
and running. Do so by opening two more terminal windows, and then type the following into the first window to get
the second member up and running:
$ mkdir -p /db/active2/data
$ mongod --dbpath /db/active2/data --port 27022 --replSet testset
Next, type this into the second window to get the final (passive) member up and running:
$ mkdir -p /db/passive1/data
$ mongod --dbpath /db/passive1/data --port 27023 --replSet testset
At this point, you have three server instances running and communicating with each other; however, you do not
quite have your replica set running, because you haven't yet initialized the replica set and instructed each member
about its role and responsibilities.
To do that, you need to attach to one of the servers and initialize the replica set. The following code selects the
first server to attach to:
$mongo [ hostname]:27021
Next, you need to initialize the first member of this set to create its oplog and a default configuration document.
You can see the MongoD instance suggesting that you need to do this in your logfiles:
Mon Jun 3 21:25:23.712 [rsStart] replSet can't get local.system.replset config from self or any
seed (EMPTYCONFIG)
Mon Jun 3 21:25:23.712 [rsStart] replSet info you may need to run replSetInitiate --
rs.initiate() in the shell -- if that is not already done
So run the rs.initiate command:
> rs.initiate()
{
"info2" : "no configuration explicitly specified -- making one",
"me" : "[hostname]:27021",
"info" : "Config now saved locally. Should come online in about a minute.",
"ok" : 1
}
Finally, you should check the status of the replica set to determine whether it has been set up correctly:
>rs.status()
{
"set" : "testset",
"date" : ISODate("2013-06-03T11:28:58Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "[hostname]:27021",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
Search WWH ::




Custom Search