From 07371be90008bd2ade042ca5056aafef398c6d93 Mon Sep 17 00:00:00 2001 From: Michael Kretzl Date: Wed, 28 Jan 2026 21:28:39 +0100 Subject: [PATCH] added first draft --- .env.example | 20 ++++ docker-compose.yml | 61 ++++++++++ grafana/dashboards/nodered-dashboard.json | 0 grafana/provisioning/dashboards/influxdb.yml | 15 +++ .../provisioning/datasources/dashboards.yml | 9 ++ mosquitto/mosquitto.conf | 11 ++ mosquitto/passwd.template | 0 setup.sh | 112 ++++++++++++++++++ 8 files changed, 228 insertions(+) create mode 100644 .env.example create mode 100644 docker-compose.yml create mode 100644 grafana/dashboards/nodered-dashboard.json create mode 100644 grafana/provisioning/dashboards/influxdb.yml create mode 100644 grafana/provisioning/datasources/dashboards.yml create mode 100644 mosquitto/mosquitto.conf create mode 100644 mosquitto/passwd.template create mode 100644 setup.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f59230f --- /dev/null +++ b/.env.example @@ -0,0 +1,20 @@ +TZ=Europe/Vienna + +INFLUXDB_PORT=8086 +GRAFANA_PORT=3000 +NODERED_PORT=1880 +MQTT_PORT=1883 +MQTT_WS_PORT=9001 + +MQTT_USER=iotuser +MQTT_PASS=strongpassword + +DOCKER_INFLUXDB_INIT_MODE=setup +DOCKER_INFLUXDB_INIT_USERNAME=admin +DOCKER_INFLUXDB_INIT_PASSWORD=supersecret +DOCKER_INFLUXDB_INIT_ORG=homelab +DOCKER_INFLUXDB_INIT_BUCKET=nodered +DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=mysupertoken + +GF_SECURITY_ADMIN_USER=admin +GF_SECURITY_ADMIN_PASSWORD=admin \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c9bb615 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,61 @@ +version: "3.9" + +services: + influxdb: + image: influxdb:2.7 + restart: unless-stopped + ports: + - "${INFLUXDB_PORT}:8086" + volumes: + - influxdb_data:/var/lib/influxdb2 + env_file: .env + + grafana: + image: grafana/grafana:latest + restart: unless-stopped + ports: + - "${GRAFANA_PORT}:3000" + volumes: + - grafana_data:/var/lib/grafana + - ./grafana/provisioning:/etc/grafana/provisioning + - ./grafana/dashboards:/var/lib/grafana/dashboards + env_file: .env + depends_on: [influxdb] + + nodered: + image: nodered/node-red:latest + restart: unless-stopped + ports: + - "${NODERED_PORT}:1880" + volumes: + - nodered_data:/data + env_file: .env + depends_on: [influxdb, mosquitto] + + mosquitto: + image: eclipse-mosquitto:latest + restart: unless-stopped + ports: + - "${MQTT_PORT}:1883" + - "${MQTT_WS_PORT}:9001" + volumes: + - ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf + - ./mosquitto/passwd:/mosquitto/config/passwd + - mosquitto_data:/mosquitto/data + - mosquitto_log:/mosquitto/log + + influxdb-backup: + image: influxdb:2.7 + depends_on: [influxdb] + entrypoint: /bin/sh + command: -c "while true; do sleep 86400; influx backup /backups -t ${DOCKER_INFLUXDB_INIT_ADMIN_TOKEN} -o ${DOCKER_INFLUXDB_INIT_ORG}; done" + volumes: + - influxdb_backups:/backups + +volumes: + influxdb_data: + grafana_data: + nodered_data: + mosquitto_data: + mosquitto_log: + influxdb_backups: \ No newline at end of file diff --git a/grafana/dashboards/nodered-dashboard.json b/grafana/dashboards/nodered-dashboard.json new file mode 100644 index 0000000..e69de29 diff --git a/grafana/provisioning/dashboards/influxdb.yml b/grafana/provisioning/dashboards/influxdb.yml new file mode 100644 index 0000000..28c7ccb --- /dev/null +++ b/grafana/provisioning/dashboards/influxdb.yml @@ -0,0 +1,15 @@ +apiVersion: 1 + +datasources: + - name: InfluxDB + type: influxdb + access: proxy + url: http://influxdb:8086 + jsonData: + version: Flux + organization: ${DOCKER_INFLUXDB_INIT_ORG} + defaultBucket: ${DOCKER_INFLUXDB_INIT_BUCKET} + tlsSkipVerify: true + secureJsonData: + token: ${DOCKER_INFLUXDB_INIT_ADMIN_TOKEN} + isDefault: true \ No newline at end of file diff --git a/grafana/provisioning/datasources/dashboards.yml b/grafana/provisioning/datasources/dashboards.yml new file mode 100644 index 0000000..e25bca0 --- /dev/null +++ b/grafana/provisioning/datasources/dashboards.yml @@ -0,0 +1,9 @@ +apiVersion: 1 + +providers: + - name: "Default" + orgId: 1 + folder: "" + type: file + options: + path: /var/lib/grafana/dashboards \ No newline at end of file diff --git a/mosquitto/mosquitto.conf b/mosquitto/mosquitto.conf new file mode 100644 index 0000000..e6af4af --- /dev/null +++ b/mosquitto/mosquitto.conf @@ -0,0 +1,11 @@ +persistence true +persistence_location /mosquitto/data/ + +listener 1883 +allow_anonymous false +password_file /mosquitto/config/passwd + +listener 9001 +protocol websockets +allow_anonymous false +password_file /mosquitto/config/passwd \ No newline at end of file diff --git a/mosquitto/passwd.template b/mosquitto/passwd.template new file mode 100644 index 0000000..e69de29 diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..77a8792 --- /dev/null +++ b/setup.sh @@ -0,0 +1,112 @@ +#!/bin/bash +set -e + +echo "======================================" +echo " Raspberry Pi Docker IoT Server Setup" +echo "======================================" + +### ---------- HOSTNAME ---------- + +CURRENT_HOSTNAME=$(hostname) +read -p "Hostname setzen? Aktuell '$CURRENT_HOSTNAME' (Enter = behalten): " NEW_HOSTNAME +if [ ! -z "$NEW_HOSTNAME" ]; then +echo "➡ Setze Hostname auf $NEW_HOSTNAME" +echo "$NEW_HOSTNAME" | sudo tee /etc/hostname >/dev/null +sudo sed -i "s/127.0.1.1.*/127.0.1.1 $NEW_HOSTNAME/" /etc/hosts +sudo hostnamectl set-hostname "$NEW_HOSTNAME" +fi + +### ---------- TIMEZONE ---------- + +read -p "Zeitzone setzen? (Default Europe/Berlin) Enter = OK oder z.B. America/New_York: " TZ +TZ=${TZ:-Europe/Berlin} +sudo timedatectl set-timezone "$TZ" +echo "➡ Zeitzone gesetzt auf $TZ" + +### ---------- NETWORK CONFIG ---------- + +read -p "Statische IP konfigurieren? (y/N): " SET_STATIC +if [[ "$SET_STATIC" =~ ^[Yy]$ ]]; then +read -p "IP Adresse (z.B. 192.168.1.50/24): " IPADDR +read -p "Gateway (z.B. 192.168.1.1): " GATEWAY +read -p "DNS Server (z.B. 192.168.1.1 8.8.8.8): " DNS + +echo "➡ Konfiguriere statische IP..." +sudo nmcli con mod "Wired connection 1" ipv4.method manual ipv4.addresses "$IPADDR" ipv4.gateway "$GATEWAY" ipv4.dns "$DNS" +sudo nmcli con up "Wired connection 1" +else +echo "➡ DHCP bleibt aktiv" +fi + +### ---------- SYSTEM UPDATE ---------- + +echo "➡ Systemupdate..." +sudo apt update && sudo apt upgrade -y + +### ---------- DOCKER INSTALL ---------- + +if ! command -v docker &> /dev/null; then +echo "➡ Installiere Docker..." +curl -fsSL [https://get.docker.com](https://get.docker.com) | sh +sudo usermod -aG docker $USER +else +echo "Docker bereits installiert" +fi + +echo "➡ Installiere Docker Compose Plugin..." +sudo apt install docker-compose-plugin -y + +### ---------- FIREWALL ---------- + +echo "➡ Konfiguriere Firewall (UFW)" +sudo apt install ufw -y +sudo ufw default deny incoming +sudo ufw default allow outgoing + +sudo ufw allow 22/tcp +sudo ufw allow 9443/tcp +sudo ufw allow 3000/tcp +sudo ufw allow 1880/tcp +sudo ufw allow 1883/tcp +sudo ufw allow 9001/tcp + +sudo ufw --force enable + +### ---------- PORTAINER ---------- + +echo "➡ Starte Portainer..." +docker volume create portainer_data || true +docker run -d +-p 8000:8000 +-p 9443:9443 +--name portainer +--restart=always +-v /var/run/docker.sock:/var/run/docker.sock +-v portainer_data:/data +portainer/portainer-ce:latest || true + +### ---------- STACK SETUP ---------- + +APP_DIR="$HOME/docker-stack" +REPO_RAW_BASE="[https://raw.githubusercontent.com/DEIN_GITHUB_USER/DEIN_REPO/main](https://raw.githubusercontent.com/DEIN_GITHUB_USER/DEIN_REPO/main)" + +mkdir -p "$APP_DIR" +cd "$APP_DIR" + +echo "➡ Lade Compose & ENV Dateien..." +curl -O "$REPO_RAW_BASE/docker-compose.yml" +curl -o .env "$REPO_RAW_BASE/.env.example" + +echo "➡ Lade Mosquitto Konfiguration..." +mkdir -p mosquitto +curl -o mosquitto/mosquitto.conf "$REPO_RAW_BASE/mosquitto/mosquitto.conf" +curl -o mosquitto/passwd.template "$REPO_RAW_BASE/mosquitto/passwd.template" + +echo "➡ Lade Grafana Provisioning..." +mkdir -p grafana/provisioning/datasources +mkdir -p grafana/provisioning/dashboards +mkdir -p grafana/dashboards + +curl -o grafana/provisioning/datasources/influxdb.yml "$REPO_RAW_BASE/grafana/provisioning/datasources/influxdb.yml" +curl -o grafana/provisioning/dashboards/dashboards.yml "$REPO_RAW_BASE/grafana/provisioning/dashboards/dashboards.yml" +curl -o grafana/dashboards/nodered-dashboard.json "$REPO_RAW_BASE/grafana/dashboar