• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to install and configure MongoDB On CentOS 8.1

  • 00:56 Vim /etc/yum.repos.d/mongodb-org.repo
  • 01:31 sudo dnf install mongodb-org
  • 03:42 systemctl start mongod
  • 04:01 systemctl enable mongod
  • 04:12 systemctl status mongod
  • 04:39 mongo
  • 07:48 vim /lib/systemd/system/mongod.service
  • 09:00 systemctl --system daemon-reload
{{postValue.id}}

To Install MongoDB on CentOS 8

Introduction:

MongoDB is a free and open-source document database that pertains to the databases family called NoSQL, which is different from the traditional table-based SQL databases like MySQL and PostgreSQL. It is saved in flexible, JSON-like documents where fields can vary from document to document and need a predefined schema, and data structure can be modified over time. This video will cover the method of installation MongoDB on CentOS 8.1

Installation Procedure:

Enable the MongoDB repository by creating a new repository file named mongodb-org.repo inside the /etc/yum.repos.d/ directory:

[root@linuxhelp ~]# Vim /etc/yum.repos.d/mongodb-org.repo
 [mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

Install the mongodb-org meta-package:

[root@linuxhelp ~]# sudo dnf install mongodb-org
CentOS Linux 8 - AppStream                                                 294 kB/s | 6.3 MB     00:21    
CentOS Linux 8 - BaseOS                                                    551 kB/s | 2.3 MB     00:04    
CentOS Linux 8 - Extras                                                    2.4 kB/s | 1.5 kB     00:00    
CentOS Linux 8 - Extras                                                    8.7 kB/s | 8.6 kB     00:00    
Extra Packages for Enterprise Linux Modular 8 - x86_64                     8.8 kB/s | 9.3 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64                             4.5 kB/s | 4.1 kB     00:00    
Extra Packages for Enterprise Linux 8 - x86_64                             529 kB/s | 8.6 MB     00:16    
[root@linuxhelp ~]# systemctl start mongod

Now enable the mongod service so that after boot up it start automatically

[root@linuxhelp ~]# systemctl enable mongod

To check status of service enter following command

[root@linuxhelp ~]# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-12-16 11:09:47 IST; 27s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 94188 (mongod)
   Memory: 94.0M
   CGroup: /system.slice/mongod.service
           └─94188 /usr/bin/mongod -f /etc/mongod.conf

Now enter to mongo shell provide the following command

[root@linuxhelp ~]# mongo
MongoDB shell version v4.2.11
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("04e9bf3f-3317-411c-bdf2-abf0c8fa4821") }
MongoDB server version: 4.2.11
Welcome to the MongoDB shell.
Server has startup warnings: 
2020-12-16T11:09:46.450+0530 I  STORAGE  [initandlisten] 
2020-12-16T11:09:46.450+0530 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-12-16T11:09:47.232+0530 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-12-16T11:09:47.232+0530 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-12-16T11:09:47.232+0530 I  CONTROL  [initandlisten] 
To enable free monitoring, run the following command: db.enableFreeMonitoring()
> use admin
switched to db admin
> db.createUser(
... {
... user:"mdadmin",
... pwd: "password",
... roles: [{role:"userAdminAnyDatabase", db: "admin"}]
... }
... )
Successfully added user: {
	"user" : "mdadmin",
	"roles" : [
		{
			"role" : "userAdminAnyDatabase",
			"db" : "admin"
		}
	]
}
> 
> 
> 
> show users
{
	"_id" : "admin.mdadmin",
	"userId" : UUID("98b57c9b-cf80-4dca-9b05-c39085bf764c"),
	"user" : "mdadmin",
	"db" : "admin",
	"roles" : [
		{
			"role" : "userAdminAnyDatabase",
			"db" : "admin"
		}
	],
	"mechanisms" : [
		"SCRAM-SHA-1",
		"SCRAM-SHA-256"
	]
}
> quit()

To turn on authentication move into the following file

[root@linuxhelp ~]# vim /lib/systemd/system/mongod.service
Find the following line:
Environment="OPTIONS=--f /etc/mongod.conf"

Add the --auth option as follows:
Environment="OPTIONS= --auth -f /etc/mongod.conf"

Now reload the mongo.d service

[root@linuxhelp ~]# systemctl --system daemon-reload
 [root@linuxhelp ~]# systemctl restart mongod

Test mongo user authentication

[root@linuxhelp ~]# mongo
MongoDB shell version v4.2.11
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
MongoDB server version: 4.2.11
switched to db admin
> use admin
Now show users
> show users
An error message should display:
2020-12-16T11:16:42.222+0530 E  QUERY    [js] uncaught exception: Error: command usersInfo requires authentication :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.getUsers@src/mongo/shell/db.js:1661:15
shellHelper.show@src/mongo/shell/utils.js:883:9
shellHelper@src/mongo/shell/utils.js:790:15
@(shellhelp2):1:1

Next, use the following command to authenticate with the credentials created before

> db.auth('mdadmin','password')
1
Now show users to confirm
> show users
{
	"_id" : "admin.mdadmin",
	"userId" : UUID("98b57c9b-cf80-4dca-9b05-c39085bf764c"),
	"user" : "mdadmin",
	"db" : "admin",
	"roles" : [
		{
			"role" : "userAdminAnyDatabase",
			"db" : "admin"
		}
	],
	"mechanisms" : [
		"SCRAM-SHA-1",
		"SCRAM-SHA-256"
	]
}

With this, the installation of MongoDB on CentOS 8.1 comes to an end.

Tags:
charmi
Author: 

Comments ( 1 )

shiraziismailsoy
Thank you (y)
Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is MongoDB?

A

Mongo-DB is a document database that provides high performance, high availability, and easy scalability.

Q

What is “Namespace” in MongoDB?

A

MongoDB stores BSON (Binary Interchange and Structure Object Notation) objects in the collection. The concatenation of the collection name and database name is called a namespace.

Q

What kind of NoSQL database MongoDB is?

A

MongoDB is a document-oriented database. It stores data in the form of BSON structure-based documents. These documents are stored in a collection.

Q

Is mongodb .repo already exists?

A

No, we need to create and add the configuration

Q

Does MongoDB support SQL?

A

Not directly, no. However, MongoDB does support a rich query language of its own. For examples on using MongoDB’s query language, see MongoDB CRUD Operations

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Isaiah ?
What is the use of SUID & SGID commands

How to set the special permissions to the files and folders using SUID and SGID commands...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.