Databases 4 min read

Step-by-Step Guide to Installing and Configuring MongoDB on Linux

This article provides a detailed Linux tutorial for installing MongoDB, disabling the firewall, extracting the package, setting environment paths, creating data and log directories, editing the configuration file, and launching the database both in foreground and as a background service.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Step-by-Step Guide to Installing and Configuring MongoDB on Linux

MongoDB is a distributed, high‑performance database written in C++ that bridges relational and non‑relational systems, offering rich features for web applications.

1. Disable the firewall

systemctl stop firewalld
systemctl disable firewalld

2. Extract the MongoDB package and move it to /opt

tar -zxvf mongodb-linux-x86_64-rhel70-4.4.2.tgz
mv mongodb-linux-x86_64-rhel70-4.4.2 /opt/mongodb

3. Add MongoDB binaries to the system PATH

vim /etc/profile
export PATH=$PATH:/opt/mongodb/bin
source /etc/profile

After sourcing, the mongod, mongo, mongos, and install_compass commands become available.

4. Create data and log directories

mkdir -p /opt/mongodb/data/db
touch /opt/mongodb/data/logs

5. Edit the MongoDB configuration file (mongodb.conf) vim /opt/mongodb/mongodb.conf Key sections to configure:

systemLog:
  destination: file
  logAppend: true
  path: /opt/mongodb/data/logs

storage:
  dbPath: /opt/mongodb/data/db
  journal:
    enabled: true

processManagement:
  fork: true   # run in background
  pidFilePath: /mongo/mongod.pid

net:
  port: 27017
  bindIp: 0.0.0.0

Make sure the dbPath, path, port, and bindIp values match your environment.

6. Start MongoDB

Foreground launch using the configuration file: ./mongod -f ../mongodb.conf Or start it as a background daemon:

mongod --dbpath /opt/mongodb/data/db --logpath /opt/mongodb/data/logs --fork

The output will indicate that the child process has started successfully.

Related reading links are provided at the end of the original article.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseLinuxcommand-lineInstallationMongoDB
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.