How to Install and Configure MongoDb on Redhat 7/CentOS 7

How do I install the latest mongoDB database server and components in Redhat 7 or a centos 7 box?

There are no Mongodb packages available in the default yum repository. You need to add the mongoDb repository and then install and configure it. Follow the guide given below which has the steps for the same.

Install MongoDb on Redhat 7/CentOS 7

1. Add repository

name=MongoDB Repository

2. Install mongodb.

sudo yum install -y mongodb-org

3. Set SElinux content for mongodb port, if it is in enforcing mode. You can check the SELinux status using “sestatus” command.

semanage port -a -t mongod_port_t -p tcp 27017

4. Start MongoDB service.

sudo service mongod start

You can check the mongoDB logs using the following command.

tail -f /var/log/mongodb/mongod.log

5. Add mongod service to boot.

sudo chkconfig mongod on

6. To stop and restart mongoDB service, you can use the following commands.

sudo service mongod stop
sudo service mongod restart

Enable MongoDB Remote Access

By default mongoDb can be accessed only on the installed host. If you want remote access of mongodb instance, you need to do the following configuration.

1. Open mongod.conf file

sudo vi /etc/mongod.conf

2. Search for bindIP parameter in the file, and repalace its value to as shown below. If you want to bind the mongodb service to a specific port, you can replace to the IP.


3. restart the mongod service.

sudo service mongod restart

Other Interesting Blogs

Leave a Comment

Share via
Copy link
Powered by Social Snap