FedoraRHEL Based

How To Install MongoDB on Fedora 43

Install MongoDB on Fedora 43

MongoDB stands as one of the most popular NoSQL database solutions for modern application development. Its flexible document-oriented data model makes it an ideal choice for developers working with dynamic schemas and complex data structures. However, installing MongoDB on Fedora 43 requires a specific approach since the database management system is no longer available in Fedora’s official repositories due to licensing conflicts with the Server Side Public License (SSPL).

This comprehensive guide walks you through the complete installation process of MongoDB on Fedora 43, from repository configuration to security hardening. Whether you’re a system administrator, developer, or database enthusiast, you’ll find detailed step-by-step instructions, troubleshooting tips, and best practices for deploying a secure and reliable MongoDB instance on your Fedora system.

Prerequisites and System Requirements

Before beginning the MongoDB installation process, ensure your Fedora 43 system meets the necessary requirements. You’ll need administrative privileges, typically through sudo access, to execute system-level commands and modify configuration files. An active internet connection is essential for downloading MongoDB packages from the official repository.

Your system should have adequate resources allocated for database operations. MongoDB performs best with at least 2GB of RAM, though production environments typically require much more depending on your database size and workload. Ensure you have sufficient disk space available, as MongoDB stores data files in /var/lib/mongo by default. Basic familiarity with Linux terminal commands and text editors like nano, vim, or gedit will make the installation process smoother.

Understanding MongoDB Repository Configuration

Fedora determined that MongoDB’s Server Side Public License v1 (SSPL) does not qualify as a Free Software License. This licensing issue led to MongoDB’s removal from Fedora’s official repositories. Consequently, never updating MongoDB would introduce security vulnerabilities, making the official MongoDB repository the recommended installation source.

The solution involves configuring DNF (Dandified YUM) to use MongoDB’s official repository designed for Red Hat Enterprise Linux (RHEL). Fedora serves as an experimental testing ground for technologies that eventually make their way into RHEL, ensuring strong compatibility between the two distributions. DNF reads configuration from /etc/dnf/dnf.conf and repository files located in /etc/yum.repos.d/, with repository-specific configurations taking precedence over global settings.

Using RHEL 9 packages provides the most stable installation path for Fedora 43. MongoDB maintains separate repositories for different version series, allowing you to choose specific releases based on your requirements.

Step 1: Creating the MongoDB Repository File

Begin by creating a dedicated repository configuration file for MongoDB. Open your terminal and execute the following command to create a new repository file using your preferred text editor:

sudo nano /etc/yum.repos.d/mongodb-org-7.0.repo

This creates a repository file for MongoDB 7.0, the latest stable release series. Alternatively, you can use the tee command for a more streamlined approach:

sudo tee /etc/yum.repos.d/mongodb-org-7.0.repo<<EOF
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
EOF

Each configuration parameter serves a specific purpose in repository management. The [mongodb-org-7.0] identifier names the repository section, while the name field provides a human-readable description. The baseurl points to the RHEL 9 package location for MongoDB 7.0 on x86_64 architecture.

Security features are controlled through the gpgcheck=1 setting, which ensures package authenticity by verifying GPG signatures. The enabled=1 parameter activates the repository immediately. Finally, gpgkey specifies the URL for MongoDB’s public GPG key used in package verification.

For different MongoDB versions, simply adjust the version numbers in both the filename and the baseurl. Version 6.0 remains a popular choice for enhanced compatibility.

Step 2: Installing MongoDB Packages

With the repository configured, refresh your DNF package cache to recognize the new MongoDB repository:

sudo dnf clean all
sudo dnf makecache

Now install MongoDB using the mongodb-org metapackage:

sudo dnf install mongodb-org

The mongodb-org package installs several critical components that work together to provide complete MongoDB functionality. The mongodb-org-server package contains the mongod daemon, the core database server process. MongoDB-org-mongos provides the sharding routing service for distributed deployments. The mongodb-org-shell includes the legacy mongo shell, though mongosh is now the recommended interactive shell. MongoDB-org-tools bundles essential utilities for database administration, backup, and restoration.

During installation, you may encounter warnings about certain packages not installing completely. These missing packages typically don’t affect MongoDB’s core functionality. The installation process handles dependencies automatically, though some RHEL-specific packages might generate compatibility warnings on Fedora systems.

MongoDB does not officially guarantee full compatibility with Fedora Linux distributions. Newer MongoDB server packages might occasionally fail to install due to platform-specific dependencies. However, the RHEL 9 packages work reliably on Fedora 43 in most scenarios.

Step 3: Starting and Enabling MongoDB Service

Fedora 43 uses systemd for service management, providing powerful control over daemon processes. Start the MongoDB service immediately with the following command:

sudo systemctl start mongod

This initiates the mongod daemon, which begins listening for database connections on the default port 27017. To ensure MongoDB starts automatically when your system boots, enable the service:

sudo systemctl enable mongod

Verify that MongoDB is running correctly by checking the service status:

sudo systemctl status mongod

A successful start displays output indicating the service is active (running). The status command provides valuable information including the service’s current state, process ID (PID), memory usage, and recent log entries.

The MongoDB service configuration resides in /usr/lib/systemd/system/mongod.service. This systemd unit file defines how the system manages the MongoDB daemon, including environment variables, startup commands, and resource limits.

Additional systemctl commands provide comprehensive service control. Use sudo systemctl restart mongod to stop and immediately restart the service, particularly useful after configuration changes. The sudo systemctl stop mongod command gracefully shuts down MongoDB. For configuration reloads without full restart, execute sudo systemctl reload mongod.

Step 4: Verifying MongoDB Installation

Test your MongoDB installation by connecting to the database using the mongosh shell. Simply run:

mongosh

Mongosh, the modern MongoDB Shell, offers significant improvements over the legacy mongo command. It provides syntax highlighting, intelligent autocomplete, and better error messages, making database interaction more intuitive and productive.

Upon successful connection, mongosh displays the MongoDB version and connection details:

Current Mongosh Log ID: 5f8a2c3b4d5e6f7g8h9i0j1k
Connecting to: mongodb://127.0.0.1:27017
Using MongoDB: 7.0.8
Using Mongosh: 2.0.0

Execute basic MongoDB commands to verify full functionality. The show dbs command lists all available databases. Create or switch to a test database with use testdb. Check your MongoDB version precisely using db.version().

MongoDB maintains detailed logs at /var/log/mongodb/mongod.log. These logs prove invaluable for troubleshooting connection issues, performance problems, or unusual behavior. Review log entries regularly to monitor database health and catch potential issues early.

Understanding MongoDB Configuration File

The primary MongoDB configuration file is located at /etc/mongod.conf. This YAML-formatted file controls all aspects of MongoDB’s behavior, from storage locations to network settings.

Key configuration parameters include storage.dbPath, which defaults to /var/lib/mongo or /var/lib/mongod depending on your installation. This directory stores all database files and collections. The systemLog section defines logging behavior, including the destination file and verbosity level.

Network configuration sits under the net section. The default port is 27017, though you can change this for security or multi-instance setups. The bindIp parameter controls which network interfaces MongoDB listens on. The default 127.0.0.1 restricts connections to localhost only, providing strong security for development environments. Setting bindIp: 0.0.0.0 allows connections from any network interface, necessary for remote access but requiring additional security measures.

The storage.engine parameter specifies which storage engine MongoDB uses. WiredTiger, the default engine, provides excellent performance and compression capabilities. Engine choice significantly impacts database performance characteristics.

When modifying configuration files, always create a backup first. After making changes, validate your YAML syntax carefully, as errors prevent MongoDB from starting. Reload the service configuration using sudo systemctl daemon-reload, then restart MongoDB with sudo systemctl restart mongod.

Configuring MongoDB Security

Security should be a top priority for any database deployment. MongoDB ships with authentication disabled by default, allowing anyone with network access to connect without credentials. This configuration is acceptable only for isolated development environments.

Enable authentication by first creating an administrative user. Connect to MongoDB using mongosh without authentication:

mongosh

Switch to the admin database and create a user with administrative privileges:

use admin
db.createUser({
  user: "mongoAdmin",
  pwd: "SecurePassword123!",
  roles: [
    { role: "userAdminAnyDatabase", db: "admin" },
    { role: "readWriteAnyDatabase", db: "admin" },
    { role: "dbAdminAnyDatabase", db: "admin" }
  ]
})

The userAdminAnyDatabase role allows user management across all databases. The readWriteAnyDatabase role provides read and write access to all databases, while dbAdminAnyDatabase grants database administration capabilities.

After creating the administrative user, enable authorization in the MongoDB configuration file. Edit /etc/mongod.conf and add or modify the security section:

security:
  authorization: enabled

Save the configuration file and restart MongoDB:

sudo systemctl restart mongod

Now authentication is required for all connections. Connect using your credentials:

mongosh -u mongoAdmin -p SecurePassword123! --authenticationDatabase admin

Alternatively, connect first then authenticate:

mongosh
use admin
db.auth("mongoAdmin", "SecurePassword123!")

Successful authentication returns 1, while failed attempts return 0.

Create database-specific users following the principle of least privilege. For example, create a user with limited access to a single database:

use myappdb
db.createUser({
  user: "appuser",
  pwd: "AppPassword456!",
  roles: [
    { role: "readWrite", db: "myappdb" }
  ]
})

Role-Based Access Control (RBAC) forms the foundation of MongoDB security. Always assign users the minimum permissions necessary for their tasks. Regularly audit user permissions and remove unnecessary access.

Consider implementing TLS/SSL encryption for production deployments, especially when MongoDB accepts remote connections. Encrypted connections prevent credential interception and data eavesdropping during network transmission.

Firewall Configuration for MongoDB

Fedora 43 ships with firewalld active by default, blocking incoming connections to non-standard ports. If you need to access MongoDB from other machines, configure the firewall appropriately while maintaining security.

Open port 27017 for MongoDB traffic using firewall-cmd:

sudo firewall-cmd --permanent --add-port=27017/tcp

The --permanent flag ensures the rule persists across system reboots. Reload firewall rules to apply changes immediately:

sudo firewall-cmd --reload

Verify the firewall configuration lists port 27017:

sudo firewall-cmd --list-ports

Exercise extreme caution when exposing MongoDB to networks. Only open firewall ports after implementing authentication and ensuring your bindIp configuration matches your security requirements. Consider using network-level restrictions through firewall zones or rich rules to limit access to specific IP addresses or subnets.

For enhanced security, use SSH tunneling or VPN connections instead of direct network exposure. This approach keeps MongoDB’s port closed on the firewall while still allowing remote access through encrypted tunnels.

Common Troubleshooting Issues

MongoDB service fails to start commonly due to permission problems with data directories. Verify that the mongod user owns the data directory:

sudo chown -R mongod:mongod /var/lib/mongo
sudo chmod 755 /var/lib/mongo

If the data directory doesn’t exist, create it manually:

sudo mkdir -p /var/lib/mongo
sudo chown mongod:mongod /var/lib/mongo

Port conflicts occur when another service uses port 27017. Identify which process occupies the port:

sudo ss -tulpn | grep 27017

Either stop the conflicting service or configure MongoDB to use a different port in /etc/mongod.conf.

SELinux, Fedora’s security enhancement system, sometimes prevents MongoDB from accessing necessary files. Check SELinux status:

sudo sestatus

Review SELinux denials related to MongoDB:

sudo ausearch -m avc -ts recent | grep mongod

If SELinux blocks legitimate MongoDB operations, create appropriate policy modules rather than disabling SELinux entirely.

Dependency conflicts may arise when using RHEL packages on Fedora. Some mongodb-org-tools components might fail to install due to platform-python dependencies. These failures typically don’t affect core MongoDB server functionality.

Connection refused errors indicate MongoDB isn’t listening on the expected address or port. Verify the service is running using sudo systemctl status mongod. Check bind configuration in /etc/mongod.conf matches your connection attempts.

MongoDB logs provide detailed error information. Examine recent log entries:

sudo tail -f /var/log/mongodb/mongod.log

Systemd journal entries offer additional troubleshooting context:

sudo journalctl -xe -u mongod

For persistent installation issues, consider using containerized MongoDB through Podman or Docker. Container deployment isolates MongoDB from system-level complications while providing consistent behavior across platforms.

Post-Installation Best Practices

Implement a comprehensive backup strategy immediately after installation. Regular backups protect against data loss from hardware failures, software bugs, or human errors. Use mongodump for logical backups or filesystem snapshots for physical backups.

Monitor MongoDB performance and resource utilization continuously. Track metrics like memory usage, disk I/O, query performance, and connection counts. Tools like MongoDB Compass, mongostat, and mongotop provide real-time insights into database operations.

Keep MongoDB updated with the latest stable releases. Updates include security patches, bug fixes, and performance improvements. However, always test updates in non-production environments before deploying to production systems.

Enable audit logging for compliance and security monitoring. Audit logs record authentication attempts, schema changes, and data access patterns, helping identify security incidents or policy violations.

Perform regular database maintenance tasks. Rebuild indexes periodically to maintain query performance. Compact data files to reclaim disk space. Analyze query patterns and create indexes accordingly.

Document all configuration changes, custom settings, and operational procedures. Comprehensive documentation proves invaluable during troubleshooting, system upgrades, or team transitions. Include rationale for non-default configurations and security policies.

Conduct regular security audits reviewing user permissions, network access controls, and authentication configurations. Remove unnecessary user accounts and restrict permissions following the principle of least privilege.

Optimize MongoDB configuration for your specific workload. Adjust cache size (cacheSizeGB) based on available RAM and dataset size. Configure compression settings to balance storage efficiency against CPU usage. Monitor performance metrics and iterate configuration adjustments for optimal results.

Alternative Installation Methods

Containerization offers a compelling alternative to native MongoDB installation. Podman, Fedora’s container management tool, runs MongoDB in isolated environments without impacting the host system. Pull and run the official MongoDB container:

podman run -d --name mongodb -p 27017:27017 -v ~/mongodb_data:/data/db mongo:latest

Container deployment provides consistency across different systems and simplified version management. Containers encapsulate MongoDB with all dependencies, eliminating compatibility concerns with the host operating system.

Another approach uses distrobox to run MongoDB within a CentOS Stream or AlmaLinux container. This method provides full RHEL compatibility while maintaining container isolation:

distrobox create --name mongodb-box --image almalinux:9
distrobox enter mongodb-box

Inside the distrobox environment, follow standard RHEL MongoDB installation procedures.

Consider installing MongoDB 4.4 for maximum Fedora compatibility if newer versions present persistent issues. Older versions trade cutting-edge features for proven stability on Fedora platforms.

Each installation method presents different trade-offs. Native installation offers best performance and simplest management. Containers provide isolation and consistency. Choose based on your specific requirements, technical expertise, and operational constraints.

Congratulations! You have successfully installed MongoDB. Thanks for using this tutorial for installing the MongoDB database on your Fedora 43 Linux system. For additional Apache or useful information, we recommend you check the official MongoDB website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button