> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memorose.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 分布式部署

> 基于 Raft 的集群、本地集群搭建与集群管理。

# 分布式部署（Distributed Deployment）

Memorose 支持基于 Raft 的复制部署，并可通过项目脚本以集群形式在本地启动。

## 推荐的本地集群启动方式

```bash theme={null}
./scripts/start_cluster.sh start --clean --build
```

典型的本地拓扑：

* 后端节点运行在 `3000`、`3001`、`3002` 端口
* 仪表盘 UI 运行在 `3100` 端口

## 集群管理端点

* `POST /v1/cluster/initialize`
* `POST /v1/cluster/join`
* `DELETE /v1/cluster/nodes/:node_id`

## 加入集群的请求体

```json theme={null}
{
  "node_id": 2,
  "address": "127.0.0.1:5002"
}
```

## 初始化示例

```bash theme={null}
curl -s -X POST http://127.0.0.1:3000/v1/cluster/initialize \
  -H "Authorization: Bearer $TOKEN"
```

## 加入集群示例

```bash theme={null}
curl -s -X POST http://127.0.0.1:3000/v1/cluster/join \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "node_id": 2,
    "address": "127.0.0.1:5002"
  }'
```

## 运维说明

* 在单节点模式下，加入和离开操作作用于本地 Raft 组。
* 在分片模式（Sharded Mode）下，集群操作会扇出到各分片组。
* 写入路径内置了 Leader 转发机制，但集群运维控制仍需要健康的 Raft 拓扑。
