• About Us
  • Disclaimers
  • Privacy Policy
  • Sitemap
Linux Tutorials for Beginners
Advertisement
  • Ubuntu
    Install and Secure phpMyAdmin on Ubuntu 22.04

    How To Install and Secure phpMyAdmin on Ubuntu 22.04

    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Ubuntu 22.04

    Install Uptime Kuma on Ubuntu 22.04

    How To Install Uptime Kuma on Ubuntu 22.04

    Install Ubuntu Server 22.04

    How To Install Ubuntu Server 22.04 LTS with Screenshots

    Set Up Firewall on Ubuntu 22.04

    How To Set Up a Firewall with UFW on Ubuntu 22.04

    Install Nginx on Ubuntu

    How To Install Nginx on Ubuntu 22.04: A Comprehensive Guide

    Install MySQL 8.0 on Ubuntu 22.04

    How To Install MySQL 8.0 on Ubuntu Server 22.04

    install-php74-ubuntu2204

    How To Install PHP 7.4 on Ubuntu 22.04

    Install Snipe-IT on Ubuntu 22.04

    How To Install Snipe-IT Asset Management on Ubuntu 22.04

  • Debian
    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Debian 11

    Install Debian 11 Server

    How To Install Debian 11 (Bullseye) Server with Pictures

    Install and Setup Node.js on Debian 11

    How To Install and Setup Node.js on Debian 11

    Install PHP 8.2 on Debian 11

    How To Install PHP 8.2 on Debian 11

    Install Nginx on Debian 11

    How To Install Nginx on Debian 11: A Comprehensive Guide

    Set Up Firewall with UFW on Debian

    How To Set Up a Firewall with UFW on Debian 11

    install php74 on debian 11

    How To Install PHP 7.4 on Debian 11

    Install MariaDB 10.9 on Debian 11

    How To Install MariaDB 10.9 on Debian 11 Server

    Initial Setup Debian Server

    Initial Setup Debian 11 Server: Secure and Efficient

  • Rocky Linux
    Install phpMyAdmin on Rocky Linux 9

    How To Install phpMyAdmin on Rocky Linux 9

    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Rocky Linux 9

    Install Rocky Linux 9.2 Server

    How To Install Rocky Linux 9.2 Server with Screenshots

    setup Firewall Using Firewalld Rocky Linux 9

    How To Set Up a Firewall Using FirewallD on Rocky Linux 9

    Install Nginx on Rocky Linux 9

    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide

    Install Apache on Rocky Linux

    How To Install and Configure Apache on Rocky Linux 9

    Install MongoDB on Rocky Linux 9

    How To Install MongoDB 6.0 on Rocky Linux 9

    Install Docker on Rocky Linux

    How To Install Docker CE on Rocky Linux 9

  • CentOS
    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on CentOS 7

    Install PHP8.2 on CentOS 7

    How To Install PHP 8.2 on CentOS 7 / RHEL 7

    Install Apache on CentOS 7

    How To Install Apache Web Server on CentOS 7

    Set Up FirewallD on CentOS 7

    How To Set Up a Firewall Using FirewallD on CentOS 7

    Initial Setup CentOS 7 Server

    Initial Setup CentOS 7 Server: Secure and Efficient

    Install Nginx on CentOS 7

    How To Install Nginx on CentOS 7: A Comprehensive Guide

    Build NGINX from Source on Centos 7

    How To Build NGINX from Source (Compile) on Centos7

    Install Docker Swarm on CentOS 7

    Install and Configure Docker Swarm Mode on Centos 7

    Install Docker Compose on Centos 7

    How To Install and Use Docker Compose on Centos 7

  • Linux
    Manage Groups on Linux

    A Simple Guide: How To Manage Groups on Linux

    Logrotate In Linux

    How To Manage Log Files Using Logrotate In Linux

    Check File Size in Linux

    The Easy Ways to Check File Size in Linux

    Linux server security system administrators

    Best Practices Linux Server Security for System Administrator

    Backup Files From Remote Linux VPS Using Rsync Script

    How To Backup Files From Remote Linux VPS Using Rsync Script

    SSH Key-based Authentication

    How To Configure SSH Key-based Authentication In Linux

    Linux File Permissions

    Understanding Linux File Permissions for Beginners

    Create Multiboot USB with Ventoy

    How To Create Multiboot USB with Ventoy in Linux

    Find Hard Disk Drive Information in Linux

    How To Find Hard Disk Drive Information in Linux

No Result
View All Result
Linux Tutorials for Beginners
  • Ubuntu
    Install and Secure phpMyAdmin on Ubuntu 22.04

    How To Install and Secure phpMyAdmin on Ubuntu 22.04

    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Ubuntu 22.04

    Install Uptime Kuma on Ubuntu 22.04

    How To Install Uptime Kuma on Ubuntu 22.04

    Install Ubuntu Server 22.04

    How To Install Ubuntu Server 22.04 LTS with Screenshots

    Set Up Firewall on Ubuntu 22.04

    How To Set Up a Firewall with UFW on Ubuntu 22.04

    Install Nginx on Ubuntu

    How To Install Nginx on Ubuntu 22.04: A Comprehensive Guide

    Install MySQL 8.0 on Ubuntu 22.04

    How To Install MySQL 8.0 on Ubuntu Server 22.04

    install-php74-ubuntu2204

    How To Install PHP 7.4 on Ubuntu 22.04

    Install Snipe-IT on Ubuntu 22.04

    How To Install Snipe-IT Asset Management on Ubuntu 22.04

  • Debian
    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Debian 11

    Install Debian 11 Server

    How To Install Debian 11 (Bullseye) Server with Pictures

    Install and Setup Node.js on Debian 11

    How To Install and Setup Node.js on Debian 11

    Install PHP 8.2 on Debian 11

    How To Install PHP 8.2 on Debian 11

    Install Nginx on Debian 11

    How To Install Nginx on Debian 11: A Comprehensive Guide

    Set Up Firewall with UFW on Debian

    How To Set Up a Firewall with UFW on Debian 11

    install php74 on debian 11

    How To Install PHP 7.4 on Debian 11

    Install MariaDB 10.9 on Debian 11

    How To Install MariaDB 10.9 on Debian 11 Server

    Initial Setup Debian Server

    Initial Setup Debian 11 Server: Secure and Efficient

  • Rocky Linux
    Install phpMyAdmin on Rocky Linux 9

    How To Install phpMyAdmin on Rocky Linux 9

    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on Rocky Linux 9

    Install Rocky Linux 9.2 Server

    How To Install Rocky Linux 9.2 Server with Screenshots

    setup Firewall Using Firewalld Rocky Linux 9

    How To Set Up a Firewall Using FirewallD on Rocky Linux 9

    Install Nginx on Rocky Linux 9

    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide

    Install Apache on Rocky Linux

    How To Install and Configure Apache on Rocky Linux 9

    Install MongoDB on Rocky Linux 9

    How To Install MongoDB 6.0 on Rocky Linux 9

    Install Docker on Rocky Linux

    How To Install Docker CE on Rocky Linux 9

  • CentOS
    Secure SSH with Fail2Ban

    How To Secure SSH with Fail2Ban on CentOS 7

    Install PHP8.2 on CentOS 7

    How To Install PHP 8.2 on CentOS 7 / RHEL 7

    Install Apache on CentOS 7

    How To Install Apache Web Server on CentOS 7

    Set Up FirewallD on CentOS 7

    How To Set Up a Firewall Using FirewallD on CentOS 7

    Initial Setup CentOS 7 Server

    Initial Setup CentOS 7 Server: Secure and Efficient

    Install Nginx on CentOS 7

    How To Install Nginx on CentOS 7: A Comprehensive Guide

    Build NGINX from Source on Centos 7

    How To Build NGINX from Source (Compile) on Centos7

    Install Docker Swarm on CentOS 7

    Install and Configure Docker Swarm Mode on Centos 7

    Install Docker Compose on Centos 7

    How To Install and Use Docker Compose on Centos 7

  • Linux
    Manage Groups on Linux

    A Simple Guide: How To Manage Groups on Linux

    Logrotate In Linux

    How To Manage Log Files Using Logrotate In Linux

    Check File Size in Linux

    The Easy Ways to Check File Size in Linux

    Linux server security system administrators

    Best Practices Linux Server Security for System Administrator

    Backup Files From Remote Linux VPS Using Rsync Script

    How To Backup Files From Remote Linux VPS Using Rsync Script

    SSH Key-based Authentication

    How To Configure SSH Key-based Authentication In Linux

    Linux File Permissions

    Understanding Linux File Permissions for Beginners

    Create Multiboot USB with Ventoy

    How To Create Multiboot USB with Ventoy in Linux

    Find Hard Disk Drive Information in Linux

    How To Find Hard Disk Drive Information in Linux

No Result
View All Result
Linux Tutorials for Beginners
No Result
View All Result

Home » Ubuntu » How To Install MongoDB 6.0 on Ubuntu Server 22.04

How To Install MongoDB 6.0 on Ubuntu Server 22.04

sammbysamm
October 16, 2023
Install MongoDB on Ubuntu

How To Install MongoDB 6.0 on Ubuntu Server 22.04

Share on FacebookShare on LinkedinShare on Whatsapp

Introduction

In the realm of modern data management, MongoDB has emerged as a leading NoSQL database solution, empowering organizations to handle diverse data types effectively. With the recent release of MongoDB 6.0, there’s a wave of excitement surrounding its enhanced features and capabilities. If you’re an Ubuntu Server 22.04 user, this comprehensive guide will take you through the step-by-step process of installing MongoDB 6.0, enabling you to harness its potential for robust data management and storage.

Table of Contents

  • Introduction
  • Embracing MongoDB 6.0
  • Prerequisites
  • Installing MongoDB 6.0 on Ubuntu Server 22.04
    • Step 1: System Update
    • Step 2: Configure the MongoDB Repository
    • Step 3: Install MongoDB on Ubuntu Server 22.04
    • Step 4: Enable and Start MongoDB
    • Step 5: Access and Secure MongoDB
      • Create the Admin User
      • Add Database and User MongoDB
      • Enabling Authentication
    • Step 6: Access MongoDB Instance
    • Step 7: Change MongoDB default Path (optional)
  • Conclusion

Embracing MongoDB 6.0

MongoDB 6.0 brings with it a range of groundbreaking enhancements that elevate data management to new heights. From native time series collections to advanced full-text search capabilities and bolstered security features, MongoDB 6.0 empowers businesses to navigate through intricate data landscapes with agility, performance, and scalability.

OTHER POSTS

How To Install and Secure phpMyAdmin on Ubuntu 22.04

How To Secure SSH with Fail2Ban on Ubuntu 22.04

How To Install Uptime Kuma on Ubuntu 22.04

MongoDB uses a flexible data model and supports a wide range of data types, including strings, numbers, booleans, arrays, and embedded documents. This flexibility makes it well-suited for handling unstructured and semi-structured data.

Some key features of MongoDB include:

  • Scalability: MongoDB can handle large amounts of data and can be easily scaled horizontally across multiple servers or clusters.
  • High Availability: MongoDB provides replication and automated failover, ensuring that data remains accessible even in the event of hardware or network failures.
  • Flexible Querying: MongoDB supports powerful query capabilities, including rich document querying, indexing, and aggregation framework for complex data retrieval and analysis.
  • Ad hoc Updates: MongoDB allows for flexible updates and modifications to documents without requiring a predefined schema.
  • Integration and Ecosystem: MongoDB has a vast ecosystem with support for multiple programming languages, frameworks, and tools. It also integrates well with other technologies such as Apache Spark, Hadoop, and various cloud platforms.

Prerequisites

Before diving into the installation process, make sure you have the following prerequisites ready:

  • An Ubuntu Server 22.04 instance with root access or sudo privileges. To set this up, follow our guide : Initial Setup Ubuntu Server 22.04: Secure and Efficient. Basic familiarity with command-line operations.

Installing MongoDB 6.0 on Ubuntu Server 22.04

Follow the next steps to install MongoDB 6 on your latest Ubuntu Servers 22.04

Step 1: System Update

Begin by ensuring your Ubuntu Server is up to date. Open a terminal and execute the following command:

samm@mongodb:~$ sudo apt-get update 
samm@mongodb:~$ sudo apt-get upgrade -y

Step 2: Configure the MongoDB Repository

MongoDB provides an official repository for various Linux distributions, including Ubuntu. Add the MongoDB repository to your system with the command:

samm@mongodb:~$ sudo apt install wget curl gnupg gnupg2 software-properties-common apt-transport-https ca-certificates lsb-release

samm@mongodb:~$ curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-6.gpg

samm@mongodb:~$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

Step 3: Install MongoDB on Ubuntu Server 22.04

Now that the repository is configured, proceed to update packages and install MongoDB 6.0.

samm@mongodb:~$ sudo apt update

samm@mongodb:~$ sudo apt install mongodb-org

This command will automatically install the MongoDB package along with its required dependencies. Once the install is complete, you’re ready to config, enable and start MongoDB.

Step 4: Enable and Start MongoDB

After the successful install of MongoDB, enable the MongoDB service to start on system boot and start the service:

samm@mongodb:~$ sudo systemctl enable --now mongod
Created symlink /etc/systemd/system/multi-user.target.wants/mongod.service → /lib/systemd/system/mongod.service.

Once the MongoDB is enabled, start the MongoDB

samm@mongodb:~$ sudo systemctl start mongod

Confirm that MongoDB is running

samm@mongodb:~$ sudo systemctl status mongod
● mongod.service - MongoDB 6.0.5 Document Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-03-20 23:55:47 WIB; 7s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 1200 (mongod)
     Memory: 62.6M
        CPU: 582ms
     CGroup: /system.slice/mongod.service
             └─1200 /usr/bin/mongod --config /etc/mongod.conf

Mar 20 23:55:47 mongodb systemd[1]: Started MongoDB 6.0.5 Document Database Server.

To check the version of MongoDB, run following command.

samm@mongodb:~$ mongod --version
db version v6.0.5
Build Info: {
    "version": "6.0.5",
    "gitVersion": "c9a99c120371d4d4c52cbb15dac34a36ce8d3b1d",
    "openSSLVersion": "OpenSSL 1.1.1n  15 Mar 2022",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "debian11",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Step 5: Access and Secure MongoDB

After installation, the MongoDB database has no security, anyone can access it without a password and make undesired changes to your database. Therefore, for enhanced security, consider configuring authentication for MongoDB.

Create the Admin User

samm@mongodb:~$ mongosh 127.0.0.1:27017

Next, generate a user with the name “mongo-admin” – feel free to adjust this name to your liking. Following the integration of the provided script, it becomes essential to set up a password for this particular user.

test> use admin
switched to db admin

admin> db.createUser({ user: "mongo-admin", pwd: "m0ngO4dm1n2023", roles: [{role: "root", db: "admin"}]})
{ ok: 1 }

admin> db.system.users.find()
[
  {
    _id: 'admin.mongo-admin',
    userId: new UUID("af967ad4-9d24-4617-9615-80e793b6b5c1"),
    user: 'mongo-admin',
    db: 'admin',
    credentials: {
      'SCRAM-SHA-1': {
        iterationCount: 10000,
        salt: 'I0esBbduvM8pmHQ2fp2leg==',
        storedKey: 'KQb8b3TSF6py6O75FAwSO3mFZ7w=',
        serverKey: 'kPqwkvgHRsqIjgZ+c2Hl4FhpBis='
      },
      'SCRAM-SHA-256': {
        iterationCount: 15000,
        salt: '8rEzL0MdSZ2WABlcUTDchV3kt2x48epC+IHtKQ==',
        storedKey: 'FrryrJLaIABb7PEebk2zYSfUQa/P9ATkyEWP+TgPZQo=',
        serverKey: 'JLFgZVMZdLUt4zKXdjswysoLkSKlqEAFWc1SvqNJvyQ='
      }
    },
    roles: [ { role: 'root', db: 'admin' } ]
  }
]

Add Database and User MongoDB

To add database and user MongoDB, execute the following commands:

  • Create Database
admin> use sammlinux_db
switched to db sammlinux_db
  • Add User Read Wirite (R/W)
sammlinux_db> db.createUser({ user: "samm-rw", pwd: "s4mm&2023", roles: [{role: "readWrite", db: "sammlinux_db"}]})
  • Add User Read Only (R/O)
sammlinux_db> db.createUser({ user: "samm-ro", pwd: "s4mm#2023", roles: [{role: "read", db: "sammlinux_db"}]})

Enabling Authentication

Afterward, modify the MongoDB configuration file to enable authentication.

samm@mongodb:~$ sudo vi /etc/mongod.conf

net:
  port: 27017
  bindIp: 127.0.0.1,172.32.1.80

security:
  authorization: enabled

samm@mongodb:~$ sudo systemctl restart mongod

Step 6: Access MongoDB Instance

Now, clients are required to authenticate themselves in order to gain access to the database. When accessing MongoDB from a client, utilize the server’s IP address, The syntax employed is as follows:

samm@mongodb:~$ mongosh 172.32.1.80:27017 -u "mongo-admin" -p --authenticationDatabase "admin"
Enter password: m0ngO4dm1n2023
Current Mongosh Log ID: 63955de17d5b6ddaa159e24e
Connecting to:      mongodb://<credentials>@172.32.1.80:27017/?directConnection=true&authSource=sammlinux_db&appName=mongosh+1.6.2
Using MongoDB:      6.0.5
Using Mongosh:      1.6.2

test> show dbs
sammlinux_db  40.00 KiB
test> 

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

Step 7: Change MongoDB default Path (optional)

The default path used as a storage for MongoDB data is /var/lib/mongo. However, this directory can be altered as below.

  • Stop the MongoDB service.
samm@mongodb:~$ sudo systemctl stop mongod
  • Create a new directory for MongoDB data.
samm@mongodb:~$ sudo mkdir -p /database/mongodb
samm@mongodb:~$ sudo mkdir -p /database/mongodb/data
samm@mongodb:~$ sudo mkdir -p /database/mongodb/log
samm@mongodb:~$ sudo chown mongodb.mongodb -R /database/mongodb
  • Copy contents to the new directory.
samm@mongodb:~$ sudo rsync -av /var/lib/mongodb /database/mongodb/data
  • Rename the old directory for backup.
samm@mongodb:~$ sudo mv /var/lib/mongodb /var/lib/mongodb.bak

After implementing these modifications, proceed to restart the MongoDB service. MongoDB will initiate using the newly established directory to store its data.

samm@mongodb:~$ sudo systemctl restart mongod

Conclusion

Congratulations! You’ve successfully installed MongoDB 6.0 on your Ubuntu Server 22.04 instance. This sophisticated NoSQL database empowers you to manage and manipulate data with flexibility and efficiency. As you embark on your journey with MongoDB 6.0, remember to explore its enhanced features and capabilities, leveraging its potential to streamline your data management strategies. Stay attuned to MongoDB’s documentation and updates to ensure you’re making the most of this powerful tool in the realm of modern data management.

Also Read Our Other Guides :

  • How To Install MongoDB 6.0 on Debian 10 & 11
  • How To Install MongoDB 6.0 on Rocky Linux 9
  • How To Install MySQL 8.0 on Ubuntu Server 22.04
  • How To Install MariaDB 10.6 on Ubuntu Server 22.04

Finally, now you have learned how to install MongoDB 6.0 on your Ubuntu 22.04 Server.

Tags: DatabasesMongoDBNoSQLUbuntu

If you got help by our tutorials, please buy me a coffee..!

Buy Me a Coffee

Thank you so much for your support!!

Previous Post

How To Install Redis on Ubuntu Server 22.04

Next Post

How To Build NGINX from Source (Compile) on Debian 11

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

RECENT POST

Install and Secure phpMyAdmin on Ubuntu 22.04

How To Install and Secure phpMyAdmin on Ubuntu 22.04

by samm
July 22, 2024
0

Are you ready to take control of your MySQL databases on Ubuntu 22.04? In this step-by-step guide, we'll walk you...

Manage Groups on Linux

A Simple Guide: How To Manage Groups on Linux

by samm
November 12, 2023
0

Are you a Linux enthusiast looking to enhance your system administration skills? One fundamental aspect you should master is how...

Install phpMyAdmin on Rocky Linux 9

How To Install phpMyAdmin on Rocky Linux 9

by samm
November 11, 2023
0

If you're navigating the world of Rocky Linux 9 and looking to streamline your MariaDB or MySQL database management, installing...

Logrotate In Linux

How To Manage Log Files Using Logrotate In Linux

by samm
November 10, 2023
0

Log files are an essential part of any Linux system. They provide valuable insights into the system's activities, helping administrators...

Load More

RECOMMENDED.

Install Redis on Debian

How To Install Redis on Debian 11 Server

October 16, 2023
Secure SSH with Fail2Ban

How To Secure SSH with Fail2Ban on Rocky Linux 9

October 29, 2023
sammlinux sammlinux sammlinux

Related Posts

Install and Secure phpMyAdmin on Ubuntu 22.04
Ubuntu

How To Install and Secure phpMyAdmin on Ubuntu 22.04

July 22, 2024
Secure SSH with Fail2Ban
Ubuntu

How To Secure SSH with Fail2Ban on Ubuntu 22.04

October 29, 2023
Install Uptime Kuma on Ubuntu 22.04
Ubuntu

How To Install Uptime Kuma on Ubuntu 22.04

November 12, 2023
Install Ubuntu Server 22.04
Ubuntu

How To Install Ubuntu Server 22.04 LTS with Screenshots

October 21, 2023
Load More
Next Post
Build NGINX on Debian

How To Build NGINX from Source (Compile) on Debian 11

  • About Us
  • Disclaimers
  • Privacy Policy
  • Sitemap

© 2023 sammlinux - Learn Today for Lead Tomorrow.

No Result
View All Result
  • Ubuntu
  • Debian
  • Rocky Linux
  • CentOS
  • Linux

© 2023 sammlinux - Learn Today for Lead Tomorrow.