How to Install MongoDB on CentOS/RHEL 7

How to Install MongoDB on CentOS/RHEL 7

 

How to Install MongoDB on CentOS/RHEL 7


MongoDB (named from “huMONGOus“) is a fully flexible index support and rich queries database. It is a NoSQL database. MongoDB provides large media storage with GridFS. Click here for more details about MongoDB.



MongoDB has released a new stable version 4.2 with lots of major enhancements. This tutorial is the latest test on CentOS 7 and helps you to install MongoDB 4.2 on CentOS 8/7/6 and RHEL 8/7/6 systems.

Step 1 – Add MongoDB Yum Repository

Add the following content in the yum repository configuration file mongodb.repo as per your required MongoDB version and system architecture. For this article, we are using MongoDB 4.0 repository.

CentOS and RedHat systems Only

vi /etc/yum.repos.d/mongodb.repo
[MongoDB]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

Step 2 – Install MongoDB Server

Let’s use the yum package manager to install mongodb-org package, it will automatically install all its dependencies. To install any specific revision of MongoDB specify package name with a version like mongodb-org-4.0.0. The following command will install the latest stable version available.


sudo yum install mongodb-org

Step 3 – Start MongoDB Service

Package mongodb-org-server provided MongoDB init script, Use that script to start service.

systemctl start mongod.service    # For CentOS 8/7 
service mongod restart            # For CentOS 6 

Configure MongoDB to autostart on system boot.

systemctl enable mongod.service    # For CentOS 8/7 
chkconfig mongod on                # For CentOS 6 

Step 4 – Check MongoDB Version

Use the following command to check the installed MongoDB version


[root@tecadmin ~]# mongod --version

db version v4.2.1
git version: edf6d45851c0b9ee15548f0f847df141764a317e
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

Connect MongoDB using the command line and execute some test commands for checking proper working.

[root@tecadmin ~]#  mongo

> use mydb;

> db.test.save( { a: 1 } )

> db.test.find()

  { "_id" : ObjectId("54fc2a4c71b56443ced99ba2"), "a" : 1 }

Congratulation’s You have successfully installed the MongoDB server on your system. For practice only you may use MongoDB browser shell.

References:
http://docs.mongodb.org/manual/installation/

Reactions

Post a Comment

0 Comments

close