One of my previous works was to set up an infrastructure with MongoDB. If you asked me why MongoDB, I would say it was due to sort of legacy. The thing was, I had been struggling for replication installation until I found a way to complete. In this post, I share my steps to achieve with some references.
Foremost, a replica set means there are several database nodes maintaining the same data set. In reality, my application will connect to these nodes, Mongo itself will allow writing onto its primary node while secondary will clone data after a short particular period time. When the primary has a problem, the cluster will vote to differentiate new primary and secondaries.
My problem was the incorrect configuration for my cluster, therefore, these nodes can not communicate. My configuration used IP information which will probably cause some communication problems when these addresses change. Anyway, my post just shows how it works. Bear in mind that I use Docker to install MongoDB so need to install Docker first.
Install mongo nodes 1
The default port of mongo is
27017, I installed 3 nodes on 1 machine (suppose my real IP is
10.164.5.85) so I have to open 3 ports for mapping to each mongo container, otherwise I will meet further issues. You can start from
27017 but I choose from
27018. Three containers are
mongo3 respectively. Replica Set name is
To verify, you can use this command