一台伺服器足夠大多數團隊使用。只有兩種情況需要加機器:伺服器故障時 MOF 也不能停,或雲端帳號多到同步一直排隊。
每個程序的角色
| 角色 | 設定 | 處理網頁 | 執行同步 |
|---|---|---|---|
| 完整 MOF | 不用設定(預設) | 是 | 是 |
| Worker | RK_CONFIG_0_CONTENT_MODE_WORKER=true | 否 | 是 |
| 僅處理網頁 | RK_CONFIG_0_CONTENT_MODE_WEB=true | 是 | 否 |
在 Admin → 系統 → MOF 程序 中可以看到每個執行中的程序及其角色。
高可用性
- 每台伺服器都使用「外部 PostgreSQL」版 compose.yaml,填同一個資料庫。
- 先啟動一台,從它的日誌取得 Admin 密碼,再啟動其他幾台。
- 負載平衡器轉送到每台的 80 連接埠,並以主動健康檢查
/v1/mof/site-info,每隔幾秒一次。
健康檢查會經過 Dash 到 MOF,哪台的 MOF 停了就會回傳 502,被負載平衡器移除。若只做被動偵測,故障後的第一個請求要等逾時才會轉到別的伺服器。
各台的映像檔版本要一致;使用瀏覽器 OAuth 的話,MOF_PUBLIC_URL 和 MOF_MCP_OAUTH_SECRET 也要一致。登入金鑰、加密金鑰和 License 存在資料庫裡,不用處理。
在 Kubernetes 上,MOF、MCP、Dash 是各自的 Deployment,直接增加副本:kubectl -n mof scale deployment/mof deployment/dash --replicas=2。升級時仍會短暫停止所有 MOF Pod(strategy 為 Recreate),確保各副本版本一致。
增加 Worker
資料庫和 MOF 版本與主部署一致。Worker 不需要開放連接埠。
下載 compose.yaml
Docker Hub · MOF v2.0.15
下載 compose.yaml ↓檢視檔案和映像檔
# MOF v2.0.15 — Linux amd64 / dockerhub
# Use the same database connection and MOF version as the main deployment.
# Private-network PostgreSQL without TLS. TLS-only databases are not supported by this release.
name: mof-worker
x-logging: &logging
driver: json-file
options:
max-size: "20m"
max-file: "5"
services:
mof-worker:
image: mofcloud/mof:v2.0.15
restart: unless-stopped
logging: *logging
environment:
RK_POSTGRES_0_ADDR: "db.example.com:5432"
RK_POSTGRES_0_USER: "mof"
RK_POSTGRES_0_PASS: "REPLACE_WITH_YOUR_DATABASE_PASSWORD"
RK_CONFIG_0_CONTENT_MODE_WORKER: "true"
# Optional, default 2: jobs run at the same time in this process, for syncs (bills,
# resources, exports) and ops (delete an account, purge bills, apply a virtual tag filter).
# RK_CONFIG_0_CONTENT_JOBS_SYNCWORKERS: "2"
# RK_CONFIG_0_CONTENT_JOBS_OPSWORKERS: "2"
volumes:
- offer-cache:/usr/src/mof/offer-cache
volumes:
offer-cache:
mofcloud/mof:v2.0.15阿里雲 ACR · MOF v2.0.15
下載 compose.yaml ↓檢視檔案和映像檔
# MOF v2.0.15 — Linux amd64 / acr
# Use the same database connection and MOF version as the main deployment.
# Private-network PostgreSQL without TLS. TLS-only databases are not supported by this release.
name: mof-worker
x-logging: &logging
driver: json-file
options:
max-size: "20m"
max-file: "5"
services:
mof-worker:
image: registry.cn-hangzhou.aliyuncs.com/mofcloud/mof:v2.0.15
restart: unless-stopped
logging: *logging
environment:
RK_POSTGRES_0_ADDR: "db.example.com:5432"
RK_POSTGRES_0_USER: "mof"
RK_POSTGRES_0_PASS: "REPLACE_WITH_YOUR_DATABASE_PASSWORD"
RK_CONFIG_0_CONTENT_MODE_WORKER: "true"
# Optional, default 2: jobs run at the same time in this process, for syncs (bills,
# resources, exports) and ops (delete an account, purge bills, apply a virtual tag filter).
# RK_CONFIG_0_CONTENT_JOBS_SYNCWORKERS: "2"
# RK_CONFIG_0_CONTENT_JOBS_OPSWORKERS: "2"
volumes:
- offer-cache:/usr/src/mof/offer-cache
volumes:
offer-cache:
registry.cn-hangzhou.aliyuncs.com/mofcloud/mof:v2.0.15GHCR · MOF v2.0.15
下載 compose.yaml ↓檢視檔案和映像檔
# MOF v2.0.15 — Linux amd64 / ghcr
# Use the same database connection and MOF version as the main deployment.
# Private-network PostgreSQL without TLS. TLS-only databases are not supported by this release.
name: mof-worker
x-logging: &logging
driver: json-file
options:
max-size: "20m"
max-file: "5"
services:
mof-worker:
image: ghcr.io/mofcloud/mof:v2.0.15
restart: unless-stopped
logging: *logging
environment:
RK_POSTGRES_0_ADDR: "db.example.com:5432"
RK_POSTGRES_0_USER: "mof"
RK_POSTGRES_0_PASS: "REPLACE_WITH_YOUR_DATABASE_PASSWORD"
RK_CONFIG_0_CONTENT_MODE_WORKER: "true"
# Optional, default 2: jobs run at the same time in this process, for syncs (bills,
# resources, exports) and ops (delete an account, purge bills, apply a virtual tag filter).
# RK_CONFIG_0_CONTENT_JOBS_SYNCWORKERS: "2"
# RK_CONFIG_0_CONTENT_JOBS_OPSWORKERS: "2"
volumes:
- offer-cache:/usr/src/mof/offer-cache
volumes:
offer-cache:
ghcr.io/mofcloud/mof:v2.0.15資料庫連線
在 compose.yaml 裡填寫與主部署相同的資料庫連線:
RK_POSTGRES_0_ADDR- 位址:連接埠
RK_POSTGRES_0_USER- 使用者名稱
RK_POSTGRES_0_PASS- 密碼
既有資料與資料庫權限
使用者需具備登入和 CREATEDB 權限。修改位址不會遷移資料或重設密碼,切換資料庫前需另行備份還原。
啟動
docker compose config --quiet
docker compose up -d
docker compose ps在這台機器上增加 Worker 數量:
docker compose up -d --scale mof-worker=3
docker compose logs --tail=100 mof-worker每個 Worker 預設同時執行 2 個同步工作(帳單、資源、匯出)和 2 個操作工作(刪除帳號、清除帳單、套用虛擬標籤)。機器記憶體有餘裕時,可在 compose.yaml 中取消註解並調高 RK_CONFIG_0_CONTENT_JOBS_SYNCWORKERS;RK_CONFIG_0_CONTENT_JOBS_OPSWORKERS 控制操作工作。