MongoDB is a scalable, Open source, high performance and document oriented NoSQL database. It is developed and supported by 10gen. NoSQL stats that MongoDB doesn’t use Tables and rows.

MongoDB provide better performance as compared to other databases because it saves the data in JASON like documents along with dynamic schema.

In this article we will describe the installation steps of MongoDB 3.2 on CentOS 7.x and RHEL 7.x

Step:1 Configure MongoDB 3.2 yum Repository.

In both Operating system RHEL7.x and CentOS 7.x yum repositories are kept in ‘/etc/yum.repos.d/’ directory.  Create the mongodb repository file with the name “mongodb-org.repo”.

[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# vi mongodb-org.repo
name=MongoDB 3.2 Repository

Step:2 Install MongoDB package using yum command.

To install MongoDB and its dependent packages use the below yum command.

[[email protected] ~]# yum install mongodb-org -y

Above command will install the followings MongoDB Packages


Following files and directory will be created once the MongoDB packages are installed.

  • /etc/mongod.conf — Cofiguration file of MongoDB (By default localhost ip  ( is bind IP and 27017 is the default port ).
  • /var/lib/mongo  — Data directory of MongoDB
  •  /var/log/mongodb/mongod.log  — Log file of MongoDB

Step:3 Start and Enable the Mongodb service.

Run the beneath commands to start and enable the mongodb service across the reboot.

[[email protected] ~]# systemctl start mongod.service
[[email protected] ~]# systemctl enable mongod.service
mongod.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mongod on
[[email protected] ~]#

In Case OS firewall is enabled and running then open the MongoDB port ‘27017’ using below firewalld-cmd command.

[[email protected] ~]# firewall-cmd --zone=public --add-port=27017/tcp --permanent
[[email protected] ~]# firewall-cmd --reload
[[email protected] ~]#

Step:4 Connect to MongoDB from the terminal.

Type the command ‘mongo’ from the terminal to connect MongoDB

[[email protected] ~]# mongo

While connecting to MongoDB we may get below warning message


Use the below commands to resolve ‘transparent huge page error‘ :

[[email protected] ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled [[email protected] ~]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[[email protected] ~]# systemctl restart mongod
[[email protected] ~]#

To make above changes permanent, add the above lines in /etc/rc.local file and assign executable rights to /etc/rc.local file.

[[email protected] ~]# cat /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled;
echo never > /sys/kernel/mm/transparent_hugepage/defrag;
[email protected] ~]# chmod +x /etc/rc.local

Use below steps to resolve Warning Error related to rlimits, exact error is shown above.

Add the below entry for mongd user in ‘/etc/security/limits.d/20-nproc.conf’ file.

[[email protected] ~]# vi /etc/security/limits.d/20-nproc.conf
mongodsoft nproc 64000

Reboot the Server and then try to connect MongoDB using mongo command:

[[email protected] ~]# mongo
MongoDB shell version: 3.2.7
connecting to: test

As you can see that we are able to connect mongodb without any warnings, So our installation is completed now.

Uninstall / Remove MongoDB

Run the beneath commands one after the another from the console to remove MongoDB completely.

[[email protected] ~]# systemctl stop mongod
[[email protected] ~]# yum erase $(rpm -qa | grep mongodb-org)
[[email protected] ~]# rm -rf /var/log/mongodb
[[email protected] ~]# rm -rf /var/lib/mongo
[[email protected] ~]#