Step-by-Step Installation Guide for MongoDB Community Edition on SUSE
Install MongoDB Community Edition on SUSE
MongoDB Community Edition is a robust NoSQL database solution that supports modern application requirements. Installing it on SUSE Linux involves adding the MongoDB repository, installing the necessary packages, and configuring the service for use.
This step-by-step guide will help you set up MongoDB on SUSE Linux efficiently.
Prerequisites
Before starting, ensure the following:
1. Operating System: SUSE Linux Enterprise Server (SLES) 12 SP3+ or SLES 15+.
2. User Privileges: Root or sudo access.
3. Internet Connection: To download MongoDB packages from the official repository.
Step 1: Import MongoDB Public GPG Key
Import MongoDB’s GPG key to verify the authenticity of the packages:
# Import MongoDB GPG key sudo rpm --import https://pgp.mongodb.com/server-6.0.asc
Step 2: Add the MongoDB Repository
Add MongoDB's official repository to the system.
For SLES 12:
# Add the MongoDB repository for SLES 12 echo -e "[mongodb-org-6.0]\nname=MongoDB Repository\nbaseurl=https://repo.mongodb.org/zypper/suse/12/mongodb-org/6.0/x86_64/\ngpgcheck=1\ngpgkey=https://pgp.mongodb.com/server-6.0.asc\nenabled=1" | sudo tee /etc/zypp/repos.d/mongodb-org-6.0.repo
For SLES 15:
# Add the MongoDB repository for SLES 15 echo -e "[mongodb-org-6.0]\nname=MongoDB Repository\nbaseurl=https://repo.mongodb.org/zypper/suse/15/mongodb-org/6.0/x86_64/\ngpgcheck=1\ngpgkey=https://pgp.mongodb.com/server-6.0.asc\nenabled=1" | sudo tee /etc/zypp/repos.d/mongodb-org-6.0.repo
Step 3: Install MongoDB
1. Refresh the repository cache:
# Refresh system repositories sudo zypper refresh
2. Install MongoDB packages:
# Install MongoDB Community Edition sudo zypper install -y mongodb-org
Step 4: Start and Enable MongoDB Service
1. Start the MongoDB service:
# Start the MongoDB service sudo systemctl start mongod
2. Enable MongoDB to start automatically on boot:
# Enable MongoDB on boot sudo systemctl enable mongod
Step 5: Verify Installation
Check the status of the MongoDB service:
# Check MongoDB service status sudo systemctl status mongod
If the service is active and running, the installation was successful.
Test the MongoDB shell:
# Access the MongoDB shell mongosh
Step 6: Configure MongoDB Security (Optional)
Enable Authentication
To secure MongoDB, enable user authentication:
1. Edit the MongoDB configuration file:
sudo nano /etc/mongod.conf
2. Add or update the security section:
security: authorization: "enabled"
3. Restart the MongoDB service:
sudo systemctl restart mongod
Step 7: Configure Firewall (Optional)
If you want MongoDB to accept remote connections, open port 27017:
# Open MongoDB port in SUSE firewall sudo firewall-cmd --permanent --add-port=27017/tcp sudo firewall-cmd --reload
Example Commands for MongoDB on SUSE
Insert a Document
Code:
// Insert a document into the 'inventory' collection
db.inventory.insertOne({ item: "laptop", quantity: 50, inStock: true });
Query Documents
Code:
// Find all documents in the 'inventory' collection
db.inventory.find();
Troubleshooting Tips
Issue | Solution |
---|---|
MongoDB service fails to start | Check /var/log/mongodb/mongod.log for error details. |
GPG key import issues | Verify the GPG key URL and ensure network connectivity. |
Remote connection issues | Verify firewall settings and MongoDB binding IP in /etc/mongod.conf. |
Additional Notes:
- Version Compatibility: Ensure that the MongoDB version matches your SUSE version.
- Updates: Regularly update MongoDB by running sudo zypper update.
- Backups: Regularly back up your data using tools like mongodump before major updates or migrations.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/mongodb/installation-mongodb-on-suse.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics