Zurück zum Blog
Mai 23, 2026Anleitungen

MongoDB auf einem Linux-VPS installieren

MongoDB Community auf Ubuntu und CentOS, Authentifizierung und Grundbefehle.

MongoDB auf einem Linux-VPS installieren

MongoDB ist eine beliebte NoSQL-Datenbank für Apps und APIs. Installation auf dem Hiddence-VPS mit grundlegender Absicherung.

Installation auf 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 auf 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 mongod

Authentifizierung aktivieren

Admin-Benutzer anlegen, bevor MongoDB im Netz erreichbar ist:

bash
mongosh

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

# In /etc/mongod.conf:
# security:
#   authorization: enabled

sudo systemctl restart mongod

Grundbefehle

bash
mongosh -u admin -p --authenticationDatabase admin

show dbs
use myapp
db.users.insertOne({ name: "test", email: "a@b.com" })
db.users.find()

Best Practices

  • MongoDB an 127.0.0.1 binden, wenn kein Fernzugriff nötig
  • Port 27017 in der Firewall blockieren
  • Regelmäßige Backups mit mongodump
  • Speicherplatz beobachten — DBs wachsen schnell
  • Replica Sets für Hochverfügbarkeit in Produktion