4NK_node/scripts/install_loki_promtail_local.sh
Debian bb61be04a4
Some checks failed
CI - 4NK_node / Code Quality (push) Failing after 50s
CI - 4NK_node / Unit Tests (push) Failing after 29s
CI - 4NK_node / Integration Tests (push) Failing after 12s
CI - 4NK_node / Security Tests (push) Failing after 27s
CI - 4NK_node / Docker Build & Test (push) Failing after 9s
CI - 4NK_node / Documentation Tests (push) Failing after 4s
CI - 4NK_node / Security Audit (push) Successful in 3s
CI - 4NK_node / Release Guard (push) Has been skipped
CI - 4NK_node / Performance Tests (push) Successful in 28s
CI - 4NK_node / Notify (push) Failing after 2s
CI - 4NK_node / Publish Release (push) Has been skipped
clean
2025-09-04 08:13:43 +00:00

110 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Version et URLs
LOKI_VER="2.9.0"
PROMTAIL_VER="2.9.0"
LOKI_URL="https://github.com/grafana/loki/releases/download/v${LOKI_VER}/loki-linux-amd64.zip"
PROMTAIL_URL="https://github.com/grafana/loki/releases/download/v${PROMTAIL_VER}/promtail-linux-amd64.zip"
# Détection Distro et dépendances
if [ -f /etc/os-release ]; then
. /etc/os-release
fi
OS_ID=${ID:-debian}
sudo apt-get update
sudo apt-get install -y curl unzip
# Installer Loki
sudo mkdir -p /usr/local/bin /etc/loki /var/lib/loki
sudo curl -L -o /tmp/loki-linux-amd64.zip "$LOKI_URL"
sudo unzip -o /tmp/loki-linux-amd64.zip -d /usr/local/bin
sudo bash -lc 'cat > /etc/systemd/system/loki.service <<EOF
[Unit]
Description=Loki service
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/local/bin/loki-linux-amd64 -config.file=/etc/loki/local-config.yaml
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.target
EOF'
sudo mkdir -p /etc/loki /var/lib/loki
sudo tee /etc/loki/local-config.yaml >/dev/null << 'EOF'
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9095
ingester:
wal:
enabled: true
storage_config:
boltdb:
directory: /var/lib/loki/chunks
limits_config:
enforce_metric_name: false
EOF
sudo systemctl daemon-reload
sudo systemctl enable loki
sudo systemctl start loki
# Installer Promtail
sudo mkdir -p /usr/local/bin /etc/promtail /var/log/promtail
sudo curl -L -o /tmp/promtail-linux-amd64.zip "$PROMTAIL_URL"
sudo unzip -o /tmp/promtail-linux-amd64.zip -d /usr/local/bin
sudo bash -lc 'cat > /etc/systemd/system/promtail.service <<EOF
[Unit]
Description=Promtail service
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/local/bin/promtail-linux-amd64 -config.file=/etc/promtail/promtail.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF'
sudo mkdir -p /etc/promtail
sudo tee /etc/promtail/promtail.yaml >/dev/null << 'EOF'
server:
http_listen_port: 9080
positions:
filename: /var/log/promtail/positions.yaml
clients:
- url: http://localhost:3100/loki/api/v1/push
scrape_configs:
- job: grafana-logs
static_configs:
- targets: [localhost]
labels:
__path__: /home/debian/code/logs/*.log
job: logs
- job: coffre-logs
static_configs:
- targets: [localhost]
labels:
__path__: /home/debian/code/4NK_dev/4NK_node/log/*.log
job: coffre_logs
EOF
sudo systemctl daemon-reload
sudo systemctl enable promtail
sudo systemctl start promtail
# Vérifications simples
echo
echo "Grafana Loki Promtail local install terminé. Vérifications:"
echo " - Grafana: http://localhost:3000"
echo " - Loki: http://localhost:3100"
echo " - Promtail: service actif (Promtail)"