For more posts regarding MongoDB, please click on the LINK

Overview

This document provides step​by​step instructions to install and configure MongoDB version 5.0.23 in an offline (air​gapped) environment on unregistered RHEL systems. The installation uses local RPM packages and configures a MongoDB Replica Set with one Primary, one Secondary, and one Arbiter node.

All MongoDB installation files will be stored under:

  • /mongo → installation RPMs
  • /mongo/data → MongoDB data files

Supported RHEL Versions for MongoDB 5.0.23

MongoDB 5.0.23 supports:

  • RHEL 7.x — Supported
  • RHEL 8.x — Supported (Recommended)
  • RHEL 9.x — Not Supported

Recommended OS: RHEL 8.6 / 8.7 / 8.8

Replica Set Architecture

Replica Set Name: rs0

Role

Hostname

IP Address

Primary

mongo1

192.168.190.10

Secondary

mongo2

192.168.190.20

Arbiter

mongo3

192.168.190.30

Offline Installation Strategy

Because the servers have no internet access and are not registered with Red Hat Subscription Manager, MongoDB will be installed using offline RPM packages copied manually to each server.

Step 1: Download MongoDB 5.0.23 RPMs (On Internet​-Connected System)

Download the following RPM packages for RHEL 8 from the MongoDB repository and place them in a single directory:

  • mongodb-org​–5.0.23
  • mongodb-org-server​–5.0.23
  • mongodb-org-shell​–5.0.23
  • mongodb-org-mongos​–5.0.23
  • mongodb-org-tools​–5.0.23
  1. mongodb-org-5.0.23: https://repo.mongodb.org/yum/redhat/8/mongodb-org/5.0/x86_64/mongodb-org-5.0.23-1.el8.x86_64.rpm
  2. mongodb-org-server-5.0.23: https://repo.mongodb.org/yum/redhat/8/mongodb-org/5.0/x86_64/mongodb-org-server-5.0.23-1.el8.x86_64.rpm
  3. mongodb-org-shell-5.0.23: https://repo.mongodb.org/yum/redhat/8/mongodb-org/5.0/x86_64/mongodb-org-shell-5.0.23-1.el8.x86_64.rpm
  4. mongodb-org-mongos-5.0.23: https://repo.mongodb.org/yum/redhat/8/mongodb-org/5.0/x86_64/mongodb-org-mongos-5.0.23-1.el8.x86_64.rpm
  5. mongodb-org-tools-5.0.23: https://repo.mongodb.org/yum/redhat/8/mongodb-org/5.0/x86_64/mongodb-org-tools-5.0.23-1.el8.x86_64.rpm

Step 2: Copy RPMs to All MongoDB Nodes

Transfer the downloaded RPMs to:

/mongo

Create the directory if it does not exist:

mkdir -p /mongo

Copy using SCP, SFTP, or WinSCP.

Step 3: Install MongoDB Using RPM (All Nodes)

Navigate to the directory:

cd /mongo

Install all RPMs:

rpm -ivh *.rpm

rpm -ivh mongodb-mongosh-1.9.1.x86_64.rpm

rpm -ivh mongodb-org-mongos-5.0.23-1.el8.x86_64.rpm

rpm -ivh mongodb-org-server-5.0.23-1.el8.x86_64.rpm

rpm -ivh mongodb-org-shell-5.0.23-1.el8.x86_64.rpm

rpm -ivh mongodb-database-tools-100.9.5-1.x86_64.rpm

rpm -ivh mongodb-org-database-tools-extra-5.0.23-1.el8.x86_64.rpm

rpm -ivh mongodb-org-database-5.0.23-1.el8.x86_64.rpm

rpm -ivh mongodb-org-tools-5.0.23-1.el8.x86_64.rpm

rpm -ivh mongodb-org-5.0.23-1.el8.x86_64.rpm

 

If dependency errors occur due to offline setup:

rpm -ivh *.rpm –nodeps

Step 4: Verify MongoDB Installation

Check the installed version:

mongod –version

Expected output: 5.0.23

mongosh –version

Expected output: 1.9.1

Step 5: Configure mongod.conf (All Nodes)

Edit /etc/mongod.conf and apply the following configuration:

storage:

  dbPath: /mongo/data

  journal:

    enabled: true

 

systemLog:

  destination: file

  path: /var/log/mongodb/mongod.log

  logAppend: true

 

net:

  port: 27017

  bindIp: 0.0.0.0

 

replication:

  replSetName: rs0

 

processManagement:

  fork: false

Step 5a : Create mongod user and group

groupadd –system mongod

useradd –system -g mongod -s /sbin/nologin -r -M mongod

Step 6: Create Directories and Set Permissions

Create the required directories:

mkdir -p /mongo/data

mkdir -p /var/log/mongodb

Set ownership:

chown -R mongod:mongod /mongo/data /var/log/mongodb

Step 7: Start and Enable MongoDB Service

Start MongoDB:

systemctl start mongod

Enable on boot:

systemctl enable mongod

Check status:

systemctl status mongod

Step 8: Firewall Configuration (If Enabled)

If firewalld is active, allow MongoDB traffic:

firewall-cmd –add-port=27017/tcp –permanent

firewall-cmd –reload

Step 9: Initialize Replica Set (Primary Node Only)

Connect to the primary node using the Mongo shell:

mongo

Run the replica set initiation:

rs.initiate({

  _id: “rs0”,

  members: [

    { _id: 0, host: “192.168.190.10:27017” },

    { _id: 1, host: “192.168.190.20:27017” },

    { _id: 2, host: “192.168.190.30:27017”, arbiterOnly: true }

  ]

})

Step 10: Verify Replica Set Status

Run:

rs.status()

rs.isMaster()

Step 11: Failover Test (Optional)

Stop MongoDB on the primary node:

systemctl stop mongod

Verify that the secondary becomes the new primary.

Production Best Practices

  • Keep MongoDB RPM versions identical across all nodes
  • Enable keyFile authentication in production
  • Keep system clocks synchronized
  • Use an odd number of voting members
  • Plan upgrade path to MongoDB 6.x