Netdata — Monitoring temps réel
Netdata offre un tableau de bord web en temps réel avec des milliers de métriques : CPU, mémoire, disques, réseau, services, containers Docker, etc.
Ce que fait le script :
- Installe Netdata via le script officiel (méthode recommandée)
- Configure la rétention des données (7 jours par défaut)
- Restreint l'accès à localhost + IP LAN (optionnel)
- Crée un vhost Nginx de proxy si Nginx est présent
Accès après install :
- Direct :
http://IP:19999 - Via Nginx :
http://netdata.mondomaine.fr
Variable optionnelle :
NETDATA_DOMAIN— domaine pour le vhost Nginx (ex :netdata.monserveur.fr)
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."
NETDATA_DOMAIN="${NETDATA_DOMAIN:-}"
# ── Installation via script officiel ─────────────────────────────────────────
info "=== Installation de Netdata ==="
apt-get update -qq
apt-get install -y curl
curl -fsSL https://get.netdata.cloud/kickstart.sh > /tmp/netdata-install.sh
bash /tmp/netdata-install.sh --stable-channel --dont-wait --disable-telemetry
rm -f /tmp/netdata-install.sh
# ── Configuration de base ─────────────────────────────────────────────────────
info "=== Configuration ==="
CONF="/etc/netdata/netdata.conf"
if [[ -f "$CONF" ]]; then
# Rétention 7 jours, 1 sample/seconde
sed -i 's/^.*history\s*=.*/ history = 604800/' "$CONF" 2>/dev/null || true
else
cat > "$CONF" <<'EOF'
[global]
run as user = netdata
history = 604800
update every = 1
[web]
bind to = 0.0.0.0:19999
allow connections from = *
EOF
fi
# ── Vhost Nginx (optionnel) ───────────────────────────────────────────────────
if [[ -n "$NETDATA_DOMAIN" ]] && command -v nginx &>/dev/null; then
info "=== Configuration vhost Nginx pour $NETDATA_DOMAIN ==="
# Mot de passe d'accès basique
if ! command -v htpasswd &>/dev/null; then
apt-get install -y -qq apache2-utils
fi
NETDATA_PASS=$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c 16)
htpasswd -bc /etc/nginx/.htpasswd_netdata admin "$NETDATA_PASS"
cat > "/etc/nginx/sites-available/netdata-${NETDATA_DOMAIN}.conf" <<EOF
upstream netdata {
server 127.0.0.1:19999;
keepalive 64;
}
server {
listen 80;
listen [::]:80;
server_name ${NETDATA_DOMAIN};
location / {
auth_basic "Netdata";
auth_basic_user_file /etc/nginx/.htpasswd_netdata;
proxy_pass http://netdata;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_cache_bypass \$http_upgrade;
}
}
EOF
ln -sf "/etc/nginx/sites-available/netdata-${NETDATA_DOMAIN}.conf" \
"/etc/nginx/sites-enabled/netdata-${NETDATA_DOMAIN}.conf"
nginx -t && systemctl reload nginx
info "Vhost Nginx configuré pour $NETDATA_DOMAIN (auth : admin / $NETDATA_PASS)"
fi
# ── Démarrage ─────────────────────────────────────────────────────────────────
systemctl enable --now netdata 2>/dev/null || true
systemctl restart netdata
sleep 3
LOCAL_IP=$(hostname -I | awk '{print $1}')
echo ""
info "=== Netdata installé ==="
echo ""
echo " Accès direct : http://${LOCAL_IP}:19999"
if [[ -n "$NETDATA_DOMAIN" ]] && command -v nginx &>/dev/null; then
echo " Via Nginx : http://${NETDATA_DOMAIN} (admin / $NETDATA_PASS)"
echo ""
echo " SSL : certbot --nginx -d ${NETDATA_DOMAIN}"
fi
echo ""
echo " Statut : systemctl status netdata"
echo " Config : /etc/netdata/netdata.conf"
echo " Logs : journalctl -fu netdata"
echo ""
warn "Port 19999 exposé publiquement. Utilise le vhost Nginx avec auth ou ferme ce port."
echo ""