How to build a simple MongoDB cluster for data replication using docker in 20 minutes - PART 2

preview_player
Показать описание
In my previous video (part 1), I was explained what is replication and how master slave architecture works in mongoDB.

Topics covered in this video are,
1. Create a new network in docker for mongoDB master slave cluster
2. Create three containers with mongoDB instance and each container will act as a separate node.
3. Make replica set configuration
4. Create a new data in primary node
5. Check the replication in secondary nodes
6. Verify possibility for write operation in secondary nodes.

Topics will be covered in upcoming videos,
How fail-over mechanism works in mongoDB
How CAP theorem can be achieved in mongoDB

Commands used:

#command to create seperate network for mongo cluster
docker network create mongo-cluster

#command to create mongo container one (node 1)
docker run -p 30001:27017 --name india --net mongo-cluster mongo mongod --replSet comments

#command to create mongo container two (node 2)
docker run -p 30002:27017 --name germany --net mongo-cluster mongo mongod --replSet comments

#command to create mongo container three (node 3)
docker run -p 30003:27017 --name australia --net mongo-cluster mongo mongod --replSet comments

#command to get shell access to node "india"
docker exec -it india mongo

#command to get shell access to node "germany"
docker exec -it india germany

#command to get shell access to node "australia"
docker exec -it india australia

Steps to configure replica set in three nodes:
step 1:
From node one (India):
db = (new Mongo('localhost:27017')).getDB('test')

step 2:
#Config for connecting three nodes together (execute this from one of the node)
config = {
"_id": "comments",
"members": [
{
"_id": 0,
"host": "india:27017"
},
{
"_id": 1,
"host": "germany:27017"
},
{
"_id": 2,
"host": "australia:27017"
}
]
}
step 3:
#after writing the config file, we need to initiate to start replicating data of "comments" replica set

Thanks.
Рекомендации по теме
Комментарии
Автор

I've literally been searching for hours for a proper tutorial on how to do this, yours is the only one that was straight to the point and actually worked. Thanks a lot!

cristiandt
Автор

Hi, the session was great and I been looking for this video for days, explanation was clear as crystal. I have something to ask the above video is done using the mongo image could the same process be done in percona mongo image.

aravinddas
visit shbcf.ru