Deploying MongoDB on a Single Node
Introduction
Deploying MongoDB on a single node is the simplest way to set up a MongoDB instance. This configuration is suitable for development environments, testing, and small-scale applications. This guide will walk you through the steps to deploy MongoDB on a single node.
Prerequisites
- A server or machine with a supported operating system (e.g., Linux, Windows, macOS).
- Administrator or root access to install software.
- Internet connection to download MongoDB packages.
Installation Steps
Step 1: Download and Install MongoDB
Download the appropriate MongoDB package for your operating system from the MongoDB Download Center. Follow the installation instructions provided for your OS.
// For Linux (Ubuntu example)
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
// Start MongoDB
sudo systemctl start mongod
sudo systemctl enable mongod
Step 2: Verify Installation
After installation, verify that MongoDB is running:
mongo --eval 'db.runCommand({ connectionStatus: 1 })'
This command should return the status of the MongoDB server, indicating that it is running.
Basic Configuration
Configuration File
The MongoDB configuration file is typically located at /etc/mongod.conf
. You can edit this file to adjust settings such as the data directory, log directory, and network interfaces.
# Example configuration
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
bindIp: 127.0.0.1
port: 27017
Conclusion
Deploying MongoDB on a single node is straightforward and suitable for development and testing purposes. By following these steps, you can set up a MongoDB instance and start building applications quickly.