How to Install and Configure MongoDB on Oracle Linux 8.5
To Install And Configure MongoDB On Oracle Linux 8.5
Introduction
MongoDB is a NoSQL database that provides high performance high availability and automatic scaling. NoSQL database means it does not support SQL to retrieve or manipulate the stored data. MongoDB doesn’t store data in tables instead it stores data in document structure similar to Json.
Installation Steps:
Step 1: Check the Oracle Linux Version by using the below command
[root@linuxhelp linuxhelp]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="8.5"
ID="ol"
Step 2: Create MongoDB Repository by using the below command
[root@linuxhelp linuxhelp]# vim /etc/yum.repos.d/mongodb.repo
[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
Step 3: Install MongoDB by using the below command
[root@linuxhelp linuxhelp]# yum install mongodb-org
MongoDB Repository 7.0 kB/s | 2.5 kB 00:00
Installing:
mongodb-org x86_64 5.0.9-1.el8 mongodb-org-5.0 11 k
Installing dependencies:
mongodb-org-shell x86_64 5.0.9-1.el8 mongodb-org-5.0 15 M
mongodb-org-tools x86_64 5.0.9-1.el8 mongodb-org-5.0 11 k
Total download size: 150 M
Installed size: 562 M
Downloading Packages:
Installed:
mongodb-database-tools-100.5.2-1.x86_64
mongodb-mongosh-1.5.0-1.el8.x86_64
mongodb-org-shell-5.0.9-1.el8.x86_64
mongodb-org-tools-5.0.9-1.el8.x86_64
Complete!
Step 4: Check the MongoDB Version by using the below command.
root@linuxhelp linuxhelp]# mongod --version
db version v5.0.9
Step 5: Connect to the MongoDB server and Create, Drop Database and User using the below command
[root@linuxhelp linuxhelp]# mongo
MongoDB shell version v5.0.9
To Create Database use the below command
> use mydb;
switched to db mydb
To create a user for mydb database with read and write access
> db.createUser(
... {
... user:"user1",
... pwd:"123456",
... roles:["readWrite"]
... }
... )
Successfully added user: { "user" : "user1", "roles" : [ "readWrite" ] }
List the mydb database users by executing the below command
> db.getUsers();
[
{
"_id" : "mydb.user1",
"userId" : UUID("83757547-4853-46e5-9c35-8f0cfa49e5f2"),
"user" : "user1",
"db" : "mydb",
"roles" : [
{
"role" : "readWrite",
"db" : "mydb"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
]
>
>
To Drop a User
> db.dropUser('user1')
true
Drop the newly created database as follows
> db.dropDatabase()
{ "ok" : 1 }
Step 6: Create a user with admin privileges using the below command
[root@linuxhelp linuxhelp]# mongo
MongoDB shell version v5.0.9
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
---
>
> use admin;
switched to db admin
>
> db.createUser(
... {
... user:"user1",
... pwd:"123456",
... roles:[{role:"root",db:"admin"}]
... }
... )
Successfully added user: {
"user" : "user1",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
>
> exit
Bye
Step 7: Login to the MongoDB server using the user1 credentials
[root@linuxhelp linuxhelp]# mongo -u user1 -p --authenticationDatabase admin
MongoDB shell version v5.0.9
Enter password:
connecting to: mongodb://127.0.0.1:27017/?authSource=admin&compressors=disabled&gssapiServiceName=mongodb
---
>
>
> exit
Bye
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to install and Configure MongoDB on Oracle Linux 8.5. Your feedback is much welcome
Comments ( 0 )
No comments available