Mongodb – creating replica set between three similar mongo databases on the local

mongodbreplication

I am creating MongoDB replication on local server by first manually creating three different databases folders with names like MongoDB, MongoDB1 and MongoDB2. Each one of them have data, bin and log sub folders and an individual mongod.cfg file. The data sub folders also have db sub folder and that is where I have all my database files.

For me MongoDB, MongoDB1 and MongoDB2 are all database instances and I am adding configuration to my first Mongo database folder (MongoDB) in mongod.cfg file as:

processManagement:
   fork: true
net:
   bindIp: 127.0.0.1
   port: 27017
storage:
   dbPath: C:\MongoDB\data\db
systemLog:
   destination: file
   path: "C:\MongoDB\log\mongo.log"
   logAppend: true
storage:
   journal:
      enabled: true
security:
   authorization: enabled
replication:
   replSetName: repl1   

I then change the parameters replSetName, dbpath, systemlog path and port number in each of the configuration files for the other two Mongo database folders (MongoDB1 and MongoDB2).

I am still not able to create replicaset between these three database folders.

  • What step is wrong?
  • Am I creating database folder in a wrong way?
  • May I know which step is wrong and how to fix it?

After I start the Mongodb service of first instance and use Windows CMD Prompt to enter the command like written below to start creating replica set, it continues running and never stops and creates a lock file in my folder.

Input

mongod --port 27017 --dbpath "C:\Mongodb\data\db" --replSet repl1

Output

Fri Jul 07 09:07:36.787 [initandlisten] MongoDB starting : pid=15892 port=27017 dbpath=\data\db\ 64-bit host=LT-SRA-EB-27ZL
Fri Jul 07 09:07:36.789 [initandlisten] db version v2.4.9
Fri Jul 07 09:07:36.791 [initandlisten] git version: 52fe0d21959e32a5bdbecdc62057db386e4e029c
Fri Jul 07 09:07:36.792 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
Fri Jul 07 09:07:36.792 [initandlisten] allocator: system
Fri Jul 07 09:07:36.792 [initandlisten] options: { replSet: "rpl1" }
Fri Jul 07 09:07:36.798 [initandlisten] journal dir=\data\db\journal
Fri Jul 07 09:07:36.799 [initandlisten] recover : no journal files present, no recovery needed
Fri Jul 07 09:07:36.854 [websvr] admin web console waiting for connections on port 28017
Fri Jul 07 09:07:36.854 [initandlisten] waiting for connections on port 27017
Fri Jul 07 09:07:36.867 [rsStart] replSet can't get local.system.replset config from self or any seed (EMPTYCONFIG)
Fri Jul 07 09:07:36.867 [rsStart] replSet info you may need to run replSetInitiate -- rs.initiate() in the shell -- if that is not already done
Fri Jul 07 09:07:41.517 [initandlisten] connection accepted from 127.0.0.1:56889 #1 (1 connection now open)
Fri Jul 07 09:07:41.526 [conn1] end connection 127.0.0.1:56889 (0 connections now open)
Fri Jul 07 09:07:44.513 [initandlisten] connection accepted from 127.0.0.1:56890 #2 (1 connection now open)
Fri Jul 07 09:07:44.525 [conn2] assertion 13435 not master and slaveOk=false ns:sc82rev161221_tracking_contact.ProcessingPool query:{ $query: { Scheduled: { $lte: new Date(1499432864509) } }, $orderby: { Scheduled: 1 } }
Fri Jul 07 09:07:44.525 [conn2]  ntoskip:0 ntoreturn:16
Fri Jul 07 09:07:44.525 [conn2] end connection 127.0.0.1:56890 (0 connections now open)
Fri Jul 07 09:07:46.529 [initandlisten] connection accepted from 127.0.0.1:56891 #3 (1 connection now open)
Fri Jul 07 09:07:46.870 [rsStart] replSet can't get local.system.replset config from self or any seed (EMPTYCONFIG)
Fri Jul 07 09:07:56.505 [initandlisten] connection accepted from 127.0.0.1:56892 #4 (2 connections now open)
Fri Jul 07 09:07:56.515 [conn4] assertion 13435 not master and slaveOk=false ns:sc82rev161221_tracking_live.ProcessingPool query:{ $query: { Scheduled: { $lte: new D
  • Before ReplicaSet creation, how do I create three database instances/servers with database in them?

  • Is my method above is correct in regards to creating three databases instances/server?

  • May I know all the steps to create ReplicaSet between these three databases on my local, using windows cmd commands?

I know I am making mistake somewhere, but I do not know where. Your feedback will help.

Best Answer

Error is change that replSetName! If you have replica set, every member what belongs that replica set MUST have (of course) same replSetName.

So, in every mongod.conf file there must be same

replSetName: repl1

After you have started those three replica set nodes, connect one of them with mongo command and give rs.initiate( { _id : "repl1", members: [ { _id : 0, host : "localhost:27017" } ] }) command. After few seconds, press 'Enter' and it should say PRIMARY. After that you can add those two other nodes with rs.add("localhost:27018") and rs.add("localhost:27019") commands. rs.status() and rs.conf() will show that you have functioning replica set.