Setting up a MongoDB replica set or load balancer using the Windows command prompt involves specific commands and configurations. Below are the steps for both approaches:
1. Setting Up a MongoDB Replica Set on Windows Using Command Prompt:
Prerequisites:
- MongoDB installed on Windows.
- Administrative privileges to create and manage directories.
Mongo db load
balance For more
under standing click below link https://drive.google.com/open?id=0B7xaspetzd9-UE80RmdCbHp5X2c https://www.youtube.com/watch?v=okrZdlO9_3Q Or Download
mongodb-win32-x86_64-3.0.7.zip file 1. Unzip a particular location like :
D:\Software\MongoDb 2. Inside D drive create a folder like
data 3. Again create another three folder
like db,db1,db2 Below command
d:>mkdir
\data\rs1 \data\rs2 \data\rs3 D:\Software\MongoDb\mongodb\bin>mongod
--replSet kartik --logpath \data\rs1\1.log --dbpath \data\rs1 --port 27017
--smallfiles --oplogSize 64 4. Now start the mongo service by below
command below: mongod --port
"PORT" --dbpath "YOUR_DB_DATA_PATH" --replSet
"REPLICA_SET_INSTANCE_NAME" 1) D:\Software\MongoDb\mongodb\bin>mongod
--replSet kartik --logpath \data\rs1\1.log --dbpath \data\rs1 --port 27017
--smallfiles --oplogSize 64 2) D:\Software\MongoDb\mongodb\bin>mongod
--replSet kartik --logpath \data\rs2\2.log --dbpath \data\rs2 --port 27018
--smallfiles --oplogSize 64 3) D:\Software\MongoDb\mongodb\bin>mongod
--replSet kartik --logpath \data\rs3\3.log --dbpath \data\rs3 --port 27019
--smallfiles --oplogSize 64 5. Now start the mongo server below
command: mongo.exe or mongo --host "host
name" --port 27017 like mongo --host "192.168.208.181" --port
27017 D:\Software\MongoDb\mongodb\bin>mongo.exe or goto line no 199 MongoDB shell version: 3.0.7 connecting to: test > rs.initiate() { "info2" : "no
configuration explicitly specified -- making one", "me" :
"IN-L1155:27017", "ok" : 1 } kartik:SECONDARY>
rs.add("192.168.65.143:27017") { "ok" : 0, "errmsg" : "Quorum check
failed because not enough voting nodes responded; required 2 but only the
following 1 voting nodes responded: IN-L1155:27017; the following nodes did
not respond affirmatively: 192.168.65.143:27017 failed with Failed attempt to
connect to 192.168.65.143:27017; couldn't connect to server
192.168.65.143:27017 (192.168.65.143), connection attempt failed", "code" : 74 } kartik:PRIMARY>
rs.add("192.168.65.143:27017") { "ok" : 0, "errmsg" : "Quorum check
failed because not enough voting nodes responded; required 2 but only the
following 1 voting nodes responded: IN-L1155:27017; the following nodes did
not respond affirmatively: 192.168.65.143:27017 failed with Failed attempt to
connect to 192.168.65.143:27017; couldn't connect to server
192.168.65.143:27017 (192.168.65.143), connection attempt failed", "code" : 74 } kartik:PRIMARY>
rs.add("192.168.208.181:27018") { "ok" : 1 } kartik:PRIMARY> rs.config()
{ "_id" :
"rs0", "version" : 2, "members" : [ { "_id" :
0, "host"
: "IN-L1155:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1, "tags"
: {
},
"slaveDelay" : 0,
"votes" : 1 }, { "_id"
: 1, "host"
: "192.168.208.181:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1, "tags"
: {
},
"slaveDelay" : 0,
"votes" : 1 } ], "settings" : {
"chainingAllowed" : true,
"heartbeatTimeoutSecs" : 10,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : { "w" :
1,
"wtimeout" : 0 } }
}
kartik:PRIMARY> rs.add("192.168.208.181:27019")
{ "ok" : 1 }
kartik:PRIMARY> rs.config()
{ "_id" :
"rs0", "version" : 3, "members" : [ { "_id"
: 0, "host"
: "IN-L1155:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1, "tags"
: {
},
"slaveDelay" : 0,
"votes" : 1 }, { "_id"
: 1, "host"
: "192.168.208.181:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1, "tags" :
{
},
"slaveDelay" : 0, "votes"
: 1 }, { "_id" :
2, "host" :
"192.168.208.181:27019",
"arbiterOnly" : false,
"buildIndexes" : true, "hidden"
: false,
"priority" : 1, "tags" :
{
},
"slaveDelay" : 0, "votes"
: 1 } ], "settings" : {
"chainingAllowed" : true,
"heartbeatTimeoutSecs" : 10,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : { "w" : 1,
"wtimeout" : 0 } }
}
kartik:PRIMARY> rs.status()
{ "set" : "rs0", "date" :
ISODate("2016-10-13T12:29:48.413Z"), "myState" : 1, "members" : [ { "_id" :
0, "name" :
"IN-L1155:27017", "health"
: 1, "state"
: 1,
"stateStr" : "PRIMARY", "uptime"
: 3268, "optime"
: Timestamp(1476361776, 1),
"optimeDate" : ISODate("2016-10-13T12:29:36Z"),
"electionTime" : Timestamp(1476358572, 2),
"electionDate" : ISODate("2016-10-13T11:36:12Z"),
"configVersion" : 3, "self" :
true }, { "_id" :
1, "name" :
"192.168.208.181:27018", "health"
: 1, "state"
: 2,
"stateStr" : "SECONDARY", "uptime"
: 136, "optime"
: Timestamp(1476361776, 1),
"optimeDate" : ISODate("2016-10-13T12:29:36Z"),
"lastHeartbeat" :
ISODate("2016-10-13T12:29:46.551Z"),
"lastHeartbeatRecv" :
ISODate("2016-10-13T12:29:48.213Z"), "pingMs"
: 0,
"syncingTo" : "IN-L1155:27017",
"configVersion" : 3 }, { "_id" :
2, "name" :
"192.168.208.181:27019", "health"
: 1, "state"
: 2,
"stateStr" : "SECONDARY", "uptime"
: 11, "optime"
: Timestamp(1476361776, 1),
"optimeDate" : ISODate("2016-10-13T12:29:36Z"),
"lastHeartbeat" :
ISODate("2016-10-13T12:29:46.554Z"),
"lastHeartbeatRecv" :
ISODate("2016-10-13T12:29:46.570Z"), "pingMs"
: 0,
"configVersion" : 3 } ], "ok" : 1
} kartik:PRIMARY> D:\Software\MongoDb\mongodb\bin>mongo
--host "192.168.208.181" --port 27018 MongoDB shell version: 3.0.7 connecting to: 192.168.208.181:27018/test kartik:SECONDARY> use docstorage switched to db docstorage kartik:SECONDARY> rs.slaveOk() kartik:SECONDARY> use docstorage switched to db docstorage kartik:SECONDARY> show collections Data system.indexes kartik:SECONDARY> db.data.find() kartik:SECONDARY> D:\Software\MongoDb\mongodb\bin>mongo
--port 27017 MongoDB shell version: 3.0.7 connecting to: 127.0.0.1:27017/test kartik:PRIMARY>
rs.add("IN-L1155:27018") { "ok" : 1 } kartik:PRIMARY>
rs.add("IN-L1155:27019") { "ok" : 1 } kartik:PRIMARY> rs.status() { "set" :
"kartik", "date" :
ISODate("2016-11-16T09:57:50.873Z"), "myState" : 1, "members" : [ { "_id" :
0, "name" :
"IN-L1155:27017", "health"
: 1, "state"
: 1,
"stateStr" : "PRIMARY", "uptime"
: 884, "optime"
: Timestamp(1479290263, 1),
"optimeDate" : ISODate("2016-11-16T09:57:43Z"),
"electionTime" : Timestamp(1479289556, 2),
"electionDate" : ISODate("2016-11-16T09:45:56Z"),
"configVersion" : 3, "self" :
true }, { "_id" :
1, "name" :
"IN-L1155:27018", "health"
: 1, "state"
: 2,
"stateStr" : "SECONDARY", "uptime"
: 16, "optime"
: Timestamp(1479290263, 1),
"optimeDate" : ISODate("2016-11-16T09:57:43Z"),
"lastHeartbeat" :
ISODate("2016-11-16T09:57:49.065Z"),
"lastHeartbeatRecv" :
ISODate("2016-11-16T09:57:50.062Z"), "pingMs"
: 0,
"syncingTo" : "IN-L1155:27017",
"configVersion" : 3 }, { "_id" :
2, "name" :
"IN-L1155:27019", "health"
: 1, "state"
: 2,
"stateStr" : "SECONDARY", "uptime"
: 7, "optime"
: Timestamp(1479290263, 1),
"optimeDate" : ISODate("2016-11-16T09:57:43Z"),
"lastHeartbeat" :
ISODate("2016-11-16T09:57:49.067Z"),
"lastHeartbeatRecv" :
ISODate("2016-11-16T09:57:49.082Z"), "pingMs"
: 2,
"syncingTo" : "IN-L1155:27018",
"configVersion" : 3 } ], "ok" : 1 } kartik:PRIMARY>
db.assignment.insert({name:"Java",duedate:"25th
January"}); WriteResult({ "nInserted" : 1 }) kartik:PRIMARY>
db.assignment.find().preety(); E QUERY TypeError: Object DBQuery:
test.assignment -> { } has no method 'preety' at (shell):1:22 kartik:PRIMARY>
db.assignment.find().pretty(); { "_id" :
ObjectId("582c2e925f6adbe1d3d069b2"), "name" :
"Java", "duedate" : "25th
January" } kartik:PRIMARY> D:\Software\MongoDb\mongodb\bin>mongo
--port 27018 MongoDB shell version: 3.0.7 connecting to: 127.0.0.1:27018/test kartik:SECONDARY>
db.assignment.find().pretty(); Error: error: { "$err" :
"not master and slaveOk=false", "code" : 13435 } kartik:SECONDARY> rs.slaveOk() kartik:SECONDARY>
db.assignment.find().pretty(); { "_id" :
ObjectId("582c2e925f6adbe1d3d069b2"), "name" :
"Java", "duedate" : "25th
January" } kartik:SECONDARY> |
0 Comments