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 Debian 10 & 11 user, this comprehensive guide will take you through the step-by-step process how to install MongoDB 6.0 on Debian 10/11, 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 Debian 11
- 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.
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 Debian Server instance with root access or sudo privileges. To set this up, follow our guide : Initial Setup Debian 11 Server: Secure and Efficient
- Basic familiarity with command-line operations.
Installing MongoDB 6.0 on Debian 11
Proceed by following these comprehensive steps to install MongoDB 6 on your most up-to-date Debian Servers.
Step 1: System Update
To start, ensure that your Debian Server is up to date. go to terminal and run the following command:
samm@mongodb:~$ sudo apt-get update
samm@mongodb:~$ sudo apt-get upgrade -y
Step 2: Install Required Packages
MongoDB provides an official repository for various Linux distributions, including Debian. 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
#Debian 11
samm@mongodb:~$ echo "deb http://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
#Debian 10
samm@mongodb:~$ echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
Step 3: Install MongoDB on Debian 10 & 11
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 installation 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 - intipseleb 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 intipseleb 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: Secure MongoDB Instance.
After installation, the MongoDB database has no security, One 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 127.0.0.1:27017 -u "mongo-admin" -p --authenticationDatabase "admin"
Enter password: m0ngO4dm1n2023
or using the ip address server
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://@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: mongo documentations.
Step 7: Change MongoDB default Path (optional)
While the default storage path for MongoDB data set to /var/lib/mongo, you can modify this directory 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 adjustments, proceed to restart the MongoDB service. MongoDB will commence utilizing the newly designated directory to store its data.
samm@mongodb:~$ sudo systemctl restart mongod
Conclusion
Congratulations! You’ve successfully install MongoDB 6.0 on your Debian 10/11 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 Ubuntu Server 22.04
- How To Install MongoDB 6.0 on Rocky Linux 9
- How To Install DBeaver Community on Ubuntu 22.04
Finally, now you have learned how to install MongoDB 6.0 on Debian 10/11.