CIQ

How to Install a NoSQL Database Server in Rocky Linux

How to Install a NoSQL Database Server in Rocky Linux
March 11, 2023

NoSQL databases are optimized for applications and use cases that require very large amounts of unstructured data with low latency and flexible data models. Because they are easily scalable and offer high availability, these types of databases are often used for real-time web applications and services that rely on big data. NoSQL databases are used by the likes of Amazon, Adobe, Netflix, Facebook, Twitter, and many more. 

There are a number of NoSQL databases that are available on Rocky Linux. One option is MongoDB, which is an open source database that includes features like ad-hoc queries, appropriate indexing, replication for high availability, sharding for distributed collections, load balancing for failover, schema-less databases, scalability, aggregation, and very high performance.

Let's walk through the process of installing and configuring the MongoDB NoSQL database on Rocky Linux 9.

Requirements

The only things you'll need in this tutorial are a running instance of Rocky Linux 9 and a user with sudo privileges. Of course, the instance of Rocky Linux will also need to have a network connection. Other than that, a few minutes of your time, and you're good to go.

Installing MongoDB

The first thing to do is log into Rocky Linux and open a terminal window. Create a new repository file with the command:

sudo nano /etc/yum.repos.d/mongodb-org-6.0.repo

Paste the following contents into the new file:

[mongodb-org-6.0]

name=MongoDB Repository

baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/

gpgcheck=1

enabled=1

gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc

Save and close the file. 

Install MongoDB with the command:

sudo dnf install mongodb-org mongodb-mongosh -y

Start and enable the MongoDB service with:

sudo sytemctl enable --now mongod

Configuring MongoDB

Now that MongoDB is installed, there are a few configurations to take care of. First, we need to disable Transparent Huge Pages. To do that, we'll create a new systemd service file with the command:

sudo nano /etc/systemd/system/disable-thp.service

Paste the following content into the new file:

[Unit]

Description=Disable Transparent Huge Pages (THP)

[Service]

Type=simple

ExecStart=/bin/sh -c "echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled && echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag"

[Install]

WantedBy=multi-user.target

Save and close the file. Reload the systemd daemon with:

sudo systemctl daemon-reload

Start and enable the new service with:

sudo systemctl enable --now disable-thp

We now must increase the ulimit on the system. The default is 1024, but MongoDB requires at least 64000. To do this, open the mongodb.conf file with:

sudo nano /etc/security/limits.d/mongodb.conf

Add the following to the bottom of the file:

mongod soft nproc 64000

mongod hard nproc 64000

mongod soft nofile 64000

mongod hard nofile 64000

Save and close the file.

Next, we need to increase the virtual memory limit for MongoDB. To do that, open the sysctl.conf file with:

sudo nano /etc/sysctl.conf

Add the following to the bottom of the file:

fs.file-max = 2097152

vm.max_map_count = 262144

vm.swappiness = 1

Save and close the file. 

Reboot Rocky Linux, so all the changes take effect.

Creating an admin user

We'll now create an admin user for MongoDB. First, access the MongoDB console with:

mongosh

Disable MongoDB monitoring with:

db.disableFreeMonitoring()

Access the default admin account with:

use admin

We'll create a new mongoadmin user with the following query:

db.createUser(

{

    user: "mongoadmin",

    pwd: passwordPrompt(),

    roles: [

      { role: "userAdminAnyDatabase", db: "admin" },

      { role: "readWriteAnyDatabase", db: "admin" }

    ]

  }

)

You will be prompted to create a password for the new user. Be warned you are not prompted to verify the password, so type it very carefully. Also, make sure to use a strong/unique password to keep the admin account secure.

We now need to enable authorization in mongod.conf. Open the file with the command:

sudo nano /etc/mongod.conf

In that file, look for the line:

#security:

Remove the # character and add the authorization line so it looks like this:

security:
    authorization: enabled

Save and close the file. Restart MongoDB with:

sudo systemctl restart mongod

Access the MongoDB console again with the command:

mongosh

Switch to the admin user with:

use admin

Authenticate as the mongoadmin user with:

db.auth("mongoadmin", passwordPrompt())

When prompted, type the password you created for the mongoadmin user, and you'll find yourself at the MongoDB console, ready to work.

Congratulations, you now have a running MongoDB server ready to go! You can start creating new users and databases to fit the needs of your company's applications and services.

Related posts

2023 Holiday Gift Guide for Rocky Linux Users

2023 Holiday Gift Guide for Rocky Linux Users

Dec 19, 2023

Rocky Linux

Why Rocky Linux Is a Rock-Solid Choice in an Economic Downturn

Why Rocky Linux Is a Rock-Solid Choice in an Economic Downturn

Jan 18, 2023

Rocky Linux

6 Signs That It's Time to Move to Rocky Linux

6 Signs That It's Time to Move to Rocky Linux

Feb 23, 2023

Rocky Linux

123
37
>>>