How To Install MongoDB 4.2 on RedHat/ CentOS 7 systems

As we discuss MongoDB in the previous Article About MongoDB, Why we use it? MongoDB’s Terminology and Implementation , MongoDB is an open-source NoSQL database.

Lots enhancements are released with the latest version MongoDB 4.2 to become more stable version easy to use in development and scaling.

MongoDB is a document-oriented database presented as two versions are released:

  • MongoDB Community is the source available and free to use edition of MongoDB.
  • MongoDB Enterprise is available as part of the MongoDB Enterprise Advanced subscription.

So in this tutorial we will show how to install MongoDB Community Edition using the package management system for these specifications as below:

  • MongoDB’s version : MongoDB 4.2
  • OS Server :Centos 7
  • System architecture : 64-bit system
  • User : non-root user with sudo privileges

First, to prepare MongoDB’s installation directly using the package management system (yum), it is required to add the MongoDB repository and configure the yum repository configuration file mongodb.repo:

  • Create the configuration file mongodb.repo using the vi editor in the yum repository:

#vi /etc/yum.repos.d/mongodb.repo

  • Add this content to mongodb.repo  file:

[MongoDB]

name=MongoDB Repository

baseurl=http://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

  • We should verify that the MongoDB repository is created within the package management utility yum using the command repolist:

#yum repolist

Second, now we can install mongodb-org package directly using the package management system (yum).There is no easy that this command below to launch the yum package manager and it will automatically install the latest stable version available MongoDB and all its dependencies:

# sudo yum install –y mongodb-org

In the next step, we have just to start MongoDB service using the systemctl utility that launch the MongoDB init script as show the next command:

#sudo systemctl start mongod.service

  • To verify that the service started since no output is provided after start command’s execution, so we can check the end of the mongod.log file with the tail command as following:

#sudo tail /var/log/mongodb/mongod.log

  • To configure MongoDB service to autostart on system boot, we use the systemctl utility:

#sudo systemctl enable mongod.service

  • To check installed MongoDB version, we can use the following command :

# mongod –version

  • To check the status of MongoDB database, we can use the following command:

# sudo systemctl status mongod.service

  • To reload the daemon process of MongDB database : mongod process that is primarily, used to manage database access, we issue the following command ; This command requests that the  daemon process reads the configuration file  /etc/mongod.conf and applies any changes without any restart.

# sudo systemctl reload mongod

  • To connect MongoDB using the command line, go on it is easy:

# mongo

> use mydb;

  • To stop MongoDB database , we issue this command that will halt all running mongod processes :

#sudo systemctl stop mongod

 

About Hela Khazri

Oracle Professional Certified Administrator (OCP 12c ) with 8 years of experience as Senior Oracle Database Administrator and Project Manager using scrum master methodology. A proven ability to maintain the high availability, to monitor the database performance and the security of databases - Having good analytical skills and detail-oriented to solve database issues and to assist the day-to-day support (L2 & L3);

Leave a Reply

Your email address will not be published. Required fields are marked *