Introduction:
MongoDB is a source-available, cross-platform, document-oriented database program. Classified as a NoSQL database product, MongoDB utilizes JSON-like documents with optional schemas.To install MongoDB on AlmaLinux, you can follow the steps below. MongoDB is available via the official MongoDB repository, which provides the latest stable versions.
Step 1: Install Required Dependencies
First, update your system and install any required dependencies:
#sudo dnf update -y
Step 2: Add the MongoDB Repository
MongoDB provides its own repository, so we need to add that to your system to get the latest version. We’ll use the MongoDB 6.x repository, but you can modify the version if needed.
- Create a .repo file for MongoDB:
#sudo nano /etc/yum.repos.d/mongodb-org-6.0.repo - Add the following content to the mongodb-org-6.0.repo file:
[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
Step 3:Install MongoDB
Once the repository is added, you can install MongoDB.
#sudo dnf install -y mongodb-org
This will install the following MongoDB packages:
mongodb-org-server (the MongoDB server)
mongodb-org-mongos (MongoDB router)
mongodb-org-shell (the MongoDB shell)
mongodb-org-tools (tools for MongoDB, including mongodump, mongoimport, etc.)
Step 4:Start and Enable MongoDB Service
After MongoDB is installed, you need to start the service and enable it to start on boot.
- Start and Enable MongoDB Service
#sudo systemctl start mongod - Enable MongoDB to start on boot:
#sudo systemctl enable mongod - Verify MongoDB is running:
Check the status of MongoDB to ensure it’s running correctly:
#sudo systemctl status mongod
You should see output that indicates MongoDB is active and running.
Active: active (running) since Tue 2024-10-17 10:00:00 UTC; 5min ago
Conclusion
You have successfully installed MongoDB on your AlmaLinux system. You can now begin using MongoDB for your applications. To ensure your MongoDB instance is secure, it’s recommended to enable authentication and configure proper firewalls.
- Access MongoDB via: mongo
- Enable Authentication for security in production environments.
- Secure your MongoDB by configuring proper firewall rules and using SSL for encrypted communication.