MongoDB Replica Set Setup Example for MOCM Distributed Mode

This is an example setup for deploying a MongoDB 8.x Replica Set for MOCM Distributed Mode. Adapt the values (IPs, ports, paths, credentials) to match your environment. For detailed MongoDB installation, refer to the official documentation links below

1. Prerequisites

1.1 Environment Requirements

ComponentRequirement
MongoDB Version8.0.x (Community or Enterprise)
Number of Nodes3 (minimum for production)
Supported OSRHEL 8/9, Rocky Linux 8/9, Ubuntu 22.04/24.04, Windows Server 2019/2022
RAMMinimum 16 GB per node (32 GB recommended)
DiskMinimum 100 GB free space (SSD recommended)
NetworkAll nodes must communicate on TCP port 27017

1.2 Hostname Planning

RoleIP (example)
Primary10.40.160.159
Secondary10.40.160.160
Secondary10.40.160.161

Starting from MongoDB 5.0, nodes configured with only IP addresses fail startup validation by default. To use IP addresses without DNS hostnames, you must add the following startup parameter in mongod.conf / mongod.cfg:

setParameter:

disableSplitHorizonIPCheck: true

This parameter is included in the configuration in Section 5.

2. Install MongoDB 8.x

Follow the official MongoDB installation guide for your operating system.

After installation, do not start the MongoDB service yet. Proceed to configure TLS and keyfile first.

3. Generate TLS Certificate

Perform on one machine, then distribute to all nodes. If your organization already has a PKI/CA infrastructure, use your existing CA to sign the MongoDB server certificates. Skip to Step 3.2.

3.1 Create Certificate Authority (CA]

Javascript
Copy

3.2 Generate Server Certificate (per node]

Repeat for each node (mongo1, mongo2, mongo3), replacing values:

Javascript
Copy

Replace mongo1 with mongo2/mongo3 and update the IP value:

  • mongo2: 10.40.160.160
  • mongo3: 10.40.160.161

3.3 Distribute Certificates

FileCopy to
ca.crtAll 3 nodes
mongo1.pemmongo1 only
mongo2.pemmongo2 only
mongo3.pemmongo3 only

Certificate directory:

  • Linux: /etc/mongodb/ssl/
  • Windows: C:\MongoDB\ssl\

Set permissions (Linux):

Javascript
Copy

4. Generate Keyfile for Internal Authentication

Javascript
Copy

Copy the same keyfile to all 3 nodes:

  • Linux: /etc/mongodb/ssl/mongodb-keyfile (chmod 400, owned by mongod)
  • Windows: C:\MongoDB\ssl\mongodb-keyfile
Javascript
Copy

5. Configure MongoDB (mongod.conf / mongod.cfg)

This is the critical configuration specific to MOCM deployment. Apply on all 3 nodes.

5.1 Linux Configuration

Javascript
Copy

5.2 Windows Configuration

Javascript
Copy

5.3 Key Configuration Parameters

ParameterValueDescription
net.tls.moderequireTLSAll connections must use TLS
net.tls.allowConnectionsWithoutCertificatestrueClients don't need client cert (set false for mutual TLS)
security.keyFilepath to keyfileInternal authentication between replica set members
security.authorizationenabledEnforce role-based access control
replication.replSetNamers0Must be identical on all nodes
setParameter.disableSplitHorizonIPChecktrueRequired when using IP addresses instead of hostnames
net.bindIp0.0.0.0Listen on all interfaces

6. Start MongoDB and Initialize Replica Set

6.1 Start Service on All Nodes

Javascript
Copy

6.2 Initialize Replica Set

Connect to 10.40.160.159 using mongosh with TLS:

Javascript
Copy

Run:

Javascript
Copy

6.3 Verify

Javascript
Copy

Expected: 1 PRIMARY + 2 SECONDARY

7. Create Users for MOCM

Create users immediately after rs.initiate(). The localhost exception closes after the first user is created.

Connect to the PRIMARY node and run:

Javascript
Copy

8. Connection String for MOCM

GUI "Database Address" Field

Javascript
Copy

9. Configure MOCM Installer - Database Configuration

After MongoDB Replica Set is ready, enter the following values in the "My OPSWAT Central Management Setup" installer:

FieldValue
Database Address10.40.160.159:27017,10.40.160.160:27017,10.40.160.161:27017
Connection TypeDiscovery
Database Admin UsernameThe admin user created in Step 7
PasswordThe admin password created in Step 7

9. Verification & Troubleshooting

9.1 Test Connection

Javascript
Copy

9.2 Common Issues

IssueSolution
Service fails to startCheck logs: /var/log/mongodb/mongod.log or C:\MongoDB\log\mongod.log
Keyfile permission error (Linux)chmod 400 and chown mongod:mongod
TLS handshake failureVerify SAN in cert matches hostname in rs.initiate()
Members can't connectCheck firewall, verify hostname resolution between nodes
"not authorized"Ensure you created users before localhost exception closed

9.3 Useful Command

Javascript
Copy
VariableType to search · ESC to discard
GlossaryType to search · ESC to discard
InsertType to search · ESC to discard
No matches