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

# 多個閘道

大多數設定只需要一個閘道——單一閘道即可處理多個訊息連線與代理程式。只有在需要更強的隔離或備援時（例如救援機器人），才應使用隔離的設定檔／連接埠執行個別閘道。

## 救援機器人快速入門

最簡單的救援機器人設定：

* 讓主要機器人使用預設設定檔。
* 使用 `--profile rescue` 執行救援機器人，並使用它自己的 Telegram 機器人權杖。
* 為救援機器人使用不同的基礎連接埠，例如 `19789`。

如此一來，即使主要機器人停止運作，救援機器人仍可進行偵錯或套用設定變更。基礎連接埠之間至少保留 20 個連接埠，確保衍生的瀏覽器／CDP 連接埠絕不會衝突。

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# 救援機器人（獨立的 Telegram 機器人、獨立設定檔、連接埠 19789）
openclaw --profile rescue onboard
openclaw --profile rescue gateway install --port 19789
```

如果主要機器人已在執行，通常只需要這些步驟。如果新手引導已安裝救援服務，請略過最後的 `gateway install`。

在 `openclaw --profile rescue onboard` 期間：

* 使用專供救援帳號使用的獨立 Telegram 機器人權杖（可輕鬆限制為僅供操作員使用，獨立於主要機器人的頻道／應用程式安裝，並提供簡單的私訊式復原路徑）。
* 保留 `rescue` 設定檔名稱。
* 使用至少比主要機器人高 20 的基礎連接埠。
* 除非你已自行管理工作區，否則接受預設的救援工作區。

### `--profile rescue onboard` 會變更什麼

`--profile rescue onboard` 會執行一般的新手引導流程，但將所有內容寫入獨立設定檔，因此救援機器人會有自己的：

* 設定檔／組態檔
* 狀態目錄
* 工作區（預設：`~/.openclaw/workspace-rescue`）
* 受管理的服務名稱
* 基礎連接埠（以及衍生連接埠）
* Telegram 機器人權杖

除此之外，提示內容與一般新手引導完全相同。

## 一般多閘道設定

相同的隔離模式適用於同一主機上的任意一對或一組閘道——為每個額外的閘道指定自己的命名設定檔與基礎連接埠：

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# 主要閘道（預設設定檔）
openclaw setup
openclaw gateway --port 18789

# 額外閘道
openclaw --profile ops setup
openclaw --profile ops gateway --port 19789
```

兩邊都使用命名設定檔也可行：

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
openclaw --profile main setup
openclaw --profile main gateway --port 18789

openclaw --profile ops setup
openclaw --profile ops gateway --port 19789
```

服務也遵循相同模式：

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
openclaw gateway install
openclaw --profile ops gateway install --port 19789
```

需要備援操作員通道時，請使用救援機器人快速入門；若要跨不同頻道、租戶、工作區或營運角色執行多個長期運作的閘道，請使用一般設定檔模式。

## 隔離檢查清單

每個閘道執行個體的以下項目必須保持唯一：

| 設定                          | 用途                    |
| --------------------------- | --------------------- |
| `OPENCLAW_CONFIG_PATH`      | 每個執行個體各自的組態檔          |
| `OPENCLAW_STATE_DIR`        | 每個執行個體各自的工作階段、認證資訊、快取 |
| `agents.defaults.workspace` | 每個執行個體各自的工作區根目錄       |
| `gateway.port`（或 `--port`）  | 每個執行個體皆須唯一            |
| 衍生的瀏覽器／CDP 連接埠              | 請參閱下文                 |

共用其中任何項目都會造成設定、狀態或連接埠衝突。即使
`OPENCLAW_ALLOW_MULTI_GATEWAY=1` 略過每個組態的單一執行個體限制，閘道啟動程序仍會
強制要求狀態目錄由唯一執行個體擁有。

## 連接埠對應（衍生）

基礎連接埠 = `gateway.port`（或 `OPENCLAW_GATEWAY_PORT`／`--port`）。

* 瀏覽器控制服務連接埠 = 基礎連接埠 + 2（僅限回送介面）。
* Canvas 主機由閘道 HTTP 伺服器本身提供服務（與 `gateway.port` 使用相同連接埠）。
* 瀏覽器設定檔的 CDP 連接埠會從 `browser control port + 9` 到 `+ 108` 自動配置。

若在設定或環境變數中覆寫其中任何項目，則必須確保每個執行個體的值皆唯一。

## 瀏覽器／CDP 注意事項（常見陷阱）

* **請勿**在多個執行個體上將 `browser.cdpUrl` 固定為相同值。
* 每個執行個體都需要自己的瀏覽器控制連接埠與 CDP 範圍（由其閘道連接埠衍生）。
* 若要明確指定 CDP 連接埠，請為每個執行個體設定 `browser.profiles.<name>.cdpPort`。
* 若使用遠端 Chrome，請使用 `browser.profiles.<name>.cdpUrl`（每個設定檔、每個執行個體各自設定）。

## 手動環境變數範例

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
OPENCLAW_CONFIG_PATH=~/.openclaw/main.json \
OPENCLAW_STATE_DIR=~/.openclaw \
openclaw gateway --port 18789

OPENCLAW_CONFIG_PATH=~/.openclaw/rescue.json \
OPENCLAW_STATE_DIR=~/.openclaw-rescue \
openclaw gateway --port 19789
```

## 快速檢查

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
openclaw gateway status --deep
openclaw --profile rescue gateway status --deep
openclaw --profile rescue gateway probe
openclaw status
openclaw --profile rescue status
openclaw --profile rescue browser status
```

* `gateway status --deep` 會找出舊版安裝所遺留的 launchd／systemd／schtasks 服務。
* 只有在你刻意執行多個隔離閘道，或 OpenClaw 無法證明可連線的探測目標是同一個閘道時，才預期會看到 `gateway probe` 警告文字，例如 `multiple reachable gateway identities detected`。即使傳輸連接埠不同，連至同一閘道的 SSH 通道、Proxy URL 或已設定的遠端 URL，仍是一個使用多種傳輸方式的閘道。

## 相關內容

* [閘道操作手冊](/zh-TW/gateway)
* [閘道鎖定](/zh-TW/gateway/gateway-lock)
* [組態設定](/zh-TW/gateway/configuration)
