[Tom @ agilysys: Data] $ mongod -- replset MyApp -- dbpath ~ /Mongoreplicate/data/node1 -- port 4000
[Tom @ agilysys: Data] $ mongod -- replset MyApp -- dbpath ~ /Mongoreplicate/data/node2 -- Port 4001
[Tom @ agilysys: Data] $ mongod -- replset MyApp -- dbpath ~ /Mongoreplicate/data/Arbiter -- Port 4002
Thu Jun 20 18:48:30 [rsstart] replset can't get local. system. replset config from self or any seed (emptyconfig)
Thu Jun 20 18:48:40 [rsstart] replset can't get local. system. replset config from self or any seed (emptyconfig)
[Tom @ agilysys: ~] $ Mongo 192.168.205.157: 40000
> Rs. Initiate ();
> Rs. Add ("192.168.205.157: 40001 ");
MyApp: Primary> Rs. Add ("192.168.205.157: 40002", {arbiteronly: true });
MyApp: Primary> dB. ismaster ();
{
"Setname": "MyApp ",
"Ismaster": True,
"Secondary": false,
"Hosts ":[
"Localhost. localdomain: 40000 ",
"192.168.205.157: 40001"
],
"Arbiters ":[
"192.168.205.157: 40002"
],
"Primary": "localhost. localdomain: 40000 ",
"Me": "localhost. localdomain: 40000 ",
"Max bsonobjectsize": 16777216,
"LocalTime": ISODate ("2013-06-21T01: 54: 07.078Z "),
"OK": 1
}
Myapp: PRIMARY> rs. status ();
{
"Set": "myapp ",
"Date": ISODate ("2013-06-21T01: 54: 45Z "),
"MyState": 1,
"Members ":[
{
"_ Id": 0,
"Name": "localhost. localdomain: 40000 ",
"Health": 1,
"State": 1,
"StateStr": "PRIMARY ",
"Uptime": 1682,
"Optime": Timestamp (1371779616000, 1 ),
"Optimedate": isodate ("2013-06-21t01: 53: 36z "),
"Self": True
},
{
"_ Id": 1,
"Name": "192.168.205.157: 40001 ",
"Health": 1,
"State": 2,
"StateStr": "SECONDARY ",
"Uptime": 312,
"Optime": Timestamp (1371779616000, 1 ),
"Optimedate": isodate ("2013-06-21t01: 53: 36z "),
"Lastheartbeat": isodate ("2013-06-21t01: 54: 44z "),
"Pingms": 0
},
{
"_ Id": 2,
"Name": "192.168.205.157: 40002 ",
"Health": 1,
"State": 7,
"StateStr": "ARBITER ",
"Uptime": 69,
"LastHeartbeat": ISODate ("2013-06-21T01: 54: 44Z "),
"PingMs": 0
}
],
"OK": 1
}
Myapp: PRIMARY>
Occour exception: myapp: SECONDARY> uncaught exception: error: {"$ err": "not master and slaveOk = f
Solution:
Myapp: SECONDARY> db. getMongo (). setSlaveOk ();
Killed master machine:
Myapp: SECONDARY> rs. status ();
{
"Set": "myapp ",
"Date": ISODate ("2013-06-21T02: 12: 50Z "),
"MyState": 1,
"Members ":[
{
"_ Id": 0,
"Name": "localhost. localdomain: 40000 ",
"Health": 0,
"State": 8,
"Statestr": "(not reachable/Healthy )",
"Uptime": 0,
"Optime": Timestamp (1371779927000, 1 ),
"Optimedate": isodate ("2013-06-21t01: 58: 47z "),
"Lastheartbeat": isodate ("2013-06-21t02: 12: 00Z "),
"Pingms": 0,
"Errmsg": "socket exception [connect_error] For localhost. localdomain: 40000"
},
{
"_ Id": 1,
"Name": "192.168.205.157: 40001 ",
"Health": 1,
"State": 1,
"Statestr": "primary ",
"Uptime": 2008,
"Optime": Timestamp (1371779927000, 1 ),
"Optimedate": isodate ("2013-06-21t01: 58: 47z "),
"Self": True
},
{
"_ Id": 2,
"Name": "192.168.205.157: 40002 ",
"Health": 1,
"State": 7,
"StateStr": "ARBITER ",
"Uptime": 1153,
"LastHeartbeat": ISODate ("2013-06-21T02: 12: 50Z "),
"PingMs": 0
}
],
"OK": 1
}
Myapp: PRIMARY> use local;
Switched to db local
Myapp: PRIMARY> show collections;
Me
Oplog. rs
Replset. minvalid
System. indexes
System. replset
Myapp: PRIMARY> db. me. find ();
{"_ Id": ObjectId ("51c3b14792a90292ff53a662"), "host": "localhost. localdomain "}
Myapp: PRIMARY> db. oplog. rs. find ();
{"Ts": Timestamp (1371779373000, 1), "h": NumberLong ("7925987885612793873"), "v": 2, "op": "n ", "ns": "", "o": {"msg": "Reconfig set", "version": 2 }}
{"Ts": Timestamp (1371779616000, 1), "h": NumberLong ("5566948347773752308"), "v": 2, "op": "n ", "ns": "", "o": {"msg": "Reconfig set", "version": 3 }}
{"Ts": Timestamp (1371779927000, 1), "h": NumberLong ("-9138762778767060051"), "v": 2, "op": "I ", "ns": "bookstore. bookstore "," o ": {" _ id ": ObjectId (" 51c3b35722904e0337859938 ")," title ":" Oliver Twist "}}
Myapp: PRIMARY>
Myapp: PRIMARY> db. getReplicationInfo ();
{
"LogSizeMB": 1453.5435546875,
"UsedMB": 0.01,
"TimeDiff": 554,
"TimeDiffHours": 0.15,
"TFirst": "Thu Jun 20 2013 18:49:33 GMT-0700 (PDT )",
"TLast": "Thu Jun 20 2013 18:58:47 GMT-0700 (PDT )",
"Now": "Thu Jun 20 2013 19:32:04 GMT-0700 (PDT )"
}
MyApp: Primary>