Files
42_124/CT124_Redash操作手冊_20260622.md
Timmy 0ca0642824 Redash 修復登入 500:DB 卷孤兒化,釘回 bdc790
斷電重建後 postgres 掛到新空匿名卷導致無 schema → 改用具名 external
volume 釘到原始資料卷;手冊「資料卷」段改寫為事故記錄+備份正解。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 22:14:37 +08:00

65 lines
2.8 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CT124 Redash(自架 SQL 查詢/儀表板)— 操作手冊
> 主機:CT124192.168.42.124Ubuntu 24.04 LXC | 位置:`/opt/redash`
> 用途:連各種資料庫,寫 SQL → 視覺化 / 儀表板 / 排程 / 告警
---
## 一、基本資訊
- 版本:**Redash 10.1.0**`redash/redash:10.1.0.b50633`,官方正式版 image
- 設定檔:**`compose.yaml`**(非 `docker-compose.yml`+ `.env`(放 `REDASH_SECRET_KEY` / `REDASH_COOKIE_SECRET`)
- `/opt/redash` 是整包 Redash 原始碼 checkout,但跑的是官方 image,不自行編譯。
- 對外:**僅 LAN**`redash.lotimmy.com``redash.timmy.edu.kg` 皆不解析,`REDASH_HOST=http://localhost:5001`
## 二、容器(6 個)
| 容器 | image | 角色 | Port |
|---|---|---|---|
| `redash-server-1` | redash 10.1.0 | Web/API | `5001 → 5000` |
| `redash-worker-1` | redash 10.1.0 | 查詢/排程執行 worker | — |
| `redash-scheduler-1` | redash 10.1.0 | 排程器 | — |
| `redash-postgres-1` | postgres:15-alpine | metadata DB`trust` 認證,內網) | — |
| `redash-redis-1` | redis:7-alpine | queue / cache | — |
| `redash-email-1` | maildev | 攔截外送信件(告警測試用) | `1025`(SMTP) / `1080`(Web) |
## 三、存取
- Web:`http://192.168.42.124:5001`
- 寄信測試/告警信箱(maildev UI):`http://192.168.42.124:1080`
## 四、操作
```bash
cd /opt/redash
docker compose up -d
docker compose ps
docker compose logs -f server
docker compose restart
# 首次 / 重建 DB schema(myfile.txt 記的就是這條)
docker compose run --rm server create_db
```
## 五、資料卷(重要,曾出事)
- Postgres 資料卷現已**釘到具名 external volume**(2026-06-22 修正):
```yaml
# compose.yaml
postgres:
volumes: [redash_pgdata:/var/lib/postgresql/data]
volumes:
redash_pgdata:
external: true
name: bdc790164a878cda6a5ad9c8ff7f4c08e8b2f79c4682231e0301a523201c3c1a
```
- **歷史事故(2026-06-22,登入 500)**:原本 postgres 用**匿名 volume**,五月斷電後 docker 重建時 compose 開了**新的空匿名卷**,把有資料的 `bdc790` 孤兒化 → DB 無 `organizations` 表 → `/login` 500。修法:找回 `bdc790` 並用上面的 external volume 釘死。
- 孤兒空卷 `2f327adc…`、`00b892ea…`(PG15 空庫)可清:`docker volume rm <hash>`(確認沒用到再刪)。
- **備份**(資料仍只在 docker volume,不在 `/opt/redash`):
```bash
docker exec redash-postgres-1 pg_dump -U postgres postgres > redash-$(date +%F).sql
```
- ⚠️ `docker compose down -v` 會刪卷;`external: true` 的卷 compose 不會自動刪,稍安全,但仍別亂下 `-v`。
- Postgres 用 `POSTGRES_HOST_AUTH_METHOD=trust`(無密碼),但**未對外開 port**,僅 docker 內網,風險可控。
- 殘留檔:`compose.yaml_BACKUP_*`、`myfile.txt` 為安裝暫存,可留可刪。