How to install MongoDB 5.0 server on Debian 11 Bullseye 2021

0

This tutorial explains how to install MongoDB 5.0 server on Debian 11 Bullseye. We will do our best to make sure you understand this guide. I hope you will like this blog How to install MongoDB 5.0 server on Debian 11 Bullseye. If your answer is yes, please share after reading this.

Check how you can install MongoDB 5.0 server on Debian 11 Bullseye

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

  • Perfect data redistribution
  • Multi-cloud security tools
  • Serverless database in MongoDB Atlas
  • Native time series functions
  • Live repartitioning
  • The versioned API prepares your applications for the future.

MongoDB is good for the following:

  • Changing data needs.
  • Blogs and content management.
  • Social and mobile networking sites
  • Catalog of e-commerce products.
  • configuration management
  • High-speed real-time analysis and 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. The Mongo-org package always contains the latest available versions of MongoDB.

First, we import the GPG public key from MongoDB. Download it using wget as shown 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 accordingly. However, if you get an error stating that GnuPG is not installed, install it as follows.

sudo apt update

sudo apt-get install gnupg2

With GnuPG installed, try importing the keys again:

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 be using the buster repository for both distributions because, at the time of this article’s documentation, the bullseye repository 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 shown below.

$ sudo apt-get update

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

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

Coup: 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 / version 5.0 [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]

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

Reading Package Lists… Done

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

In this guide, we are going to install a specific version, i.e. 5.0.2, and therefore specify each component package with the version number as shown 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.2 without specifying the component version, the latest version of each component will be installed.

Dependency tree from the previous command:

Building dependency tree

Reading status 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 updated, 9 newly installed, 0 to remove, and 2 not updated.

You should get 147MB of files.

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

With MongoDB 5.0 installed, we are now ready to perform some configuration on our system. First, start and activate the mongod service on Debian 11 / Debian 10 as shown below.

sudo systemctl start mongod

sudo systemctl activate mongod

Check the version of MongoDB installed.

$ mongod –version

database version v5.0.2

Construction information: {

“Version”: “5.0.2”,

“GitVersion”: “6d9ec525e78465dcecadcff99cce953d380fedc8”,

“OpenSSLVersion”: “OpenSSL 1.1.1k March 25, 2021”,

“Modules”: [],

“Mapper”: “tcmalloc”,

“environment”: {

“Distmod”: “debian10”,

“Draft”: “x86_64”,

“Target_arch”: “x86_64”

}

}

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

Check if the service is running:

$ systemctl status mongod

● mongod.service: MongoDB database server

Loaded: Loaded (/lib/systemd/system/mongod.service; Enabled; Provider Preset: Enabled)

Active: active (in operation) from Saturday 21 / 08-2021 07:49:24 EDT; 39 s ago

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

Main PID: 5029 (Mongod)

Memory: 71.4M

Group C: /system.slice/mongod.service

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

Aug 21 07:49:24 ns1.computingforgeeks.local systemd[1]: The MongoDB database server has started.

Aug 21 07:49:29 ns1.computingforgeeks.local systemd[1]: /lib/systemd/system/mongod.service:11: PIDFile = reference path under the inherited directory / var / run….

MongoDB 5.0 secure instance.

After installation, the MongoDB database is not secure. You can access it without a password and make unwanted changes to your database. Therefore, we need to protect this database by creating a username and password. Connect to the database by issuing the code:

$ mongo

Then add a user called mongouser, remember you can change this name as you like. With the following added script, you need to set a password for the user.

use administrator

db.createUser (

{

user: “mongouser”,

pwd: passwordPrompt (), // or clear text password

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

}

)

Sample output for the script.

> use administrator

changed to database administrator

> db.createUser (

… {

… User: “mongouser”,

… Pwd: passwordPrompt (), // or clear text password

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

…}

…)

Enter password:

User successfully added: {

“User”: “mongouser”,

“The roles”: [

{

“role” : “userAdminAnyDatabase”,

“db” : “admin”

},

“readWriteAnyDatabase”

]

}

> exit

goodbye

Then 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, and then add authentication. Make sure to add a double space before the authorization as the syntax is very important here. Your file should appear as shown below.

Security:

authorization: activated

For the changes to take effect, restart the MongoDB service.

sudo systemctl restart mongod

Clients must now authenticate to access the database. The syntax used is as follows.

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

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

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

mongo -u mongouser -p -authenticationDatabase admin

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

Step 5: Change the default MongoDB path in Debian 11 / Debian 10

The default path used as storage for MongoDB data is / var / lib / mongo. However, this directory can be changed as shown 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 that will belong to MongoDB.

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

3. Copy the 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

After making these changes, restart the MongoDB service. MongoDB will start using the newly created directory to store your data.

sudo systemctl start mongod.service

Final words: how to install MongoDB 5.0 server on Debian 11 Bullseye

hope you will understand this item How to install MongoDB 5.0 server on Debian 11 Bullseye, if your answer is no, you can request anything through the contact forum section linked to this article. And if your answer is yes, then share this article with your family and friends.

Share.

Leave A Reply