Skip to main content

部署指南 / Deployment Guide

生产构建 / Production Build​

在仓库根目录构建服务端、管理工具和带 RocksDB 的 KV 示例。rr-server 内置的是 Echo 冒烟服务;真实业务应嵌入 Rr crates, 或参考 examples/kv-store 构建自己的二进制。

Build the server, admin CLI, and RocksDB-enabled KV example from the repository root. The stock rr-server contains an Echo smoke service; embed the Rr crates for real application logic, using examples/kv-store as the reference.

cargo build --release -p rr-server -p rr-admin --features rr-server/rocks
cargo build --release -p kv-store --features rocks

二进制位于 target/release/。kv-store --data-dir 只在带 rocks 特性的构建中可用。

Binaries are written to target/release/. kv-store --data-dir requires a build with the rocks feature.

节点配置 / Node Configuration​

生产节点使用 rocks 和 strict,为数据、Admin、指标分别设置地址。启用 Admin 时必须同时配置 TLS、mTLS 和 Admin token; 以下片段不包含完整 TLS 字段,按 TLS 指南 补齐后再启动。

Use rocks with strict in production and configure data, Admin, and metrics addresses explicitly. An enabled Admin service also requires TLS, mTLS, and an Admin token. Complete the TLS fields in the following fragment with the TLS guide before starting the node.

[node]
id = 1
listen_addr = "0.0.0.0:51001"
data_dir = "/var/lib/rr/data"
admin_port = 52001
admin_bind_host = "0.0.0.0"
metrics_port = 9100
metrics_bind_host = "0.0.0.0"

[storage]
backend = "rocks"
durability = "strict"

[auth]
admin_token_env = "RR_ADMIN_TOKEN"

Admin 和未认证的指标端点只向运维网络开放;不要把它们直接暴露到公网。配置优先级为 CLI > 环境变量 > TOML > 默认值。

Expose Admin and the unauthenticated metrics endpoint only to the operations network, never directly to the public internet. Configuration precedence is CLI > environment > TOML > defaults.

启动三节点 KV 集群 / Start a Three-Node KV Cluster​

这是 kv-store 的手动组建流程,不是通用的在线加节点流程。三个节点必须使用相同的完整花名册,格式为 id@advertised_addr ,且必须包含本节点。只在节点 1 上使用一次 --bootstrap;它会直接把花名册中的三个节点初始化为 voter。其他节点不要逐个“加 入”,也不要再执行 bootstrap。

This is the kv-store manual formation flow, not a generic online node-join flow. All nodes must use the same complete id@advertised_addr roster, including themselves. Use --bootstrap once, on node 1 only; it initializes all three roster entries as voters. Do not bootstrap the other nodes or treat them as incremental joins.

无参数 kv-store demo 会自行初始化单副本组;常驻的手动单节点服务只在全新建组时引导一次。 Genesis、Adopt、正常重启以及已初始化或 durable 节点恢复都不使用 --bootstrap。 重复初始化即使因组已存在而成为 no-op,也不是重启或成员变更策略。本次 gRPC Pre-Vote 故障并非 --bootstrap 导致,不要用它处理选主、网络隔离或 Pre-Vote 问题。

The no-argument kv-store demo initializes its own single-replica group. A persistent manual single-node service bootstraps once when its fresh group is created. Genesis, Adopt, normal restarts, and already initialized or durable-node recovery do not use --bootstrap. Repeating initialization may be a no-op when the group exists, but it is not a restart or membership-change strategy. The gRPC Pre-Vote failure addressed here was not caused by --bootstrap; do not use it to address election, network-isolation, or Pre-Vote failures.

前提:三个节点已配置符合 SAN 的证书,且环境中均有非空的 RR_ADMIN_TOKEN 和 RR_CLIENT_TOKEN。kv-store 的 Admin 端口 始终是 --port + 1000。

Prerequisites: every node has a certificate with the correct SANs, and non-empty RR_ADMIN_TOKEN and RR_CLIENT_TOKEN are present in its environment. The kv-store Admin port is always --port + 1000.

# 节点 1 / node 1
./target/release/kv-store --node-id 1 --listen-addr 0.0.0.0 --port 51001 \
--data-dir /var/lib/rr/data --bootstrap \
--peers 1@192.168.1.1:51001,2@192.168.1.2:51001,3@192.168.1.3:51001 \
--tls-cert /etc/rr/tls/node1.pem --tls-key /etc/rr/tls/node1.key --tls-ca /etc/rr/tls/ca.pem

# 节点 2 / node 2
./target/release/kv-store --node-id 2 --listen-addr 0.0.0.0 --port 51001 \
--data-dir /var/lib/rr/data \
--peers 1@192.168.1.1:51001,2@192.168.1.2:51001,3@192.168.1.3:51001 \
--tls-cert /etc/rr/tls/node2.pem --tls-key /etc/rr/tls/node2.key --tls-ca /etc/rr/tls/ca.pem

# 节点 3 / node 3
./target/release/kv-store --node-id 3 --listen-addr 0.0.0.0 --port 51001 \
--data-dir /var/lib/rr/data \
--peers 1@192.168.1.1:51001,2@192.168.1.2:51001,3@192.168.1.3:51001 \
--tls-cert /etc/rr/tls/node3.pem --tls-key /etc/rr/tls/node3.key --tls-ca /etc/rr/tls/ca.pem

--listen-addr 只决定绑定地址,其他节点拨入的地址来自花名册。不要复用 rr-server --peers 的旧语义:stock server 的该参 数仅用于推导本地初始路由表,并按列表顺序猜测节点 ID;多节点应使用显式托管花名册或外部 ConfigProvider。

--listen-addr controls binding only; peers dial the advertised roster addresses. Do not carry this syntax over to rr-server --peers: the stock server uses that option only to size its local initial routing table and guesses IDs by list order. Use an explicit managed roster or an external ConfigProvider for real multi-node topologies.

stock rr-server --bootstrap 只把本地托管的每个组初始化为仅含当前节点的单 voter 组, 不同于 kv-store 的全花名册初始化;其 Echo 服务也不提供 KV 语义。

Stock rr-server --bootstrap initializes each locally hosted group with only the current node as its single voter. This differs from kv-store full-roster initialization, and the stock Echo service does not provide KV semantics.

托管 Genesis 改用相同的 cluster.name、cluster.nodes 和 [cluster.formation],不设置 bootstrap,也不使用旧 peers 列表。已有集群必须使用 adopt,不能用 Genesis 重建。完整流程见 Kubernetes 部署 和 升级指南。

Managed Genesis instead uses identical cluster.name, cluster.nodes, and [cluster.formation] settings, with neither bootstrap nor the legacy peers list. Existing clusters must use adopt, never a fresh Genesis. See Kubernetes Deployment and Upgrading.

验证 leader、日志推进和成员关系;安全模式下 rr-admin 必须显式携带 TLS 和 token 环境变量名。

Verify the leader, log progress, and membership. In secure mode, pass TLS paths and the token environment-variable name to rr-admin explicitly.

rr-admin --addr 192.168.1.1:52001 --token-env RR_ADMIN_TOKEN \
--tls-ca /etc/rr/tls/ca.pem --tls-cert /etc/rr/tls/client.pem --tls-key /etc/rr/tls/client.key \
group status --group 1
rr-admin --addr 192.168.1.1:52001 --token-env RR_ADMIN_TOKEN \
--tls-ca /etc/rr/tls/ca.pem --tls-cert /etc/rr/tls/client.pem --tls-key /etc/rr/tls/client.key \
group membership --group 1

若节点一直未选出 leader,先检查三个地址和端口是否互通、花名册是否逐字一致、证书 SAN 与 CA 是否匹配,再检查是否误在多个节 点执行了 bootstrap。

If no leader emerges, check address/port reachability, byte-for-byte roster agreement, certificate SANs and CA trust, then check whether more than one node was bootstrapped.

快照与持久化 / Snapshots and Persistence​

快照按 SnapshotPolicy::LogsSinceLast(N) 自动构建,默认阈值为 50,000 条日志,可用 --snapshot-logs-since-last 或 RR_SNAPSHOT_LOGS_SINCE_LAST 调整。Rocks 模式会把每组快照原子写入 {data_dir}/raft-log/{group_id}/sm-snapshot.bin,重 启后先恢复快照,再重放剩余日志。Mem 模式的日志和快照都只在内存中,进程重启即丢失。

Snapshots use SnapshotPolicy::LogsSinceLast(N), with a default threshold of 50,000 entries; override it with --snapshot-logs-since-last or RR_SNAPSHOT_LOGS_SINCE_LAST. In Rocks mode, each group's snapshot is atomically persisted to {data_dir}/raft-log/{group_id}/sm-snapshot.bin; startup restores it before replaying the remaining log. In Mem mode, both log and snapshot are memory-only and lost on restart.

框架持久化的是 Service::snapshot() 产生的字节,不替代业务级备份。kv-store 的业务 map 虽在内存中维护,但 Rocks 模式可 通过已持久化快照和日志重建。

The framework persists the bytes returned by Service::snapshot(); this is not a substitute for business-level backups. Although kv-store keeps its working map in memory, Rocks mode can rebuild it from the persisted snapshot and log.

备份与恢复 / Backup and Restore​

整目录备份必须离线执行。先 drain、正常停止节点,再备份;输出不能位于 data_dir 内,也不能覆盖已有文件。

Whole-directory backup is offline only. Drain and stop the node gracefully before archiving. The output must be outside data_dir and must not already exist.

mkdir -p /var/backups/rr
rr-admin --addr 127.0.0.1:52001 --token-env RR_ADMIN_TOKEN \
--tls-ca /etc/rr/tls/ca.pem --tls-cert /etc/rr/tls/client.pem --tls-key /etc/rr/tls/client.key \
node drain --node-id 1
# 正常停止 rr-server / stop rr-server gracefully, then run:
rr-admin backup --data-dir /var/lib/rr/data --output /var/backups/rr/node1-$(date +%F).tar.gz --node-id 1
rr-admin inspect-backup --input /var/backups/rr/node1-$(date +%F).tar.gz

恢复时节点必须停止,目标目录必须为空或不存在。工具先解包到同文件系统的临时目录并校验 SHA-256,再原子改名;不要手工覆盖非 空目录。

For restore, stop the node and use an empty or absent target directory. The tool verifies SHA-256 in a sibling temporary directory before an atomic rename; never overwrite a non-empty directory manually.

rr-admin restore --input /var/backups/rr/node1-2026-11-14.tar.gz --data-dir /var/lib/rr/data

恢复后启动该节点并检查快照、日志追平和成员关系。不要把单节点旧备份当成整集群时间点恢复,也不要在仍有 quorum 时同时回滚多 个节点;多数派状态丢失需要单独的灾难恢复方案。

After restore, start the node and verify snapshots, log catch-up, and membership. A single node's old archive is not a cluster-wide point-in-time restore. Do not roll back multiple nodes while a healthy quorum exists; majority state loss requires a separate disaster-recovery procedure.

运行中可按组导出快照,但它不是 rr-admin restore 可读取的 tar 包,恢复需要应用自己的导入流程:

A running node can export one group's snapshot. This binary snapshot is not a tar archive accepted by rr-admin restore; importing it requires an application-specific procedure.

rr-admin --addr 192.168.1.1:52001 --token-env RR_ADMIN_TOKEN \
--tls-ca /etc/rr/tls/ca.pem --tls-cert /etc/rr/tls/client.pem --tls-key /etc/rr/tls/client.key \
group online-backup --group 1 --output /var/backups/rr/group-1.snapshot --force-fresh

添加节点 / Add a Node​

以下流程只适用于支持动态成员的 legacy 部署。先让 ConfigProvider 包含新节点地址并启动一个空节点,再在当前 leader 上添加 learner。默认 auto_promote_learners = true 会在追平后提升 voter;若显式关闭,则手工指定完整目标 voter 集合。

This flow applies only to legacy deployments that support dynamic membership. Add the new node's address to the ConfigProvider and start the empty node, then add a learner on the current leader. By default auto_promote_learners = true promotes a caught-up learner; if disabled, set the complete target voter list manually.

rr-admin --addr 192.168.1.1:52001 --token-env RR_ADMIN_TOKEN \
--tls-ca /etc/rr/tls/ca.pem --tls-cert /etc/rr/tls/client.pem --tls-key /etc/rr/tls/client.key \
group add-learner --group 1 --node-id 4 --addr 192.168.1.4:51001
rr-admin --addr 192.168.1.1:52001 --token-env RR_ADMIN_TOKEN \
--tls-ca /etc/rr/tls/ca.pem --tls-cert /etc/rr/tls/client.pem --tls-key /etc/rr/tls/client.key \
group change-membership --group 1 --voters 1,2,3,4

验证 group membership、路由表和 /ready。Managed formation P1 不支持动态扩容或副本替换;不要通过修改 SeedSpec 或 replicaCount 模拟加节点。

Verify group membership, the routing table, and /ready. Managed formation P1 does not support dynamic expansion or replica replacement; do not emulate node addition by changing SeedSpec or replicaCount.

移除节点 / Remove a Node​

先预检,再从所有组移除节点,最后更新路由配置并停止进程。不要在改 Raft membership 之前先从 ConfigProvider 删除地址,否则 编排工具可能无法拨到目标或 leader。

Run a dry run, remove the node from every group, then update routing configuration and stop the process. Do not delete its address from the ConfigProvider before the Raft change; the orchestrator may still need to reach the target or leader.

rr-admin --addr 192.168.1.1:52001 --token-env RR_ADMIN_TOKEN \
--tls-ca /etc/rr/tls/ca.pem --tls-cert /etc/rr/tls/client.pem --tls-key /etc/rr/tls/client.key \
node decommission --node-id 3 --dry-run
rr-admin --addr 192.168.1.1:52001 --token-env RR_ADMIN_TOKEN \
--tls-ca /etc/rr/tls/ca.pem --tls-cert /etc/rr/tls/client.pem --tls-key /etc/rr/tls/client.key \
node decommission --node-id 3

命令失败或报告 coverage gap 时不要停节点,应在承载对应组的节点或 leader 上重跑。服务端默认拒绝缩到少于 2 个 voter; --force 仅限灾难恢复。Managed P1 不支持此运行时缩容流程。

If the command fails or reports a coverage gap, do not stop the node; rerun it against a node hosting that group or its leader. The server rejects a result with fewer than two voters by default; --force is reserved for disaster recovery. Managed P1 does not support this runtime shrink flow.

监控与网络 / Monitoring and Network​

使用 RUST_LOG 控制结构化日志,通过 rr-admin group status、group snapshot-status 和 Prometheus 指标观察 leader、日 志与快照。指标语义见 指标参考,持久化细节见 持久化与恢复。

Use RUST_LOG for structured logs and inspect leader, log, and snapshot state through rr-admin group status, group snapshot-status, and Prometheus. See Metrics Reference and Durability & Recovery.

节点间必须能访问配置的 Client/Raft gRPC 地址;Admin 和 metrics 使用独立端口。保持低延迟、稳定拓扑,并监控 rr_channel_reconnects_total。当前心跳为 50ms、选举超时为 150–300ms,高延迟链路会导致反复选举。

Peers must reach the configured Client/Raft gRPC addresses; Admin and metrics use separate ports. Keep latency low and topology stable, and monitor rr_channel_reconnects_total. The current heartbeat is 50ms and election timeout is 150– 300ms; high-latency links can cause repeated elections.

可选只读 Console / Optional Read-Only Console​

rr-admin console 是可选的只读观察组件,与 Admin CLI/REPL 同属一个 Rust 二进制,不是必须随集群启动的 Raft 控制面。停止 Console 不影响 Raft 节点;membership、选主、快照、drain 等受控写操作仍使用 Admin CLI。

rr-admin console is an optional read-only observer in the same Rust binary as the Admin CLI/REPL, not a Raft control plane that every cluster must run. Stopping it does not affect Raft nodes; controlled writes such as membership, leadership, snapshot, and drain operations remain with the Admin CLI.

完整浏览器 UI 需要先静态导出前端。Node.js 和 pnpm 只参与构建,生产环境不需要独立 Node.js 服务:

Build the full browser UI as a static export first. Node.js and pnpm are build-time-only dependencies; production needs no standalone Node.js service:

pnpm --dir crates/rr-admin/console install --frozen-lockfile
pnpm --dir crates/rr-admin/console run build

将 target/release/rr-admin 和 crates/rr-admin/console/out/ 一起部署,例如把导出内容复制到 /opt/rr/console,再用 --static-dir /opt/rr/console 指向它。默认静态目录面向源码树,不能只复制二进制后 就假定部署机上存在前端产物。

Ship target/release/rr-admin together with crates/rr-admin/console/out/; for example, copy the export to /opt/rr/console and pass --static-dir /opt/rr/console. The default static directory is source-tree-oriented, so copying only the binary does not deploy the frontend.

非 loopback 生产监听必须同时启用 Console HTTPS 和 viewer token。独立模式不需要启动时提供任何集群来源或 Admin 凭证;--state-dir 指向由 Console 运行用户独占的持久配置目录。子命令后的 TLS 参数只保护

Browser→Console HTTPS:

A non-loopback production listener requires both Console HTTPS and a viewer token. Standalone mode needs no cluster source or Admin credential at startup. Point --state-dir at persistent storage exclusively writable by the Console user. TLS flags after the subcommand protect only browser-to-Console HTTPS:

export RR_CONSOLE_TOKEN='<viewer-token-from-your-secret-store>'

./target/release/rr-admin console \
--listen 0.0.0.0:8443 \
--console-token-env RR_CONSOLE_TOKEN \
--tls-cert /etc/rr/tls/console.pem \
--tls-key /etc/rr/tls/console.key \
--static-dir /opt/rr/console \
--state-dir /var/lib/rr-console

部署后打开 /connections/,为每个目标集群分别填写 Admin seeds/discovery、Admin TLS/token、discovery TLS/auth 和可选 Prometheus。无来源启动没有 Admin/metrics 网络流量;只有显式 Connect 的 runtime 开始采集,最多同时活跃 8 个。旧 --peers/--discovery、全局 Admin TLS/token 和进程级 Prometheus 参数仍用于单个临时启动连接,具体 参数位置和示例见 TLS 指南;新部署通常使用保存连接。

Open /connections/ after deployment and configure each target's Admin seeds/discovery, Admin TLS/token, discovery TLS/auth, and optional Prometheus independently. No-source startup produces no Admin/metrics traffic; only explicitly connected runtimes collect, with at most eight active at once. Legacy --peers/--discovery, global Admin TLS/token, and process-level Prometheus flags still create one ephemeral startup connection; see the TLS guide for flag position and examples. New deployments normally use saved connections.

节点 Admin token 只保留在 BFF。Console 经 Admin gRPC 取得受信描述符,再从描述符的 observability_addr 通过 HTTP 抓取 /health、/ready 和 /metrics;BFF 必须能访问这些观测端口。仅启用 Admin/metrics 端口并不 足够:stock rr-server 必须在 [node] 中完整配置 advertise_addr、admin_advertise_addr、 observability_advertise_addr 和 environment,字段语义见 NodeDirectory 自注册。缺少描述符时仍可使用 Admin-backed 视图,但健康探测和实时指标按能力降级。当前节点指标端点可能未认证,只向受信运维网络开放,不要 暴露到公网。

The node Admin token remains inside the BFF. The Console obtains a trusted descriptor over Admin gRPC, then scrapes /health, /ready, and /metrics over HTTP from its observability_addr; the BFF needs network access to this observability endpoint. Enabling Admin and metrics ports alone is insufficient: stock rr-server must configure all of advertise_addr, admin_advertise_addr, observability_advertise_addr, and environment in [node]. See NodeDirectory self-registration for their semantics. Without a descriptor, Admin-backed views remain available but health probes and live metrics degrade by capability. Node metrics endpoints may be unauthenticated, so expose them only to the trusted operations network, never publicly.

实时趋势默认只保存在 BFF 的有界内存中,重启即清空。需要历史时可成对添加 --prometheus-url http://prometheus.internal:9090 和 --prometheus-cluster cluster_id=prod-rr;Prometheus 是 可选历史后端,只提供固定 raw-family 模板,不是 Raft 集群或 Console 的必需依赖,也不开放任意 PromQL。 etcd 发现、session 语义和完整故障排查见 集群管理控制台手册。

Live trends are retained only in bounded BFF memory and are cleared on restart. For history, optionally add both --prometheus-url http://prometheus.internal:9090 and --prometheus-cluster cluster_id=prod-rr. Prometheus is an optional history backend with fixed raw-family templates, not a requirement for the Raft cluster or Console, and it does not expose arbitrary PromQL. See the Cluster Admin Console manual for etcd discovery, session semantics, and complete troubleshooting.