Influxdb docker replication
This commit is contained in:
108
README.md
108
README.md
@@ -25,12 +25,108 @@ sudo systemctl status towerd
|
||||
sudo journalctl -u towerd -f
|
||||
```
|
||||
|
||||
## Config
|
||||
## Metrics
|
||||
|
||||
Edit in `/etc/towerd/env`
|
||||
Originally I was going to write to my influxdb server over the network but I learned that influxdb can be configured
|
||||
to save locally and drain when network is up, which would be pretty awesome for edge computing like the tower. So,
|
||||
new architecture is to run locally and configure it to replicate.
|
||||
|
||||
### Local Config
|
||||
|
||||
Create `/opt/towerd/.env`
|
||||
|
||||
```shell
|
||||
INFLUXDB_INIT_PASSWORD=change-me
|
||||
INFLUXDB_INIT_ADMIN_TOKEN=change-me-to-a-long-random-token
|
||||
INFLUXDB_INIT_ORG=tower
|
||||
INFLUXDB_INIT_BUCKET=tower
|
||||
```
|
||||
TOWERD_INFLUX_TOKEN=<token>
|
||||
TOWERD_INFLUX_ORG=<org>
|
||||
TOWERD_INFLUX_BUCKET=<xyz>
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```shell
|
||||
cd /opt/towerd
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
Init vars only matter once
|
||||
|
||||
InfluxDB listens on `127.0.0.1:8086` only.
|
||||
|
||||
### Configure towerd
|
||||
|
||||
Create `/etc/towerd/env`:
|
||||
|
||||
```shell
|
||||
TOWERD_INFLUX_URL=http://127.0.0.1:8086
|
||||
TOWERD_INFLUX_ORG=tower
|
||||
TOWERD_INFLUX_BUCKET=tower
|
||||
TOWERD_INFLUX_TOKEN=<same as INFLUXDB_INIT_ADMIN_TOKEN>
|
||||
TOWERD_INFLUX_HOST=kw1fox-1
|
||||
|
||||
# optional
|
||||
# TOWERD_INFLUX_INTERVAL_S=30
|
||||
```
|
||||
|
||||
Restart towerd after editing:
|
||||
|
||||
```shell
|
||||
sudo systemctl restart towerd
|
||||
```
|
||||
|
||||
### Replicate to remote InfluxDB
|
||||
|
||||
Need influx cli
|
||||
|
||||
```shell
|
||||
# register the remote server
|
||||
influx remote create \
|
||||
--host http://127.0.0.1:8086 \
|
||||
--token "$TOWERD_INFLUX_TOKEN" \
|
||||
--name kitsune-remote \
|
||||
--remote-url http://influx.kitsunehosting.net:8086 \
|
||||
--remote-api-token <remote-write-token> \
|
||||
--remote-org-id <remote-org-id>
|
||||
|
||||
# list remotes to get the ID from the previous step
|
||||
influx remote list \
|
||||
--host http://127.0.0.1:8086 \
|
||||
--token "$TOWERD_INFLUX_TOKEN"
|
||||
|
||||
# replicate the local bucket to the remote bucket
|
||||
influx replication create \
|
||||
--host http://127.0.0.1:8086 \
|
||||
--token "$TOWERD_INFLUX_TOKEN" \
|
||||
--name tower-to-kitsune \
|
||||
--remote-id <remote-id> \
|
||||
--local-bucket-id <local-bucket-id> \
|
||||
--remote-bucket <remote-bucket-name>
|
||||
```
|
||||
|
||||
Find the local bucket ID:
|
||||
|
||||
```shell
|
||||
influx bucket list \
|
||||
--host http://127.0.0.1:8086 \
|
||||
--token "$TOWERD_INFLUX_TOKEN"
|
||||
```
|
||||
|
||||
Check replication queue health:
|
||||
|
||||
```shell
|
||||
influx replication list \
|
||||
--host http://127.0.0.1:8086 \
|
||||
--token "$TOWERD_INFLUX_TOKEN"
|
||||
```
|
||||
|
||||
## systemd
|
||||
|
||||
`towerd` loads `/etc/towerd/env` via `EnvironmentFile`. If using Docker for InfluxDB, ensure Docker starts before towerd:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
After=docker.service
|
||||
Wants=docker.service
|
||||
```
|
||||
|
||||
Add those lines to `/etc/systemd/system/towerd.service` under `[Unit]`.
|
||||
|
||||
18
docker-compose.yml
Normal file
18
docker-compose.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
services:
|
||||
influxdb:
|
||||
image: influxdb:2.7
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "127.0.0.1:8086:8086"
|
||||
volumes:
|
||||
- influx-data:/var/lib/influxdb2
|
||||
environment:
|
||||
DOCKER_INFLUXDB_INIT_MODE: setup
|
||||
DOCKER_INFLUXDB_INIT_USERNAME: admin
|
||||
DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_INIT_PASSWORD}
|
||||
DOCKER_INFLUXDB_INIT_ORG: ${INFLUXDB_INIT_ORG:-tower}
|
||||
DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUXDB_INIT_BUCKET:-tower}
|
||||
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUXDB_INIT_ADMIN_TOKEN}
|
||||
|
||||
volumes:
|
||||
influx-data:
|
||||
@@ -41,7 +41,7 @@ impl InfluxConfig {
|
||||
|
||||
Some(Self {
|
||||
url: std::env::var("TOWERD_INFLUX_URL")
|
||||
.unwrap_or_else(|_| "http://influx.kitsunehosting.net:8086".into()),
|
||||
.unwrap_or_else(|_| "http://127.0.0.1:8086".into()),
|
||||
org,
|
||||
bucket,
|
||||
token,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[Unit]
|
||||
Description=Tower Daemon
|
||||
After=multi-user.target
|
||||
After=multi-user.target docker.service
|
||||
Wants=docker.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
|
||||
Reference in New Issue
Block a user