added first draft
This commit is contained in:
20
.env.example
Normal file
20
.env.example
Normal file
@@ -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
|
||||
61
docker-compose.yml
Normal file
61
docker-compose.yml
Normal file
@@ -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:
|
||||
0
grafana/dashboards/nodered-dashboard.json
Normal file
0
grafana/dashboards/nodered-dashboard.json
Normal file
15
grafana/provisioning/dashboards/influxdb.yml
Normal file
15
grafana/provisioning/dashboards/influxdb.yml
Normal file
@@ -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
|
||||
9
grafana/provisioning/datasources/dashboards.yml
Normal file
9
grafana/provisioning/datasources/dashboards.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: "Default"
|
||||
orgId: 1
|
||||
folder: ""
|
||||
type: file
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
11
mosquitto/mosquitto.conf
Normal file
11
mosquitto/mosquitto.conf
Normal file
@@ -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
|
||||
0
mosquitto/passwd.template
Normal file
0
mosquitto/passwd.template
Normal file
112
setup.sh
Normal file
112
setup.sh
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user