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.
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 firewalld2. 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/mongodb3. Add MongoDB binaries to the system PATH
vim /etc/profile export PATH=$PATH:/opt/mongodb/bin source /etc/profileAfter 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/logs5. 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.0Make 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 --forkThe output will indicate that the child process has started successfully.
Related reading links are provided at the end of the original article.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
