Table of Contents

How To Install Mongodb on Centos (Linux)

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

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

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

Now lets install the Mongodb using yum command "yum install mongodb-org"

sudo yum install -y mongodb-org

How To Start MongoDB On Linux

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

If you see message above (running). It means mongodb server has started.

Mongodb has config file which resides here

/etc/mongod.conf

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...

/home/mongo_db/mongo/

Related Posts