Today we will setup a 3 Node Replica Set for MongoDB on Ubuntu 16. A Replica Set is a form of data replication, so that your data resides on more than one node for data durability. We will setup the 1st node as the primary node, the second as the secondary node and the 3rd node will act as an arbiter.
The arbiter node can almost be mentioned as a voter node, as it will be set in place to prevent split brain.
Resources:
- https://eladnava.com/deploy-a-highly-available-mongodb-replica-set-on-aws/
- https://stackoverflow.com/questions/38524150/mongodb-replica-set-with-simple-password-authentication (auth)
- https://stackoverflow.com/questions/14789622/mongodb-keyfile-too-open-permissions
Installing MongoDB on our 3 Nodes:
Our case, using Ubuntu 16.04, setting up our repository and installing mongodb from our repository:
1 2 3 4 |
|
Preparing our Directories:
1 2 |
|
Populating our MongoDB Configuration:
- MongoDB Prefers XFS File Systems when using WiredTiger.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Enable MongoDB On Startup and Start MongoDB:
1 2 |
|
Setup MongoDB Replica Sets:
In our setup we will have 3 nodes: (mongodb-1, mongodb-2, mongodb3) From our Primary Node, connect to MongoDB and inititalize our replica set:
1 2 3 4 5 6 7 8 9 10 |
|
Next, add our 2 other MongoDB Nodes, remember mongodb-3
is our arbiter node:
1 2 3 4 |
|
Verify the Replica Set Status:
1
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
Setup Auth:
Setup Authentication on our MongoDB Database, we will create the user adminuser
and setup the password to secret
:
1 2 3 4 |
|
1 2 3 4 5 6 7 8 9 10 |
|
Restart MongoDB:
1
|
|
Connect and Authenticate against MongoDB:
Connect to your MongoDB Cluster with auth:
1
|
|