How to install Mongodb on centos

We need to add the latest repo in the following file...

vi /etc/yum.repos.d/mongodb-org-4.2.repo

name=MongoDB Repository

Now lets install the mongodb using yum command

sudo yum install -y mongodb-org

Lets start the mongo using service

service mongod start
service mongod status
Active: active (running) since Sun 2019-08-18 22:55:11 EDT; 4s ago

Mongodb has config file which resides here


If you have lots of data going in to mongodb everyday and then it is better to change the Mongo db path to a disk which is big in size. For me it is the /home directory.

Lets create couple of directories to store the db and log file.

mkdir -p /home/mongo_db/mongo/
mkdir -p /home/mongo_db/log 

Lets vi the mongod.conf and change the pointers

vi /etc/mongod.conf

Change /var/lib/mongo/ to /home/mongo_db/mongo/

and change /var/log/mongodb/mongod.log to /home/mongo_db/log/mongod.log

Also comment the following setting so that log file doesnt become to big over time.

logAppend: true

Now lets change ownership of following directories to mongod

chown -R mongod:mongod /home/mongo_db

Lets stop the mongod current running instance before applying the above changes.

service mongod stop
service mongod start

You would see now mongo populating data and log in following directories...