October 21, 2021
How to install MongoDB 5.0 on Rocky Linux 8

How To Install MongoDB 5.0 Community Server On Rocky Linux 8

On this tutorial, we will learn how to install MongoDB Community Server version 5.0.3 (the latest version so far) on Rocky Linux 8 operating system.

Introduction

MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL). MongoDB offers both an Enterprise and Community version of its powerful distributed document database. The latest version of MongoDB when this article is written is version 5.0.3. On this article, we will discuss how to install MongoDB Community Server 5.0 on Rocky Linux 8.



MongoDB version 5.0 come with new features. Key MongoDB 5.0 highlights include:

  • Native time series collections, clustered indexing, and window functions make it easier, faster, and lower cost to build and run applications like IoT and financial analytics, and to enrich your enterprise data with time series measurements.
  • Live Resharding allows you to change the shard key for your collections on-demand as your workloads grow and evolve – with no database downtime or complex migrations.
  • The Versioned API future-proofs your applications. Starting with MongoDB 5.0, you can upgrade to the latest MongoDB releases without the risk of introducing backward-breaking changes that require application-side rework.
  • MongoDB’s unique Client-Side Field Level Encryption now extends some of the industry’s strongest data privacy controls to multi-cloud databases.

MongoDB 5.0 Community Server Installation on Rocky Linux 8

The installation process will be consist of several task, as described below :

  1. Prerequisite
  2. Add the MongoDB 5.0 Repository
  3. Install the MongoDB 5.0
  4. Enable and Startup the MongoDB 5.0 Services
  5. Testing MongoDB

Prerequisite

Before we are deploying MongoDB on CentOS 8 operating system, we have to fulfill the prerequisite first. As described on the MongoDB documentation, if MongoDB only supports the 64-bit versions of these platforms.

  1. Rocky Linux 8 system with sufficient disk space
  2. Account user with sudo privilege or root account

Add MongoDB 5.0 Repository

Creating a repository file of MongoDB 5.0 is the first step to install MongoDB, The file name and location will be /etc/yum.repos.d/mongodb-org-5.0.repo. We will create a new file with vi text editor, by typing command as follow :

sudo vi /etc/yum.repos.d/mongodb-org-5.0.repo

The content of the file is as follow :


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

Once we have added the repository, then we will update the system repositories to sync the newly added repository with the system, by typing command line : sudo dnf -y update.



[ramansah@otodiginet ~]$ sudo dnf -y update
Rocky Linux 8 - AppStream 3.6 kB/s | 4.8 kB 00:01
Rocky Linux 8 - AppStream 2.1 MB/s | 9.1 MB 00:04
Rocky Linux 8 - BaseOS 3.3 kB/s | 4.3 kB 00:01
Rocky Linux 8 - BaseOS 1.9 MB/s | 7.5 MB 00:03
Updating Rocky Linux 8 system
Updating Rocky Linux 8 system

Install MongoDB 5.0

On this step, we will install MongoDB on the system. To perform MongoDB installation, we just type the command line : sudo dnf install -y mongodb-org.

[ramansah@otodiginet ~]$ sudo dnf install -y mongodb-org
MongoDB Repository 28 kB/s | 11 kB 00:00
Dependencies resolved.
===============================================================================================================
Package Architecture Version Repository Size
===============================================================================================================
Installing:
mongodb-org x86_64 5.0.3-1.el8 mongodb-org-5.0 11 k
Installing dependencies:
mongodb-database-tools x86_64 100.5.0-1 mongodb-org-5.0 47 M
mongodb-mongosh x86_64 1.1.0-1.el7 mongodb-org-5.0 43 M
mongodb-org-database x86_64 5.0.3-1.el8 mongodb-org-5.0 11 k
mongodb-org-database-tools-extra x86_64 5.0.3-1.el8 mongodb-org-5.0 16 k
mongodb-org-mongos x86_64 5.0.3-1.el8 mongodb-org-5.0 19 M
mongodb-org-server x86_64 5.0.3-1.el8 mongodb-org-5.0 28 M
mongodb-org-shell x86_64 5.0.3-1.el8 mongodb-org-5.0 15 M
mongodb-org-tools x86_64 5.0.3-1.el8 mongodb-org-5.0 10 k

Transaction Summary
===============================================================================================================
Install 9 Packages

Total download size: 152 M
Installed size: 556 M

...
...

Installed:
mongodb-database-tools-100.5.0-1.x86_64 mongodb-mongosh-1.1.0-1.el7.x86_64
mongodb-org-5.0.3-1.el8.x86_64 mongodb-org-database-5.0.3-1.el8.x86_64
mongodb-org-database-tools-extra-5.0.3-1.el8.x86_64 mongodb-org-mongos-5.0.3-1.el8.x86_64
mongodb-org-server-5.0.3-1.el8.x86_64 mongodb-org-shell-5.0.3-1.el8.x86_64
mongodb-org-tools-5.0.3-1.el8.x86_64
Install MongoDB 5.0
Install MongoDB 5.0



MongoDB 5.0 Repository File
MongoDB 5.0 Repository File

Once we have added the repository, then we will update the system repositories to sync the newly added repository with the system, by typing command line : sudo dnf -y update.

[ramansah@otodiginet ~]$ sudo dnf -y update
Rocky Linux 8 - AppStream                                                      3.6 kB/s | 4.8 kB     00:01    
Rocky Linux 8 - AppStream                                                      2.1 MB/s | 9.1 MB     00:04    
Rocky Linux 8 - BaseOS                                                         3.3 kB/s | 4.3 kB     00:01    
Rocky Linux 8 - BaseOS                                                         1.9 MB/s | 7.5 MB     00:03    
Updating Rocky Linux 8 system
Updating Rocky Linux 8 system

Install MongoDB 5.0

On this step, we will install MongoDB on the system. To perform MongoDB installation, we just type the command line : sudo dnf install -y mongodb-org.

[ramansah@otodiginet ~]$ sudo dnf install -y mongodb-org
MongoDB Repository                                                              28 kB/s |  11 kB     00:00    
Dependencies resolved.
===============================================================================================================
 Package                                   Architecture    Version              Repository                Size
===============================================================================================================
Installing:
 mongodb-org                               x86_64          5.0.3-1.el8          mongodb-org-5.0           11 k
Installing dependencies:
 mongodb-database-tools                    x86_64          100.5.0-1            mongodb-org-5.0           47 M
 mongodb-mongosh                           x86_64          1.1.0-1.el7          mongodb-org-5.0           43 M
 mongodb-org-database                      x86_64          5.0.3-1.el8          mongodb-org-5.0           11 k
 mongodb-org-database-tools-extra          x86_64          5.0.3-1.el8          mongodb-org-5.0           16 k
 mongodb-org-mongos                        x86_64          5.0.3-1.el8          mongodb-org-5.0           19 M
 mongodb-org-server                        x86_64          5.0.3-1.el8          mongodb-org-5.0           28 M
 mongodb-org-shell                         x86_64          5.0.3-1.el8          mongodb-org-5.0           15 M
 mongodb-org-tools                         x86_64          5.0.3-1.el8          mongodb-org-5.0           10 k

Transaction Summary
===============================================================================================================
Install  9 Packages

Total download size: 152 M
Installed size: 556 M

...
...

Installed:
  mongodb-database-tools-100.5.0-1.x86_64                      mongodb-mongosh-1.1.0-1.el7.x86_64              
  mongodb-org-5.0.3-1.el8.x86_64                               mongodb-org-database-5.0.3-1.el8.x86_64         
  mongodb-org-database-tools-extra-5.0.3-1.el8.x86_64          mongodb-org-mongos-5.0.3-1.el8.x86_64           
  mongodb-org-server-5.0.3-1.el8.x86_64                        mongodb-org-shell-5.0.3-1.el8.x86_64            
  mongodb-org-tools-5.0.3-1.el8.x86_64                        
Install MongoDB 5.0
Install MongoDB 5.0

The installation was done successfully. To verify the installation, we will query its version by typing command line : mongod --version.

ramansah@otodiginet ~]$ mongod --version
db version v5.0.3
Build Info: {
    "version": "5.0.3",
    "gitVersion": "657fea5a61a74d7a79df7aff8e4bcf0bc742b748",
    "openSSLVersion": "OpenSSL 1.1.1g FIPS  21 Apr 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "rhel80",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
MongoDB version 5.0.3
MongoDB version 5.0.3

Enable And Startup MongoDB 5.0 Service

Once the installation was completed done successfully, then we will startup and enable the MongoDB service. By default MongoDB service is not run automatically. Then we will verify MongoDB service status.

[ramansah@otodiginet ~]$ sudo systemctl start mongod
[ramansah@otodiginet ~]$ sudo systemctl enable mongod
[ramansah@otodiginet ~]$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-10-08 08:07:25 WIB; 13s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 48539 (mongod)
   Memory: 65.0M
   CGroup: /system.slice/mongod.service
           └─48539 /usr/bin/mongod -f /etc/mongod.conf

Oct 08 08:07:24 otodiginet systemd[1]: Starting MongoDB Database Server...
Oct 08 08:07:24 otodiginet mongod[48536]: about to fork child process, waiting until server is ready for conne>
Oct 08 08:07:24 otodiginet mongod[48536]: forked process: 48539
Oct 08 08:07:25 otodiginet mongod[48536]: child process started successfully, parent exiting
Oct 08 08:07:25 otodiginet systemd[1]: Started MongoDB Database Server
MongoDB 5.0 Service
MongoDB 5.0 Service

As shown on the above, if the MongoDB daemon has already running properly.

Testing MongoDB 5.0 Community Server

In this section, we will try to login to MongoDB database, do some query and try to create a database user. We will use mongo command line as MongoDB command shell which was provided to login to database. Just type the mongo command line as shown below.

[ramansah@otodiginet ~]$ mongo
MongoDB shell version v5.0.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("d73f147f-0587-4c8a-8950-27ae63682efb") }
MongoDB server version: 5.0.3
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
We recommend you begin using "mongosh".
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
	https://community.mongodb.com
---
The server generated these startup warnings when booting: 
        2021-10-08T08:07:25.899+07:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2021-10-08T08:07:25.899+07:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
---
---
        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()
---

After successful login, there is a warning message, “Warning: the “mongo” shell has been superseded by “mongosh” which delivers improved usability and compatibility.The “mongo” shell has been deprecated and will be removed in an upcoming release.”.

As recommendation, we will use the new MongoDB shell for connecting to MongoDB database by using mongosh command line, as shown below.



bye
[ramansah@otodiginet ~]$ mongosh
Current Mongosh Log ID:	615fa16408a1f7461833aba9
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000
Using MongoDB:		5.0.3
Using Mongosh:		1.1.0

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

------
   The server generated these startup warnings when booting:
   2021-10-08T08:07:25.899+07:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2021-10-08T08:07:25.899+07:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
------

Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded.
  You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js.
test> use admin
switched to db admin
admin> show dbs
admin     41 kB
config  61.4 kB
local     41 kB
admin> show collections
system.version
admin> 

After logged in successfully, then we tried to add a new database user called as digimbadmin, as shown below.

admin> db.createUser(
... {
..... user: "digimbadmin",
..... pwd: "passwordkoe",
..... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
..... }
... )
{ ok: 1 }
admin> show users
[
  {
    _id: 'admin.digimbadmin',
    userId: UUID("b295dc6b-660a-4196-8443-64b5e34d9555"),
    user: 'digimbadmin',
    db: 'admin',
    roles: [ { role: 'userAdminAnyDatabase', db: 'admin' } ],
    mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
  }
]
admin> 
Creating new database user on MongoDB 5.0
Creating new database user on MongoDB 5.0

Conclusion

So far, we have learnt how to install MongoDB 5.0 Community Server version 5.0.3 (so far the latest version) on Rocky Linux 8 operating system. This article is very simple, only a little step for knowing one of the famous NoSQL database, MongoDB.

Share this article via :

Leave a Reply

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