How to install MongoDB 5.0 Server on Debian 11 Bullseye

How to install MongoDB 5.0 Server on Debian 11 Bullseye

Hello Geeky, so today we are focusing on How you can install MongoDB 5.0 Server on Debian 11 Bullseye. So please read this tutorial carefully so you may comprehend it in a better helpful way.

Guide: How you can install MongoDB 5.0 Server on Debian 11 Bullseye

This guide provides a systematic demonstration of how to Install MongoDB 5.0 on Debian 11/ Debian 10 Linux systems. MongoDB is a general-purpose, object-oriented, simple, and dynamic database. It is a NoSQL document store. This means that data objects are stored as separate documents in a collection. This helps to overcome the relational databases approach. MongoDB is written in C++ for massive scalability and high performance. It is available for Windows, macOS, and Linux Operating Systems and is supported by both 32 and 64-bit architectures. MongoDB 5.0 brings new features such as:

  • Seamless data redistribution
  • Multi cloud-security tools
  • Serverless database on MongoDB Atlas
  • Native time-series features
  • Live Resharding
  • The Versioned API future-proofs your applications.

MongoDB is good for the following:

  • Evolving data requirements.
  • Blogs and content management.
  • Mobile and social networking sites
  • E-commerce product catalogue.
  • configuration management
  • Real-time analytics and high-speed logging

Step 1: Add MongoDB APT repository on Debian 11/ Debian 10

In this guide, we will install MongoDB 5.0 using the apt manager. Here we will use the official mongo-org package. This package is supported and maintained by MongoDB Inc. Mongo-org package always contains the latest available versions of MongoDB.

First, we import the MongoDB public GPG key. Download it using wget as below. Install wget on Debian 11/ Debian 10 using sudo apt install wget

wget -qO – https://www.mongodb.org/static

This code should respond with OK as the output. However, if you get an error indicating that GnuPG is not installed, install it as below.

sudo apt update

sudo apt-get install gnupg2

With GnuPG installed, retry key importation:

wget -qO – https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add –

The next step requires us to create a /etc/apt/sources.list.d/mongodb-org-5.0.list file for MongoDB 5.0. We will use the buster’s repo for both distros since, by the time of documenting this article, the one for bullseye did not exist.

echo “deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main” | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

Then update your local package database as below.

$ sudo apt-get update

Hit:1 http://deb.debian.org/debian buster InRelease

Hit:2 http://security.debian.org/debian-security buster/updates InRelease

Hit:3 http://deb.debian.org/debian buster-updates InRelease

Ign:4 http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 InRelease

Get:5 http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 Release [2,396 B]

Get:6 http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 Release.gpg [801 B]

Get:7 http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0/main amd64 Packages [6,551 B]

Fetched 9,748 B in 3s (3,461 B/s)

Reading package lists… Done

Step 2: Install MongoDB 5.0 on Debian 11/ Debian 10

In this guide, we will install a specific release i.e 5.0.2 and therefore we will specify each component package with the version number as below.

sudo apt-get install -y mongodb-org mongodb-org-database mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools

If you choose to install mongodb-org=5.0.2without specifying components’ version, the latest version of each component will be installed.

Dependency tree of the above command:

Building dependency tree

Reading state information… Done

The following additional packages will be installed:

mongodb-database-tools mongodb-mongosh mongodb-org-database-tools-extra

The following NEW packages will be installed:

mongodb-database-tools mongodb-mongosh mongodb-org mongodb-org-database

mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server

mongodb-org-shell mongodb-org-tools

0 upgraded, 9 newly installed, 0 to remove and 2 not upgraded.

Need to get 147 MB of archives.

After this operation, 449 MB of additional disk space will be used.

With MongoDB 5.0 installed, we are now set to make a few configurations to our system. First, start and enable the mongod service on Debian 11/ Debian 10 as below.

sudo systemctl start mongod

sudo systemctl enable mongod

Check the installed MongoDB version.

$ mongod –version

db version v5.0.2

Build Info: {

“version”: “5.0.2”,

“gitVersion”: “6d9ec525e78465dcecadcff99cce953d380fedc8”,

“openSSLVersion”: “OpenSSL 1.1.1k 25 Mar 2021”,

“modules”: [],

“allocator”: “tcmalloc”,

“environment”: {

“distmod”: “debian10”,

“distarch”: “x86_64”,

“target_arch”: “x86_64”

}

}

Step 3: Configure MongoDB on Debian 11/ Debian 10.

Verify if the service is running:

$ systemctl status mongod

● mongod.service – MongoDB Database Server

Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)

Active: active (running) since Sat 2021-08-21 07:49:24 EDT; 39s ago

Docs: https://docs.mongodb.org/manual

Main PID: 5029 (mongod)

Memory: 71.4M

CGroup: /system.slice/mongod.service

└─5029 /usr/bin/mongod –config /etc/mongod.conf

Aug 21 07:49:24 ns1.computingforgeeks.local systemd[1]: Started MongoDB Database Server.

Aug 21 07:49:29 ns1.computingforgeeks.local systemd[1]: /lib/systemd/system/mongod.service:11: PIDFile= references path below legacy directory /var/run….

Secure MongoDB 5.0 Instance.

After installation, the MongoDB database has no security, One can access it without a password and make undesired changes to your database. Therefore, we need to secure this database by creating a username and password. Connect to the database by issuing the code:

$ mongo

Then add a user named mongouser, remember you can change this name to your desired one. with the below script added, you are required to set a password for the user.

use admin

db.createUser(

{

user: “mongouser”,

pwd: passwordPrompt(), // or cleartext password

roles: [ { role: “userAdminAnyDatabase”, db: “admin” }, “readWriteAnyDatabase” ]

}

)

Sample output for the script.

 

> use admin

switched to db admin

> db.createUser(

… {

… user: “mongouser”,

… pwd: passwordPrompt(), // or cleartext password

… roles: [ { role: “userAdminAnyDatabase”, db: “admin” }, “readWriteAnyDatabase” ]

… }

… )

Enter password:

Successfully added user: {

“user” : “mongouser”,

“roles” : [

{

“role” : “userAdminAnyDatabase”,

“db” : “admin”

},

“readWriteAnyDatabase”

]

}

> exit

bye

Next, edit the MongoDB configuration file and enable authentication.

sudo apt install vim

sudo vim /etc/mongod.conf

In the file, find the #security line, uncomment it then add the authentication. Ensure you add double space before authorization since the syntax is very important here. Your file should appear as below.

security:

authorization: enabled

For the changes made to apply, restart the MongoDB service.

sudo systemctl restart mongod

Now clients need to authenticate themselves to access the database. The syntax used is as below.

mongo –port 27017 –authenticationDatabase “admin” -u “your-user” -p

Step 4: Using MongoDB 5.0 on Debian 11/ Debian 10.

MongoDB listens on a default port 27017. From the localhost connect to the created user using

mongo -u mongouser -p –authenticationDatabase admin

Enter the password you created earlier to connect to your database.

Step 5: Change MongoDB default Path on Debian 11/ Debian 10

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.

sudo systemctl stop mongod.service

2. Create a new directory for MongoDB data.

sudo mkdir -p /data/computingforgeeks/mongo

Set the directory to be owned by MongoDB.

sudo chown -R mongodb:mongodb /data/computingforgeeks/mongo

3. Copy contents to the new directory. Install Rsync using sudo apt install rsync

sudo rsync -av /var/lib/mongodb /data/computingforgeeks/mongo

4. Rename the old directory for backup.

sudo mv /var/lib/mongodb /var/lib/mongodb.bak

5. Create a symbolic link to the new location.

sudo ln -s /data/computingforgeeks/mongo /var/lib/mongodb

With these changes made, restart the MongoDB service. MongoDB will start using the new directory created to store its data.

sudo systemctl start mongod.service

Faq

Guide about How you can install MongoDB 5.0 Server on Debian 11 Bullseye


In this guide, we told you about the How you can install MongoDB 5.0 Server on Debian 11 Bullseye; please read all steps above so that you understand How you can install MongoDB 5.0 Server on Debian 11 Bullseye in case if you need any assistance from us, then contact us.

How this tutorial or guide assisting you?


So in this guide, we discuss the How you can install MongoDB 5.0 Server on Debian 11 Bullseye, which undoubtedly benefits you.




Final note

I hope you like the guide How you can install MongoDB 5.0 Server on Debian 11 Bullseye. In case if you have any queries regards this article/tutorial you may ask us. Also, please share your love by sharing this article with your friends and family.

Trickbugs: Get the latest Trick and Tips
Logo
Enable registration in settings - general