一台服务器够大多数团队用。只有两种情况需要加机器:服务器出问题时 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 控制操作任务。