+5 votes
222 views
How to install MongoDB on CentOS 8

in Linux / Unix by (551k points)
reopened | 222 views

1 Answer

+3 votes
Best answer

1. How to add the MongoDB repository in CentOS 8
2. How to install MongoDB on CentOS 8
3. How to access MongoDB using the Shell and create an Administrator user
4. How to configure authentication in MongoDB in CentOS 8

Working with databases is essential in all types of organizations, as this gives us the opportunity to manage hundreds of objects in a centralized and functional way according to the needs of each corporate segment. Therefore, it is ideal that databases provide us with features such as security , scalability, functionality and compatibility..

The following explains in detail how to install MongoDB on CentOS 8 , and incidentally combine one of the best database managers with a comprehensive system focused on the corporate sector.

What is MongoDB?
MongoDB has been developed as a distributed database, which is based on a special approach for application developers and with full compatibility in cloud storage based on availability issues.

MongoDB has a documentary structure since it stores the data in the form of JSON-type documents looking for their recursion..

MongoDB features
Within the characteristics of MongoDB we find:
  • It allows working with dynamic and flexible schemes.
  • Supports matrices and nested objects.
  • Integrates an expressive query language thanks to which it will be possible to filter and sort using any field variable.
  • MongoDB's own queries are JSON facilitating their programming.
  • It supports general additions such as the search for graphics or text.
  • It offers two types of relationships (reference and embedded).
  • Execute complete ACID transactions.
  • We can make combinations in the consultations.
  • Offers triggers without a server.
  • It contains more than 80 metrics at the level of supervision and alerts.
  • All clusters will be automated facilitating their administration.
  • Add preconfigured security features for tasks such as authentication, authorization, encryption and more.
  • All network traffic will be encrypted using Transport Layer Security (TLS - Transport Layer Security)
  • We can create global clusters which offer low latency read and write.
  • It integrates BI connectors with which it is facilitated that BI tools can communicate in MySQL protocol.
  • It will be possible to view the data live using one of the MongoDB instances.
  • Intuitive interface

Without further ado, let's see how to install MongoDB on CentOS 8 and thus realize its full potential.


1. How to add the MongoDB repository in CentOS 8


MongoDB by default is not available in the CentOS 8 repository, so we must include it manually. For this we will use some editor and execute the following:
 nano /etc/yum.repos.d/mongodb.repo 
In this new file we will paste the following:
 [mongodb-org-4.2] name = MongoDB Repository baseurl = https: //repo.mongodb.org/yum/redhat/$releasever/mongodb-org/development/x86_64/ gpgcheck = 1 enabled = 1 gpgkey = https: //www.mongodb.org/static/pgp/server-4.2.asc 
image

We save the changes with the Ctrl + O keys and exit the editor with the Ctrl + X keys..


2. How to install MongoDB on CentOS 8

Step 1

Once we add the repository, we proceed to the installation of MongoDB. To do this we will execute the following:
 dnf install mongodb-org 
image
Step 2

Enter the letter S to confirm the download and installation of MongoDB in CentOS 8 and then we will see the following: image
Step 3

Enter the letter S again to confirm the download of the GPG key and once this is finished we will see the following: image
Step 4

Now we are going to start and enable MongoDB on the startup of CentOS 8 by running:
 systemctl start mongod systemctl enable mongod 
image
Step 5

We check the status of MongoDB by executing the following:
 systemctl status mongod 
image
Step 6

Another option to see the status of MongoDB is to run netplan to see its listening port:
 netstat -pnltu 
image

There we found the address 127.0.0.1:27017.


3. How to access MongoDB using the Shell and create an Administrator user

Step 1

To access MongoDB just run the following:
 mongo 
image
Step 2

The next step will be to create the administrator user. To do this, in the Shell execution line we enter:
 use admin 
image
Step 3

There we execute the following line:
 db.createUser ({user: "admin", pwd: "admin123", roles: [{role: "root", db: "admin"}]}) 
image

This verifies that the user has been created with the indicated permissions.

Step 4

To list the current users we execute:
 show users 
image

4. How to configure authentication in MongoDB in CentOS 8


Security is key in any database so we can configure the authentication method in MongoDB.
Step 1

At this point everyone will have access to editing in the database, to configure the authentication of the user created we will edit the file /lib/systemd/system/mongod.service: image
Step 2

In this file we will go to the “Service” section and edit the following line like this:
 Environment = "OPTIONS = --auth -f /etc/mongod.conf" 
image

We save the changes with the Ctrl + O keys and exit with the Ctrl + X keys.

Step 3

We apply the changes by executing:
 systemctl daemon-reload systemctl restart mongod 
With this change it will now be necessary to enter the user's credentials as follows (in this case):
 mongo -u admin -p admin123 --authenticationDatabase admin 
image
Step 4

If you try to connect without credentials we would see the following: image

With these simple steps we have installed MongoDB and have ensured its use in CentOS 8.


by (3.5m points)
edited

Related questions

+4 votes
1 answer
asked Oct 8, 2020 in Linux / Unix by backtothefuture (551k points) | 344 views
+5 votes
1 answer
asked Sep 2, 2020 in Linux / Unix by backtothefuture (551k points) | 2k views
+3 votes
1 answer
asked Aug 13, 2020 in Linux / Unix by backtothefuture (551k points) | 1.9k views
+4 votes
1 answer
asked Jun 9, 2020 in Linux / Unix by backtothefuture (551k points) | 601 views
+4 votes
1 answer
asked May 14, 2020 in Linux / Unix by backtothefuture (551k points) | 612 views
Sponsored articles cost $40 per post. You can contact us via Feedback
10,634 questions
10,766 answers
510 comments
3 users