This commit is contained in:
Ornel_Zply 2025-11-06 13:03:07 +01:00
parent 5123a547d9
commit 50ee1271dd
2 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,104 @@
#!/bin/bash
# ---------------------------------------------------------
# Script d'installation automatique de Node Exporter + Promtail
# Compatible Debian/Ubuntu
# ---------------------------------------------------------
set -e # Stoppe le script en cas d'erreur
# --- Variables globales ---
NODE_EXPORTER_VERSION="1.7.0"
PROMTAIL_VERSION="2.9.2"
LOKI_SERVER_IP="192.168.56.16" # à modifier selon ton environnement
HOSTNAME_LABEL=$(hostname)
# --- Vérification utilisateur root ---
if [ "$EUID" -ne 0 ]; then
echo "Ce script doit être exécuté en tant que root (sudo)."
exit 1
fi
echo "🚀 Mise à jour du système..."
apt update -y && apt install -y wget unzip
# --- Installation de Node Exporter ---
echo "Installation de Node Exporter v${NODE_EXPORTER_VERSION}..."
cd /tmp
wget -q https://github.com/prometheus/node_exporter/releases/download/v${NODE_EXPORTER_VERSION}/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz
tar xvf node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz
mv node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64/node_exporter /usr/local/bin/
useradd -rs /bin/false nodeusr || true
cat >/etc/systemd/system/node_exporter.service <<EOF
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=nodeusr
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now node_exporter
echo "Node Exporter installé et démarré."
# --- Installation de Promtail ---
echo "Installation de Promtail v${PROMTAIL_VERSION}..."
cd /tmp
wget -q https://github.com/grafana/loki/releases/download/v${PROMTAIL_VERSION}/promtail-linux-amd64.zip
unzip -o promtail-linux-amd64.zip
mv promtail-linux-amd64 /usr/local/bin/promtail
chmod +x /usr/local/bin/promtail
# --- Configuration de Promtail ---
cat >/etc/promtail-config.yml <<EOF
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://${LOKI_SERVER_IP}:3100/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: vm-observed
host: ${HOSTNAME_LABEL}
__path__: /var/log/*.log
EOF
# --- Service Promtail ---
cat >/etc/systemd/system/promtail.service <<EOF
[Unit]
Description=Promtail
After=network.target
[Service]
ExecStart=/usr/local/bin/promtail -config.file=/etc/promtail-config.yml
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now promtail
echo "Promtail installé et démarré."
# --- Résumé ---
echo "Installation terminée avec succès !"
echo "----------------------------------------"
echo "Node Exporter : http://$(hostname -I | awk '{print $1}'):9100/metrics"
echo "Promtail : config => /etc/promtail-config.yml"
echo "Loki Server IP : ${LOKI_SERVER_IP}:3100"
echo "----------------------------------------"