How to install MongoDB on CentOS 8

MongoDB is a free and open source document database. It belongs to a family of databases called NoSQL. NoSQL is different from traditional relational databases, for example: MySQL and PostgreSQL.

In MongoDB, data is flexibly stored as documents in a JSON-like form. It does not require a pre-defined schema, and the data structure can always be changed.

This guide explains how to install and configure MongoDB Community Edition on CentOS 8 server.

One, install MongoDB

MongoDB is not available on the CentOS 8 core software source. We will enable the official MongoDB software source and install the software package.

At the time of writing this article, the latest MongoDB version on the official MongoDB software source is 4.2. Before starting the installation, visit the MongoDB document Install on Red Hat to check if there is a newer release version.

Perform the following steps as root or a user with sudo privileges to install MongoDB on CentOS 8 system:

  1. Create a source file named mongodb-org.repo in the /etc/yum.repos.d/ directory to start the MongoDB source:
sudo nano /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

If you want to install an older version of MongoDB, replace 4.2 with the version you want.

  1. Install the mongodb-org meta-package:
sudo dnf install mongodb-org

During the installation process, you will be prompted to insert the MongoDB GPG key. Type y and press Enter to enter.

The following packages will be installed on your system as part of the mongodb-org package:

  1. Once the installation is complete, enable and start the MongoDB service:
sudo systemctl enable mongod --now
  1. To verify the installation, connect to the MongoDB database and print out the server version:
mongo

Run the following command to display the MongoDB version number:

db.version()

The output might look like this:

4.2.3

Two, configure MongoDB

The MongoDB configuration file is named: mongod.conf, located in the /etc directory. This file is in YAML format.

The default configuration is suitable for most user scenarios. In any case, for production environments, we recommend opening the security chapter and enabling user authentication: /etc/mongod.conf

security:
 authorization: enabled

This authorization option enables Role-Based Access Control (RBAC), which specifies the user's access rules for data and operations. If this option is disabled, then every user can access any data and perform any operation.

After making any changes to the MongoDB configuration file, restart the mongod service:

sudo systemctl restart mongod

For information about MongoDB configuration options, please visit Configuration File Options Document Page.

Three, create a MongoDB administrator##

If you have enabled MongoDB user authentication, you need to create an administrator user who can access and manage MongoDB instances.

First, access the MongoDB shell:

mongo

Enter the following command to connect to the admin database:

use admin
switched to db admin

Create a new user with the name mongoAdmin and assign the role of userAdminAnyDatabase:

db.createUser({
 user:"mongoAdmin", 
 pwd:"changeMe", 
 roles:[{ role:"userAdminAnyDatabase", db:"admin"}]})
Successfully added user:{"user":"mongoAdmin","roles":[{"role":"userAdminAnyDatabase","db":"admin"}]}

Exit the Mongo shell:

quit()

To test the modification, use the administrator account you created earlier to access the mongo shell:

mongo -u mongoAdmin -p --authenticationDatabase admin
MongoDB shell version v4.2.3
Enter password:
use admin
switched to db admin

Now, print the user:

show users
{"_ id":"admin.mongoAdmin","user":"mongoAdmin","db":"admin","roles":[{"role":"userAdminAnyDatabase","db":"admin"}],"mechanisms":["SCRAM-SHA-1","SCRAM-SHA-256"]}

Four, summary##

We have shown you how to install and configure MongoDB 4.2 on your CentOS 8 server.

Read The MongoDB 4.2 Manual to find more information on this topic.

Recommended Posts

How to install MongoDB on CentOS 8
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
How to install Memcached on CentOS 8
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install MongoDB on Ubuntu 16.04
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to install MariaDB on CentOS 8
How to install Odoo 13 on CentOS 8
How to install Apache on CentOS 8
How to install OpenCV on CentOS 8
How to install PHP on CentOS 8
How to install Apache Maven on CentOS 8
How to install Apache Kafka on CentOS 7
R&D: How To Install Python 3 on CentOS 7
How to install GCC compiler on CentOS 7
How to install offline JDK1.8 on centos7.0
How to install Visual Studio Code on CentOS 8
How to install and use Docker on CentOS 7
How to install RPM packages on CentOS Linux
How to install and configure VNC on CentOS 8
How to install and use Composer on CentOS 8
How to install and configure Redis on CentOS 8
How to install Node.js and npm on CentOS 8
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and use Curl on CentOS 8
How to install and configure Owncloud on CentOS 8
How to install VirtualBox client extension on CentOS 8
How to install Docker CE on RHEL 8 / CentOS 8
How to install and uninstall tomcat on centos
How to install and configure Redmine on CentOS 8
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04