Mai 23, 2026Guides
Installer MongoDB sur un VPS Linux
MongoDB Community sur Ubuntu et CentOS, authentification et commandes de base.

MongoDB est une base NoSQL populaire pour apps et API. Installation sur VPS Hiddence et sécurisation de base.
Installation sur Ubuntu 22.04+
bash
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt update
sudo apt install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
mongosh --eval "db.runCommand({ ping: 1 })"Installation sur RHEL / CentOS / Alma / Rocky
bash
cat <<EOF | sudo tee /etc/yum.repos.d/mongodb-org-7.0.repo
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
EOF
sudo yum install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongodActiver lâauthentification
CrĂ©ez un admin avant dâexposer MongoDB au rĂ©seau :
bash
mongosh
use admin
db.createUser({
user: "admin",
pwd: "StrongPasswordHere",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
})
# Dans /etc/mongod.conf :
# security:
# authorization: enabled
sudo systemctl restart mongodCommandes de base
bash
mongosh -u admin -p --authenticationDatabase admin
show dbs
use myapp
db.users.insertOne({ name: "test", email: "a@b.com" })
db.users.find()Bonnes pratiques
- Lier MongoDB Ă 127.0.0.1 sans accĂšs distant requis
- Bloquer le port 27017 au pare-feu
- Sauvegardes réguliÚres avec mongodump
- Surveiller lâespace disque
- Replica sets pour haute dispo en production
MongoDB sâinstalle proprement depuis les dĂ©pĂŽts officiels. Activez lâauth, limitez le rĂ©seau et sauvegardez avant la production.