MongoDB is a NoSQL database that uses a document-oriented data model, making it ideal for handling large amounts of data. In this guide, we will walk through the steps to install and secure MongoDB on Debian 11.

Step 1: Update Your System

Start by ensuring your system is up to date:

sudo apt update && sudo apt upgrade -y

Step 2: Import the MongoDB Public Key

Import the public GPG key used by the MongoDB package management system:

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

Step 3: Create the MongoDB Source List File

Create a list file for MongoDB:

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/debian bullseye/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

Step 4: Update the Package Database

Update the package database to include the MongoDB packages:

sudo apt update

Step 5: Install MongoDB

Install MongoDB using the following command:

sudo apt install -y mongodb-org

Step 6: Start and Enable MongoDB

Start the MongoDB service and enable it to run at boot:

sudo systemctl start mongod
sudo systemctl enable mongod

Step 7: Secure MongoDB

By default, MongoDB is not secured. To secure it, first, enable authentication. Edit the MongoDB configuration file:

sudo nano /etc/mongod.conf

Find the line that says security: and add the following under it:

authorization: "enabled"

Save and exit the editor, then restart MongoDB:

sudo systemctl restart mongod

Step 8: Create an Admin User

Connect to the MongoDB shell:

mongo

Switch to the admin database and create a new admin user:

use admin
db.createUser({user: "admin", pwd: "your_password", roles: [{role: "userAdminAnyDatabase", db: "admin"}]})

Replace your_password with a strong password.

Step 9: Verify Authentication

Exit the MongoDB shell and try to connect again with authentication:

mongo -u admin -p your_password --authenticationDatabase admin

Conclusion

You have successfully installed and secured MongoDB on Debian 11. This database will help you manage your data efficiently and securely.

If you're looking for a reliable hosting solution for your MongoDB server, consider using Windows VPS UK. With Windows VPS, you can efficiently host your applications and ensure high performance. Whether you need VPS UK Windows or Windows Virtual Private Servers, you'll find a solution that fits your requirements.

For larger deployments or enterprise needs, explore Windows Virtual Dedicated Server Hosting or Virtual Private Server Hosting Windows. Whether you're located in the UK, Italy, or elsewhere, Windows VPS Italy and UK VPS Windows offer reliable hosting options. Visit Windows VPS Hosting UK to discover the best hosting solutions for your needs.

¿Fue útil la respuesta? 0 Los Usuarios han Encontrado Esto Útil (0 Votos)