I am on Windows 10 Environment. I would like to Implement Replica Set on MongoDB. I am facing some issues..
For that, I cover almost many tutorials to implement the things on Windows Machine.
I want to create a replica set consisting of a primary node and another node, which will be replicating the data.
My structure is like this:
- Install folder: C:/Programs Files\MongoDb\Server\3.4\bin\
- Database folder: C:/data/db
- Log file folder: C:/data/log
- Config: C:/data/mongod.cfg
I have defined the service with this command:
sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\data\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
I have started the service with this command:
net start mongodb
It runs successfully.
However, now I am getting problems with replication. What I did to set up the replica set is:
- create three subfolders under the data folder named rs1, rs2, rs3, using the command
mkdir \data\rs1 \data\rs1 \data\rs2
- Implement the Replset for replication of three servers.
My three startup commands are: 1. start mongod --replSet udd --logpath \data\rs1\1.log --dbpath \data\rs1 --port 27017 --smallfiles --oplogSize 64 2. start mongod --replSet udd --logpath \data\rs1\2.log --dbpath \data\rs2 --port 27018 --smallfiles --oplogSize 64 3. start mongod --replSet udd --logpath \data\rs1\3.log --dbpath \data\rs3 --port 27019 --smallfiles --oplogSize 64
With those running, I can type mongo --port 27017
; this connects properly to 127.0.0.1:27017/
Now my problem is that earlier the mongo shell prompt said udd:PRIMARY>; but now it has changed to say: udd:OTHER>
Please guide me how I can move forward with replication; any help is really appreciated.
My rs.reconfig(config,{"force":true}) will be
udd:OTHER> config = {_id: "udd", members: [
... {_id: 0, host: "127.0.0.1:27017"},
... {_id: 1, host: "127.0.0.1:27018"},
... {_id: 2, host: "127.0.0.1:27019"}
... ]}
{
"_id" : "udd",
"members" : [
{
"_id" : 0,
"host" : "127.0.0.1:27017"
},
{
"_id" : 1,
"host" : "127.0.0.1:27018"
},
{
"_id" : 2,
"host" : "127.0.0.1:27019"
}
]
}
udd:OTHER> rs.reconfig(config,{"force":true})
{ "ok" : 1 }
udd:OTHER> rs.status()
{
"set" : "udd",
"date" : ISODate("2018-01-31T11:58:15.717Z"),
"myState" : 2,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"appliedOpTime" : {
"ts" : Timestamp(1517381781, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1517381781, 1),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "127.0.0.1:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1506,
"optime" : {
"ts" : Timestamp(1517381781, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-01-31T06:56:21Z"),
"configVersion" : 37530,
"self" : true
},
{
"_id" : 1,
"name" : "127.0.0.1:27018",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2018-01-31T11:58:15.677Z"),
"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "No connection could be made because the target machine actively refused it.",
"configVersion" : -1
},
{
"_id" : 2,
"name" : "127.0.0.1:27019",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2018-01-31T11:58:15.670Z"),
"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "No connection could be made because the target machine actively refused it.",
"configVersion" : -1
}
],
"ok" : 1
}
udd:SECONDARY>
Now rs.conf() will be
udd:SECONDARY> rs.conf()
{
"_id" : "udd",
"version" : 37530,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "127.0.0.1:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "127.0.0.1:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "127.0.0.1:27019",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 60000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5a715e56bff9fd66ea55b862")
}
}
udd:SECONDARY>
udd
but startingmongod
your repSet name issfr
. What are you using yourmongo.cfg
? If you're startingmongod
with command line options?? – user9251303