Minecraft Server — Vanilla
Récupère la dernière version stable via l'API Mojang, installe Java 21 et crée un service systemd.
Prérequis :
- Debian 11/12, Ubuntu 22+
- Accès root
- Variable optionnelle :
MC_MEMORY=4Gpour changer la RAM allouée (défaut : 2G)
Ce que fait le script :
- Installe
openjdk-21-jre-headless - Interroge l'API Mojang pour obtenir la dernière release
- Télécharge le
server.jarofficiel - Crée l'utilisateur
minecraftet le dossier/opt/minecraft/vanilla - Configure
eula.txtetserver.properties - Active un service systemd
minecraft
Après l'install : ouvre le port 25565/tcp sur ton firewall.
bash
#!/bin/bash
set -euo pipefail
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERR]${NC} $*"; exit 1; }
[[ $EUID -ne 0 ]] && error "Ce script doit être exécuté en root."
MC_USER="minecraft"
MC_DIR="/opt/minecraft/vanilla"
MC_MEMORY="${MC_MEMORY:-2G}"
# ── Java 21 ──────────────────────────────────────────────────────────────────
info "=== Étape 1/5 — Installation de Java 21 ==="
apt-get update -qq
apt-get install -y -qq openjdk-21-jre-headless curl python3
java -version 2>&1 | grep -oP '"\K[^"]+' | { read v; info "Java installé : $v"; }
# ── Dernière version Mojang ───────────────────────────────────────────────────
info "=== Étape 2/5 — Récupération de la dernière version ==="
MANIFEST=$(curl -fsSL https://launchermeta.mojang.com/mc/game/version_manifest_v2.json)
LATEST=$(echo "$MANIFEST" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['latest']['release'])")
VER_URL=$(echo "$MANIFEST" | python3 -c "
import sys, json
d = json.load(sys.stdin)
latest = d['latest']['release']
print(next(v['url'] for v in d['versions'] if v['id'] == latest))
")
JAR_URL=$(curl -fsSL "$VER_URL" | python3 -c "import sys,json; print(json.load(sys.stdin)['downloads']['server']['url'])")
info "Version : $LATEST"
# ── Dossier & utilisateur ────────────────────────────────────────────────────
info "=== Étape 3/5 — Préparation de l'environnement ==="
useradd -r -m -d "$MC_DIR" -s /bin/false "$MC_USER" 2>/dev/null || true
mkdir -p "$MC_DIR"
# ── Téléchargement ───────────────────────────────────────────────────────────
info "=== Étape 4/5 — Téléchargement du serveur ==="
curl -fsSL --progress-bar -o "$MC_DIR/server.jar" "$JAR_URL"
echo "eula=true" > "$MC_DIR/eula.txt"
cat > "$MC_DIR/server.properties" <<EOF
server-port=25565
max-players=20
difficulty=normal
gamemode=survival
level-name=world
online-mode=true
view-distance=10
motd=Minecraft $LATEST
EOF
chown -R "$MC_USER:$MC_USER" "$MC_DIR"
# ── Systemd ──────────────────────────────────────────────────────────────────
info "=== Étape 5/5 — Service systemd ==="
cat > /etc/systemd/system/minecraft.service <<EOF
[Unit]
Description=Minecraft Vanilla $LATEST
After=network.target
[Service]
User=$MC_USER
WorkingDirectory=$MC_DIR
ExecStart=/usr/bin/java -Xms512M -Xmx${MC_MEMORY} -jar server.jar nogui
ExecStop=/usr/bin/kill -s SIGINT \$MAINPID
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now minecraft
echo ""
info "=== Minecraft $LATEST installé et démarré ==="
echo ""
echo " Répertoire : $MC_DIR"
echo " Port : 25565/tcp"
echo " RAM allouée : $MC_MEMORY (override: MC_MEMORY=4G bash ...)"
echo " Statut : systemctl status minecraft"
echo " Logs : journalctl -fu minecraft"
echo " Stop/start : systemctl stop|start minecraft"
echo ""
warn "Pense à ouvrir le port 25565/tcp sur ton firewall !"
echo ""