MongoDB Replica Set
This guide will lead you through deploying your first MongoDB ReplicaSet using ClusterControl. You'll end up with a fully functional, production-ready MongoDB cluster that’s equipped for monitoring, automatic failover, backups, scaling, and alerting.
MongoDB ReplicaSet is a built-in high availability feature that replicates data from a primary node to one or more secondary nodes. ClusterControl simplifies the setup process, offering automation, visibility, and lifecycle management.
See also
Prerequisites
Ensure the following requirements are met before proceeding:
- ClusterControl should be installed and running. If not, follow the installation instructions in Quickstart or use the Installer Script.
- You need at least three hosts (bare-metal or virtual machines) installed with the supported operating system. See Operating System.
- One host for the MongoDB primary server.
- Two hosts for the MongoDB replica servers.
- SSH access to all servers involved.
- All nodes must have internet access during the deployment stage.
- NTP is configured and running on all hosts to keep their clocks synchronized.
Architecture
Below is the architecture diagram of the replica set:
flowchart TD
A{{**Users<br>Clients<br>Apps**}} --> |RW| B[192.168.99.100<br>MongoDB Primary]
A --> |RO| C[192.168.99.101<br>MongoDB Secondary] & D[192.168.99.102<br>MongoDB Secondary]
B -.-> |replicates| C & D
E[/**ClusterControl**<br>192.168.99.5/] -.- |manages| B & C & D
subgraph MongoDB Replica Set
B
C
D
end
Step 1: Set up SSH key-based authentication
-
On the ClusterControl server, generate a new SSH key as the root user:
-
Copy the SSH public key to all target nodes:
ssh-copy-id -i ~/.ssh/id_rsa [email protected] # Primary ssh-copy-id -i ~/.ssh/id_rsa [email protected] # Secondary 1 ssh-copy-id -i ~/.ssh/id_rsa [email protected] # Secondary 2
-
Test connectivity from the ClusterControl server to each host:
ssh [email protected] "ls /root" ssh [email protected] "ls /root" ssh [email protected] "ls /root"
Step 2: Deploy MongoDB replica set
-
Open your browser and navigate to your ClusterControl server’s IP or domain name.
-
From the ClusterControl dashboard, click on Deploy a cluster in the top-right corner and choose Create a database cluster.
-
Choose "MongoDB" from the Database dropdown and the appropriate Vendor and Version (e.g., "MongoDB" and "7.0") from the wizard. Click Continue.
-
In the Deploy MongoDB wizard, configure the cluster as follows:
- Name: Enter a name for your cluster (e.g., My First MongoDB Cluster).
- Tags: Enter one or more tags, separated by pressing "Enter" (e.g., production, replication, dc1).
- SSH user:
root
- SSH user key path:
/root/.ssh/id_rsa
- SSH port: 22
- SSH sudo password: (leave blank if using key-based auth)
- Install software: On (default)
- Disable firewall: Checked (default)
- Disable SELinux/AppArmor: Checked (default)
- Server port: 5432 (default)
- Server data directory:
/var/lib/mongodb
- User: Enter MongoDB admin user eg:
mongoadm
- Password: Enter a secure password for the MongoDB admin
- ReplicaSet name: Enter your ReplicaSet name
- Configuration template: mongodb.conf.7.0.percona (default)
- Repository: Use vendor repositories (default)
- Enable SSL encryption: On (default)
- Primary node:
- Specify "192.168.99.100" as the primary node and press Enter.
- Replica node:
- Specify "192.168.99.101" as replica and press Enter.
- Specify "192.168.99.102" as another replica and press Enter.
- Wait until everything is green. If a red warning appears, inspect the error and fix it.
- Proceed only if all nodes are reachable (shown in green).
- Review the summary. You can go back to modify any configuration. The settings persist until you exit the wizard.
-
Click Finish to start the deployment.
-
ClusterControl will provision your MongoDB ReplicaSet cluster. Monitor progress from Activity center. This process can take a few minutes. Once complete, the cluster appears on the Home page.
Step 3: Monitor your cluster
After deployment, the Home page provides an overview of your cluster's health, node status, alarms, automatic recovery status, and topology visualization.
Step 4: Schedule automatic backups
To protect your data, set up automatic backups:
-
Go to ClusterControl → Clusters → choose the cluster → Backups to open the backup overview.
-
Go to Create Backup → Schedule a Backup. The backup wizard appears.
-
In the Create a backup schedule wizard:
- Schedule name: Enter the backup name, eg:
DailyBackup
- Cluster: Auto selected by default.
- Backup method: mongodump.
- Upload to cloud: Off (enable if configured)
- Retention: 31 Days (default)
- Enable encryption:
Off
(default)
- Storage host: Select your storage host
- Storage directory: Set accordingly
- Backup subdirectory: Set accordingly
- Set backup schedule: Simple
- Every: Your preferred time
- Timezone: Your preferred timezone
- Review and click Create
- Schedule name: Enter the backup name, eg:
-
Click Create to set the backup schedule.
Step 5: Configure alerts and notifications
To keep track of any issues or incidents in your cluster, it's important to set up alerting. ClusterControl supports sending alarms and alerts to email, web hooks and third-party notification services like Slack or Telegram. In this example, we are going to use email.
Firstly, configure the mail server. Go to ClusterControl GUI → Settings → You don't have a mail server configured. Configure now → SMTP Server. Fill up all necessary information about the SMTP server. You can also opt for Sendmail, however a mail transfer agent (sendmail, postfix or exim) must be installed on the ClusterControl server.
Once configured, we can configure the alert and recipients as below:
- Go to ClusterControl GUI → choose the cluster → Settings → Email Notifications.
- Choose a user group where you are belong to from the User group dropdown.
- Choose your email address to from the Users in the selected group dropdown.
- Click Enable.
- Set the Digest delivery time when you want a digested (summarized events) to be sent to you every day.
- Set all Critical events to "Deliver" (default), all Warning events to "Digest" and you may ignore the Info events.
This ensures you are always notified when critical issues arise and can act quickly to resolve them. You will also get an email with summarized warning events every day at the configured delivery time.
Tip
You can also configure alarms to be sent to third-party notification systems (Slack, Telegram), incident management systems (PagerDuty, ServiceNow, OpsGenie) or web hooks. See Integration → Notification Services.
Step 6 Connect to the cluster
Use the Mongo shell or your application driver:
mongosh -u <mongo_admin> -p <password> --authenticationDatabase admin --host 192.168.99.100
Check replica set status:
rs.status()
Step 7: Cluster management operations
ClusterControl supports:
- Adding/removing replica nodes
- Performing rolling upgrades
- Resyncing lagging nodes
- Manual or automatic failover
- Customizing MongoDB configuration
- Upgrading MongoDB versions
- Deploying sharded clusters (optional)
- Managing backup schedules and restores
- User and role management
All operations can be executed safely from the UI without logging into individual nodes.
Conclusion
You have successfully deployed a MongoDB ReplicaSet using ClusterControl. Your cluster is now fault-tolerant, secure, and manageable through a unified interface.