MongoDb replica set install

Data integrity and fault tolerance are key areas for any database. For MongoDb, we want the ability to replicate data on 3 or more separate database servers. This provides us with significant uptime, and ensuring that if one or two random outages occur, we can still operate the business.

First, you want to ensure that you have all of the MongoDb server prerequisites installed. You can visit MongoDb here for more information:

We are going to be starting with a base Ubuntu 22.04 install. Download the latest from Ubuntu Server at

Next, before doing anything, download VirtualMin: Click the “Download Virtualmin GPL” button.

sudo su -
cd /root    
mv /home/ddietrich/ .
chown root:root 
chmod u+x

Once done, you will have a completed install with Virtualmin (including Webmin). Go to your server at Login with your root password. Once you are logged in, select the Refresh and Update Settings button to configure your Virtualmin settings for your usage.

Once you’ve installed Virtualmin and Webmin, install your SSL certificate for the server, if you have one. If you do have one, I like to install my SSL certificates in /root/{{Domain Name for this server}}. In our case here, you will want to copy your SSL certificate .pem file (contains both the private and public key), and the gd_bundle.crt. You may already have a gd_bundle.crt. If so and this is NOT a GoDaddy registered domain, leave it alone. Otherwise if you DO have a GoDaddy account, pull your gd_bundle.crt from and copy it, and the .pem file, to a /root/ssl-certs directory.

Now, edit the /etc/webmin/miniserv.conf file. Ensure you have the following two lines (comment any preexisting lines that start with keyfile= and/or extracas= by placing a # as the first character on the line), add these lines with your domain SSL certificate:



Next, I like to copy over a set of shell scripts I use for common everyday tasks:

cd /opt
mv /home/ddietrich/scripts/ .
chown -R root:root scripts/
cd /etc/profile.d
ln -s /opt/scripts/

Next, you want to ensure that you have a fully-qualified domain name (FQDN) for your server. In our case, we used Set this in your /etc/hostname name file. Then ensure it is in your /etc/hosts file too. Additionally, since this is going to be a replica set, be sure to add your other server names and their IP addresses to your /etc/hosts file. Once completed, reboot.

Example /etc/hosts with the local machine name, and the FQDNs of the three machine replica set: localhost u22mongo1

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Now we are ready for MongoDb. Follow the MongoDb page here for setting up MongoDb on Ubuntu Linux:

Scroll to Top