Zum Hauptinhalt springen Zur Suche springen Zum Menü springen

[HowTo] Node-RED + InfluxDB + Grafana auf Debian sicher installieren

#1

[HowTo] Node-RED + InfluxDB + Grafana auf Debian sicher installieren

Hallo zusammen,

in diesem Beitrag zeige ich euch, wie ihr auf Debian Linux (z. B. Debian 12 Bookworm) eine saubere und sichere Umgebung für Node-RED, InfluxDB, Grafana und MQTT aufsetzt.
Damit habt ihr eine stabile Basis für eure PV-Anlage, Victron-Systeme oder Smart Home Projekte.


Voraussetzungen

  • Frisches Debian (mindestens 11, besser 12)
  • Root-Zugang oder ein Nutzer mit sudo
  • Basiswissen Linux/SSH

1. System vorbereiten

sudo apt update
sudo apt full-upgrade -y
sudo apt install -y curl wget gnupg2 ca-certificates software-properties-common

Admin-Konto anlegen (falls nicht vorhanden):

sudo adduser admin
sudo usermod -aG sudo admin

2. SSH absichern

Schlüsselpaar auf dem Client erstellen und hochladen:

ssh-keygen -t ed25519 -C "mein-admin"
ssh-copy-id admin@server

SSH-Config anpassen:

sudo nano /etc/ssh/sshd_config

Wichtige Zeilen:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes

Dienst neu laden:

sudo systemctl reload ssh

3. Firewall & Schutz

UFW installieren und konfigurieren:

sudo apt install -y ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow from 192.168.1.0/24 to any port 22 proto tcp
sudo ufw allow from 192.168.1.0/24 to any port 1880 proto tcp
sudo ufw allow from 192.168.1.0/24 to any port 3000 proto tcp
sudo ufw allow from 192.168.1.0/24 to any port 8086 proto tcp
sudo ufw allow from 192.168.1.0/24 to any port 1883 proto tcp
sudo ufw enable

Zusatzschutz gegen Brute-Force:

sudo apt install -y fail2ban
sudo systemctl enable --now fail2ban

4. Node-RED installieren

Eigenen User anlegen:

sudo adduser --gecos "" --disabled-password nodered

Node-RED + Node.js installieren:

sudo -u nodered bash -lc 'bash <(curl -sL https://github.com/node-red/linux-installers/releases/latest/download/update-nodejs-and-nodered-deb)'

Systemd-Service konfigurieren (Unit auf nodered-User anpassen):

sudo nano /lib/systemd/system/nodered.service

Dann starten:

sudo systemctl daemon-reload
sudo systemctl enable --now nodered

Zugriff absichern (Admin-Login aktivieren):

sudo -u nodered bash -lc 'node-red admin hash-pw'
sudo nano /home/nodered/.node-red/settings.js

5. MQTT-Broker (Mosquitto)

sudo apt install -y mosquitto mosquitto-clients
sudo systemctl enable --now mosquitto

Passwortschutz aktivieren:

sudo mosquitto_passwd -c /etc/mosquitto/passwd iotuser
echo -e "allow_anonymous false\npassword_file /etc/mosquitto/passwd\nlistener 1883" | sudo tee /etc/mosquitto/conf.d/auth.conf
sudo systemctl restart mosquitto

6. InfluxDB 2.x installieren

sudo mkdir -p /etc/apt/keyrings
curl -sL https://repos.influxdata.com/influxdata-archive.key | gpg --dearmor | sudo tee /etc/apt/keyrings/influxdata-archive.gpg >/dev/null
echo 'deb [signed-by=/etc/apt/keyrings/influxdata-archive.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list
sudo apt update
sudo apt install -y influxdb2
sudo systemctl enable --now influxdb

Setup starten (Web auf Port 8086 oder CLI):

influx setup

7. Grafana installieren

sudo mkdir -p /etc/apt/keyrings
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg >/dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana
sudo systemctl enable --now grafana-server

Webinterface: http://server-ip:3000
Default Login: admin / admin


8. Node-RED mit InfluxDB verbinden

Paket installieren:

sudo -u nodered bash -lc 'cd ~/.node-red && npm install node-red-contrib-influxdb'
sudo systemctl restart nodered

In Node-RED:

  • InfluxDB Node hinzufügen
  • Verbindung mit http://localhost:8086 und Token eintragen
  • Bucket auswählen

9. Test-Flow MQTT → Node-RED → InfluxDB

MQTT-Testnachricht senden:

mosquitto_pub -h localhost -t test/sensor -m '{"power":123.4,"temp":22.1}'

Node-RED Flow:

  • MQTT In Node (test/sensor)
  • JSON Node
  • Function Node:
msg.payload = [
  { measurement: "sensor",
    fields: { power: msg.payload.power, temp: msg.payload.temp }
  }
];
return msg;
  • InfluxDB Out Node → Bucket

10. Grafana Dashboard erstellen

  1. Login auf http://server-ip:3000
  2. Data Source → InfluxDB anlegen
  3. Panel erstellen und Messung sensor auswählen

Fertig – eure Daten fließen! 🎉


11. Sicherheit & Updates

  • Keine Root-SSH-Logins
  • Firewall aktiv
  • Node-RED Passwortschutz aktiviert
  • Regelmäßige Updates:
sudo apt update && sudo apt upgrade -y

Hilfreich 1

Zum Antworten mit dem Kundenkonto anmelden.