Skip to content

Deployment Overview of MongoDB on Server

Prerequisites and Basic Requirements

The following requirements must be met before deploying MongoDB on the server:

  • Operating System: Ubuntu Jammy (22.04 LTS)

  • Architecture: AMD64 or ARM64

  • Privileges: Root access or a user with sudo privileges is required to install packages and manage services.

  • Domain: The server operates within the hostkey.in zone.

  • Ports: The default port for MongoDB is 27017, which must be open for local or internal network access unless otherwise configured.

File and Directory Structure

MongoDB components are installed in the following locations:

  • Configuration Directory: /etc/mongod.conf (Main configuration file)

  • Data Directory: /var/lib/mongo (Default location for database storage)

  • Log Directory: /var/log/mongodb (Location for log files)

  • Lock File: /var/lock/mongodb (Location for lock files)

  • PID File: /var/run/mongodb (Location for process ID files)

Application Installation Process

The application is installed using the native package manager for the Ubuntu distribution. The installation process includes the following steps:

  1. System Update: The system packages are updated using the APT package manager.

  2. Dependency Installation: Required tools such as curl, gnupg, nano, vim, htop, net-tools, and dnsutils are installed.

  3. Repository Setup:

    • The GPG key for MongoDB version 8.0 is added to the system.

    • A repository list file is created at /etc/apt/sources.list.d/mongodb-org-8.0.list pointing to the official MongoDB repository for ubuntu jammy.

  4. Package Installation: The mongodb-org package is installed, which includes the MongoDB server (mongod) and client tools.

  5. Service Activation: The mongod service is started and enabled to launch automatically on system boot.

Access Rights and Security

Security measures are implemented as follows:

  • Service Management: The MongoDB service is managed via systemd.

  • Firewall: The configuration assumes that necessary ports are open for the MongoDB service. External access should be restricted to trusted networks.

  • Authentication: By default, MongoDB installations require explicit configuration to enable authentication. Ensure that user accounts are created and authentication is enabled in the configuration file before exposing the service to untrusted networks.

Databases

The database storage and connection settings are configured as follows:

  • Storage Location: Data is stored in the /var/lib/mongo directory.

  • Connection Method: Connections are established via the TCP/IP protocol.

  • Default Bind Address: MongoDB typically binds to 127.0.0.1 (localhost) by default, requiring local access unless the bindIp parameter is modified in the configuration file.

  • Database Engine: The installation provides the standard MongoDB 8.0 engine.

Available Ports for Connection

The following port is utilized by the deployed MongoDB instance:

  • 27017: Default port for the MongoDB service.

Starting, Stopping, and Updating

The MongoDB service is managed using systemd commands. Use the following commands to control the service:

  • Start the service:

    sudo systemctl start mongod
    

  • Stop the service:

    sudo systemctl stop mongod
    

  • Restart the service:

    sudo systemctl restart mongod
    

  • Check service status:

    sudo systemctl status mongod
    

  • Enable service on boot:

    sudo systemctl enable mongod
    

To update the MongoDB software to a newer patch version available in the repository, run:

sudo apt update
sudo apt upgrade mongodb-org

question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×