MongoDB is a leading document-oriented NoSQL database that stores data in flexible JSON-like BSON documents, making it well-suited for applications with evolving schemas, hierarchical data, or high-throughput write workloads. MongoDB is not included in the RHEL 8 AppStream, so you must add the official MongoDB repository before installing. This guide walks through creating the MongoDB 7.0 repository file, installing the server, configuring the mongod.conf file, starting the service, and securing your deployment by creating an administrative user. You will also learn how to open the firewall when remote access is required.

Prerequisites

  • A server running RHEL 8 or a compatible rebuild (AlmaLinux 8, Rocky Linux 8)
  • Root or sudo access to the system
  • Internet access to reach repo.mongodb.org for package downloads
  • firewalld active if MongoDB must accept remote connections

Step 1 — Add the MongoDB 7.0 Repository

Create the repository definition file for MongoDB 7.0. The file tells dnf where to find MongoDB packages and provides the GPG key URL for package signature verification:

sudo tee /etc/yum.repos.d/mongodb-org-7.0.repo <<'EOF'
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
EOF

Verify that dnf can see the new repository and locate the MongoDB server package:

dnf repolist | grep mongodb
dnf info mongodb-org-server

Step 2 — Install MongoDB

The mongodb-org meta-package installs the MongoDB server, shell (mongosh), command-line tools, database tools, and the MongoDB monitoring agent in a single operation:

sudo dnf install -y mongodb-org

Once installed, confirm the version:

mongod --version

Step 3 — Start and Enable the mongod Service

Enable and start the mongod systemd service so that MongoDB runs immediately and restarts automatically after reboots:

sudo systemctl enable --now mongod

Verify the service status:

sudo systemctl status mongod

The output should show active (running). MongoDB writes its log to /var/log/mongodb/mongod.log by default.

Step 4 — Review and Edit the MongoDB Configuration

MongoDB’s main configuration file is /etc/mongod.conf. By default, MongoDB binds only to 127.0.0.1, which is the recommended setting until authentication is configured. Open the file and review the key sections:

sudo grep -A3 'net:' /etc/mongod.conf

You should see:

net:
  port: 27017
  bindIp: 127.0.0.1

To enable remote access after configuring authentication (Step 5), change bindIp to the server’s network interface address or 0.0.0.0 for all interfaces:

sudo sed -i 's/bindIp: 127.0.0.1/bindIp: 0.0.0.0/' /etc/mongod.conf

Restart mongod after any configuration change:

sudo systemctl restart mongod

Step 5 — Connect with mongosh and Create an Admin User

Connect to the local MongoDB instance with the mongosh shell:

mongosh

At the mongosh prompt, switch to the admin database and create an administrative user. Then test basic collection operations:

use admin
db.createUser({
  user: "mongoadmin",
  pwd: "StrongPassword1!",
  roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
})

use testdb
db.inventory.insertOne({ item: "journal", qty: 25, status: "A" })
db.inventory.find({ status: "A" })
exit

Enable authentication by adding security.authorization: enabled to /etc/mongod.conf:

sudo tee -a /etc/mongod.conf <<'EOF'

security:
  authorization: enabled
EOF

sudo systemctl restart mongod

Step 6 — Open the Firewall for Remote Access

If remote applications need to connect to MongoDB on port 27017, open that port in firewalld. Always ensure authentication is enabled before exposing MongoDB to a network:

sudo firewall-cmd --permanent --add-port=27017/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports

For tighter security, restrict access to a specific application server IP:

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.50" port port="27017" protocol="tcp" accept'
sudo firewall-cmd --reload

Conclusion

You have installed MongoDB 7.0 on RHEL 8 by adding the official repository, installed the full mongodb-org package set, reviewed and customised /etc/mongod.conf, created an administrative user, enabled authentication, and configured the firewall. Your MongoDB instance is now secured and ready for application workloads.

Next steps: How to Configure MongoDB Replica Sets on RHEL 8, How to Back Up and Restore MongoDB with mongodump and mongorestore, and How to Enable TLS/SSL Encryption for MongoDB on RHEL 8.