When recently building an AWS environment consisting of a number of resources including a replication cluster for
MongoDB on a standard linux amazon EC2 instance, I encountered a few minor issues with how the documentation on MongoDB not necessarily covering all basis for how one might go about setting up a replica set.
As a result of this encountered issues with my instances not being able to communicate with each other. Even after specifying the replication set on initiation “mongod –replSet Name”, the master instance still had trouble talking to a slave instance. There were also permission issues with writing data to the specified MongoDB partition data directory amongs’t others.
Long story short.
Just a small note on things to consider and possibly configure when planning on setting up a
replica set for MongoDB in production. And again this was all done using an
Amazon Web Service EC2 “Amazon Linux AMI release 2016.09” standard image running Centos7.
A. At this point, your MongoDB database should already be installed with the service not yet running.
B. As best practice suggests when creating a replica set for Production, at a minimum ensure you have 3 instances ready for replication as well as a separate mounted disk for your individual MongoDb data directory. This improves performance.
So mount your disk, partition using the appropriate tool, Gdisk/Fdisk, create your custom data directory and add it to your fstab.
C. Add your replication set name to your MongoDB configuration file.
D. And firewall, this one I banged my head agains’t the wall a few times. Regardless of whether firewallD is installed or not, Mongo still requires you grant internal route access to specific services internally to the machine in question.
E. Set service to restart on reboot for high availability.
And those are some of the simple thing’s to consider when setting up database replication for MongoDB. This could have been on an on-premise set of servers, a cloud environment or even a local vagrant development environment. Either way they have helped consistently set up replication when required.
Thanks for reading and if you have questions or need help let us know.