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.
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
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
Step 2
Enter the letter S to confirm the download and installation of MongoDB in CentOS 8 and then we will see the following:
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:
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
Step 5
We check the status of MongoDB by executing the following:
systemctl status mongod
Step 6
Another option to see the status of MongoDB is to run netplan to see its listening port:
netstat -pnltu
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
Step 2
The next step will be to create the administrator user. To do this, in the Shell execution line we enter:
use admin
Step 3
There we execute the following line:
db.createUser ({user: "admin", pwd: "admin123", roles: [{role: "root", db: "admin"}]})
This verifies that the user has been created with the indicated permissions.
Step 4
To list the current users we execute:
show users
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:
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"
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
Step 4
If you try to connect without credentials we would see the following:
With these simple steps we have installed MongoDB and have ensured its use in CentOS 8.