Info | ||
---|---|---|
| ||
The default port used by Witness is 27010. For all server instances the port should be kept as 27010. |
Download and installation of MongoDb
Download the MongoDB ZIP installer here: https://www.mongodb.org/dl/win32/x86_64-2008plus-ssl?_ga=1.147098928.662975023.1471964900
Make sure you choose the ZIP and not the MSI version as we need to manually install the servers.
To enable resilience, the two Mongo servers must be installed on their own hardware. You should not use the same hardware platform that Witness is running on. The final server which is the Arbiter can be run on the same hardware installation as Witness.
Default Setup
The mongo zip file will contain only one directory which is bin. On each server create the directory C:\mongodb and copy the bin folder to this directory.
Info | ||
---|---|---|
| ||
To make the usage of Mongo easier, we recommend that you append the bin folder to the Windows Path. Please append the C:\mongodb\bin folder to the PATH environment variable. |
In the mongodb directory create data\replicaset-27010 folder and also the log folder.
If done correctly, you will have the following under C:\monogdb
C:\monogdb\bin
- C:\mongodb\data\replicaset-27010
- C:\mongodb\log
MongoDb Configuration File
To allow more control over configuration all instances of the MongoDb server will use a config file.
In each C:\mongodb folder create the file replicaset-27010.cfg with the following content.
- dbpath=C:\mongodb\data\replicaset-27010
- logpath=C:\mongodb\log\replicaset-27010.log
- logappend=true
- port=27010
- replSet=navtechreplicaset
- bind_ip = 127.0.0.1,<<ip address of server/DNS name>>
- dbath: this is the directory where MongoDB will store data. Each member of the replica set will have its own folder. If the folder does not exist, MongoDB will not start.
- logpath: this is the file where MongoDB will send all diagnostic information. If the file is not present, MongoDB will create it. By default MongoDB will overwrite the log file each time the process starts. To append to the log instead, add "logappend=true" to the config file.
- port: this is the port that the MongoDB server will listen on for client connections. By default if not set, MongoDB will resort to 27017
- replSet: the name of the replica set this server belongs to. All members of the replica set must use this name. if not set in the config, this server is not part of a replica set and any commands issued to it to make it part of a replica set will fail.
- bind_ip: MongoDB will bind to these ip addresses. It is possible to bind to more than one, simply add each address as a comma separated list.
Install MongoDB as a service
To make maintenance of the servers as easy as possible it is recommended that you install the MongoDB instances as services. On each machine that Mongo will be running, issue the following command through the command line.
Code Block |
---|
mongod --config "C:\mongodb\replicaset-27010.cfg" --install --serviceName "NavtechRadar-MongoDb-replicaset-27010" --serviceDisplayName "NavtechRadar-MongoDb-replicaset-27010" |
Configure MongoDB Replica Set
To configure the replica set, all the MongoDB servers need to be running.
Info |
---|
You must be logged into the server that will become the PRIMARY node in the Replica Set for the following to function correctly. |
Code Block |
---|
mongo --port 27010 |
Code Block |
---|
rs.initiate() |
Note |
---|
A common error is "couldn't initiate: can't find self in the replset config my port: 27010" This means your configuration file is wrong with the bind_ip parameter. If you make a change to the configuration file, you must remember to stop and restart the service. |
Add Secondary Replica Set member
Depending on the version of MonogDB that you running with, you may need to perform the following command on the PRIMARY or the SECONDARY.
Code Block |
---|
rs.add("HOST:27010") |
Info |
---|
Where HOST is the IP Address used in the bind_ip section of the config file of the secondary server. |
After running the rs.add command, execute the command
Code Block |
---|
rs.status() |
On the primary server. You should now see the two servers with one marked as PRIMARY and the other as SECONDARY.
Add the Arbiter
Finally execute the following command on the primary.
Code Block |
---|
rs.addArb("HOST:27010") |
Where HOST is the IP Address of where the arbiter resides.
Execute the command rs.status() again, and you should see something like the following
Code Block |
---|
{ "set" : "replicaset", "date" : ISODate("2017-01-11T15:44:06.792Z"), "myState" : 7, "term" : NumberLong(53), "heartbeatIntervalMillis" : NumberLong(2000), "members" : [ { "_id" : 1, "name" : "10.0.6.114:27010", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 88537, "optime" : { "ts" : Timestamp(1484126776, 4), "t" : NumberLong(53) }, "optimeDate" : ISODate("2017-01-11T09:26:16Z"), "lastHeartbeat" : ISODate("2017-01-11T15:44:03.742Z"), "lastHeartbeatRecv" : ISODate("2017-01-11T15:44:06.485Z"), "pingMs" : NumberLong(0), "syncingTo" : "10.0.6.115:27010", "configVersion" : 7 }, { "_id" : 2, "name" : "10.0.6.115:27010", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 88537, "optime" : { "ts" : Timestamp(1484126776, 4), "t" : NumberLong(53) }, "optimeDate" : ISODate("2017-01-11T09:26:16Z"), "lastHeartbeat" : ISODate("2017-01-11T15:44:03.742Z"), "lastHeartbeatRecv" : ISODate("2017-01-11T15:44:05.322Z"), "pingMs" : NumberLong(0), "electionTime" : Timestamp(1484060896, 1), "electionDate" : ISODate("2017-01-10T15:08:16Z"), "configVersion" : 7 }, { "_id" : 3, "name" : "10.0.7.48:27010", "health" : 1, "state" : 7, "stateStr" : "ARBITER", "uptime" : 88538, "configVersion" : 7, "self" : true } ], "ok" : 1 } |
You have now successfully installed and configured the MonogDB servers as a replica set.
Related information
Filter by label (Content by label) | ||||
---|---|---|---|---|
|