How to Install and Configure MongoDB on Centos/Redhat Servers

Install and configure mongodb on centos/redhat 7 machines

MongoDB is one of the best NoSQL databases. It is been widely used by many big organizations for big data and other workloads.

Install and Configure MongoDB

In this tutorial, we will walk you through the steps for installing and configuring MongoDB on a centos7 or a RedHat 7 server. Also, you will learn the commands and custom configurations for managing the MongoDB server.

1. Create a MongoDB repo file

sudo touch /etc/yum.repos.d/mongodb-org-3.2.repo

2. Copy the following contents to the repo file.

name=MongoDB Repository

3. Install MongoDB using the yum command.

sudo yum install -y mongodb-org

4. Open /etc/selinux/config file set the SELINUX parameter as follows.


Note: If you do not want to disable SeLinux, execute the following command.

semanage port -a -t mongod_port_t -p tcp 27017

27017 is the port which MongoDB runs. If you are using a differnt port, then change it accordingly.

5. Restart the server.

sudo init 6

MongoDb Configuration Files

The default configurations are as follows.

1. You can find the MongoDB data in /var/lib/mongo directory.

2. All the MongoDB logs are saved to /var/log/mongodb

3. MongoDb configuration file is /etc/mongod.conf

By default, MongoDB service is bind to (localhost). If you are accessing MongoDB from the same server which is installed, then this configuration is fine.

If you want remote access, you need to change the bind_ip parameter under network interfaces in /etc/mongod.conf. You can either give to allow any IP or a particular IP. For example,

  port: 27017


  port: 27017

Start MongoDb

You can now start the MongoDB service using the following.

sudo service mongod start


sudo systemctl start mongod

Manage MongoDb Service

1. To add MongoDB to the boot service,

sudo systemctl enable mongod

2. To restart,

sudo systemctl restart mongod

3. To stop,

sudo systemctl stop mongod

Access MongoDB Shell

To access the MongoDB shell, just execute the following command from the terminal.



The new economy needs a new approach to education. Education is no longer a one-time investment at the beginning of one's career, it's a lifelong pursuit. We're building an educational experience that empowers our readers to thrive in this new world order.

Leave Comment