MongoDB is a popular open-source, document-based database that offers high performance, scalability, and flexibility. In this blog post, I will show you how to install MongoDB Community Edition on Red Hat Enterprise Linux, CentOS Linux, or Oracle Linux using the yum package manager.

Prerequisites

Before you begin, make sure you have the following:

  • A 64-bit version of Red Hat Enterprise Linux, CentOS Linux, or Oracle Linux ¹² on x86_64 or ARM64 architecture. MongoDB does not support the Unbreakable Enterprise Kernel (UEK) on Oracle Linux.
  • Root or sudo access to your system.
  • A stable internet connection.

Step 1: Configure the yum repository

To install MongoDB directly using yum, you need to create a /etc/yum.repos.d/mongodb-org-7.0.repo file with the following content:

[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc

This will enable the MongoDB 7.0 Community Edition repository on your system. You can also download the .rpm files directly from the MongoDB repository.

Step 2: Install the MongoDB packages

To install the latest stable version of MongoDB, run the following command:

sudo yum install -y mongodb-org

This will install the following packages:

  • mongodb-org: A metapackage that will automatically install the four component packages listed below.
  • mongodb-org-server: The MongoDB database server and associated tools.
  • mongodb-org-mongos: The MongoDB shard daemon and associated tools.
  • mongodb-org-shell: The MongoDB shell, an interactive JavaScript interface to MongoDB.
  • mongodb-org-tools: The MongoDB tools, such as mongodump, mongorestore, mongoexport, mongoimport, and mongostat.

Alternatively, to install a specific release of MongoDB, specify each component package individually and append the version number to the package name, as in the following example:

sudo yum install -y mongodb-org-7.0.23 mongodb-org-server-7.0.23 mongodb-org-mongos-7.0.23 mongodb-org-shell-7.0.23 mongodb-org-tools-7.0.23

Step 3: Start and enable the MongoDB service

To start the MongoDB service, run the following command:

sudo systemctl start mongod

To verify that the MongoDB service is running, run the following command:

sudo systemctl status mongod

You should see an output similar to this:

● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2024-01-22 16:35:27 IST; 1min 39s ago
     Docs: https://www.mongodb.org/manual
 Main PID: 1765 (mongod)
   CGroup: /system.slice/mongod.service
           └─1765 /usr/bin/mongod -f /etc/mongod.conf

To enable the MongoDB service to start automatically on system boot, run the following command:

sudo systemctl enable mongod

Step 4: Connect to MongoDB from the terminal

To connect to MongoDB from the terminal, run the following command:

mongo

This will launch the MongoDB shell, where you can interact with your MongoDB databases and collections. You should see an output similar to this:

MongoDB shell version v7.0.23
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f2d8f9f9-9a4d-4b7c-8f6a-4f8f9f9f9f9f") }
MongoDB server version: 7.0.23
---
The server generated these startup warnings when booting:
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten]
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten]
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten]
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten]
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
        2024-01-22T16:35:28.123+0530 I  CONTROL  [initandlisten]
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

>

You can now run MongoDB commands in the shell. For example, to show the databases on your system, run the following command:

show dbs

You should see an output similar to this:

admin   0.000GB
config  0.000GB
local   0.000GB

To exit the MongoDB shell, press Ctrl+C or type quit().

Conclusion

In this blog post, I have shown you how to install MongoDB Community Edition on Red Hat OS using the yum package manager. You have also learned how to start, enable, and connect to the MongoDB service from the terminal. I hope you found this tutorial helpful and informative. If you have any questions or feedback, please leave a comment below.

¹: Install MongoDB Community Edition on Red Hat or CentOS
²: Installing MongoDB on Red Hat Enterprise Linux.

Source: Conversation with Bing, 1/22/2024
(1) Install MongoDB Community Edition on Red Hat or CentOS. https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-red-hat/.
(2) Install MongoDB Community Edition on Red Hat or CentOS. https://www.mongodb.com/docs/v5.0/tutorial/install-mongodb-on-red-hat/.
(3) Install MongoDB Community Edition on Red Hat or CentOS. https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-red-hat/.
(4) Install MongoDB Community Edition on Red Hat or CentOS. https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-red-hat/.
(5) Installing MongoDB on Red Hat Enterprise Linux. https://developers.redhat.com/blog/2016/06/02/installing-mongodb-on-red-hat-enterprise-linux.
(6) How to Install MongoDB on RHEL 8 / CentOS 8 – LinuxTechi. https://www.linuxtechi.com/how-to-install-mongodb-rhel-centos/.
(7) Install MongoDB Community Edition on Red Hat or CentOS. https://www.mongodb.com/docs/v4.4/tutorial/install-mongodb-on-red-hat/.
(8) github.com. https://github.com/assembler-school/mongodb-intro-workshop/tree/4072f6c0af3be41dbb786ff663fdc794fdaec196/README.md.
(9) github.com. https://github.com/ndlarsen/ndlarsen.github.io/tree/d9e7d5ac302e41921cd6cc211dfb9f8256e3af37/_drafts%2F2019-10-06-building-a-full-stack-web-application-part-2-storage-with-mongodb.md.
(10) en.wikipedia.org. https://en.wikipedia.org/wiki/MongoDB.

By kirodewal

Hi I'm Kamlesh. I'm very interested in writing blogs & codes on telegram bots.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.