返回顶部
f

failover-gateway故障转移网关

Set up an active-passive failover gateway for OpenClaw. Deploy a standby node that auto-promotes when your primary goes down and auto-demotes when it recovers. Includes health monitor script, systemd services, channel splitting strategy, and step-by-step deployment guide. Use when you need high availability, disaster recovery, or redundancy for your OpenClaw instance.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
729
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

failover-gateway

OpenClaw 故障转移网关

部署一个备用 OpenClaw 网关,当主网关宕机时自动接管。采用主动-被动设计,具备自动提升和自动降级功能。

功能特性

  • - 约30秒故障转移 — 健康监控检测到主网关宕机,提升备用网关
  • 自动恢复 — 主网关恢复后,备用网关自动降级
  • 零脑裂 — 主备使用不同通道(无重复消息)
  • Git同步工作区 — 备用网关在提升时拉取最新工作区
  • 每月12美元 — 运行在最低配置VPS上

架构

主网关(你的主VPS) 备用网关(故障转移VPS)
├─ 完整堆栈(所有通道) ├─ 仅单一通道(如Discord私信)
├─ 所有定时任务 ├─ 无定时任务(恢复模式)
├─ 网关运行中 ✅ ├─ 网关已停止 💤
└─ 推送工作区至Git └─ 健康监控监视主网关

├─ 主网关健康 → 休眠
├─ 主网关宕机30秒 → 提升
└─ 主网关恢复 → 降级

关键思路:在主备之间拆分通道。不共享凭证——让每个节点独占不同通道的所有权。这完全消除了脑裂问题。

通道拆分示例

配置主网关备用网关
RC + DiscordRocket.Chat(完整)仅Discord私信
Discord + Telegram
Discord(完整) | 仅Telegram私信 | | Slack + Discord | Slack(完整) | 仅Discord私信 |

主网关处理所有事务。备用网关仅用于最小恢复——足以保持可联系状态。

前置条件

  • - 在VPS上运行的主OpenClaw实例
  • 用于备用网关的第二台VPS(每月6-12美元,任何提供商均可)
  • Tailscale 网状网络(或任何VPN/私有网络)
  • 用于工作区同步的Git仓库(GitHub、GitLab等)
  • 备用网关的第二个消息通道(与主网关不同)

分步部署

第一阶段:配置备用VPS

任何便宜的VPS均可。推荐:2GB内存,Ubuntu 24.04。

bash

加固服务器


ufw allow 22/tcp
ufw enable
apt install -y fail2ban unattended-upgrades

创建openclaw用户

adduser openclaw --disabled-password usermod -aG sudo openclaw

将你的SSH密钥复制到openclaw用户

安装Tailscale

curl -fsSL https://tailscale.com/install.sh | sh tailscale up --hostname=your-failover-name

第二阶段:安装OpenClaw

bash

以openclaw用户身份执行


curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source ~/.bashrc
nvm install --lts
npm install -g openclaw

克隆工作区

git clone ~/.openclaw/workspace

第三阶段:故障转移配置

在备用网关上创建最小化的OpenClaw配置。仅启用备用通道:

json
{
agents: {
defaults: {
model: {
primary: anthropic/claude-opus-4-6,
fallbacks: [anthropic/claude-sonnet-4-5]
},
workspace: /home/openclaw/.openclaw/workspace
},
list: [{ id: main, default: true }]
},
channels: {
discord: {
enabled: true,
token: <你的Discord机器人令牌>,
dm: {
policy: allowlist,
allowFrom: [<你的Discord用户ID>]
}
}
},
gateway: {
port: 18789,
mode: local,
bind: tailnet
}
}

重要: 在主网关上禁用此通道以避免冲突。

测试是否正常工作:openclaw gateway run — 验证机器人连接和响应,然后停止。

第四阶段:部署健康监控

将附带的 scripts/health-monitor.sh 复制到备用网关:

bash
sudo cp health-monitor.sh /usr/local/bin/openclaw-health-monitor.sh
sudo chmod +x /usr/local/bin/openclaw-health-monitor.sh

编辑顶部的变量:

  • - PRIMARYIP — 主网关的Tailscale IP
  • PRIMARYPORT — 主网关的网关端口(默认:18789)
  • SECRETS_HOST — (可选)提升时用于rsync同步密钥的主机

创建systemd服务:

/etc/systemd/system/openclaw-health-monitor.service
ini
[Unit]
Description=OpenClaw故障转移健康监控
After=network-online.target tailscaled.service
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/bin/openclaw-health-monitor.sh
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

/etc/systemd/system/openclaw.service
ini
[Unit]
Description=OpenClaw网关(故障转移)
After=network-online.target tailscaled.service
Wants=network-online.target

[Service]
Type=simple
User=openclaw
Group=openclaw
WorkingDirectory=/home/openclaw/.openclaw/workspace
ExecStart=/usr/bin/openclaw gateway run
Restart=on-failure
RestartSec=5
Environment=HOME=/home/openclaw
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

启用监控(但不启用网关——监控会在提升时启动它):

bash
sudo systemctl daemon-reload
sudo systemctl enable openclaw-health-monitor
sudo systemctl start openclaw-health-monitor

不要启用openclaw.service — 由监控控制

第五阶段:在主网关上禁用备用通道

这一步至关重要。从主网关配置中移除或禁用备用通道:

json
{
channels: {
discord: { enabled: false }
}
}

每个节点独占其通道。无共享,无冲突。

第六阶段:测试

bash

在主网关上 — 模拟故障


sudo systemctl stop openclaw-gateway # 或终止进程

查看备用网关日志

journalctl -u openclaw-health-monitor -f

预期结果:3次检查失败 → 提升 → 网关启动 → 备用通道上线

在主网关上 — 恢复

sudo systemctl start openclaw-gateway

预期结果:备用网关检测到主网关 → 降级 → 网关停止

故障转移时间线

时间事件
0秒主网关宕机
10秒
首次健康检查失败 | | 20秒 | 第二次检查失败 | | 30秒 | 第三次检查失败 → 提升 | | 35秒 | Git拉取,密钥同步 | | 40秒 | 网关启动中 | | 45秒 | 备用通道激活 | | ~60秒 | 你重新可联系 |

边界情况

场景结果
主网关宕机备用网关在约30-60秒内提升
主备同时宕机
你离线(添加第三个节点?) | | 网络分区 | 备用网关可能在主网关仍在运行时提升——但由于使用不同通道,无冲突 | | 备用网关重启 | 健康监控自动重启(systemd),继续监视 | | 主网关频繁切换 | 提升/降级循环——健康监控可处理,但考虑增加FAIL_THRESHOLD |

回切

恢复是自动的。当主网关恢复时:

  1. 1. 健康监控检测到主网关健康
  2. 停止备用网关
  3. 主网关恢复所有通道
  4. 备用网关恢复监视状态

无需手动干预。

成本

组件成本
VPS(2GB内存)每月6-12美元
Tailscale
免费(个人版) | | Git仓库 | 免费 | | 总计 | 每月6-12美元 |

提示

  • - 每月测试一次。 关闭主网关,验证故障转移是否正常工作。信任但验证。
  • 保持备用网关最小化。 无定时任务,

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 failover-gateway-pub-1776420028 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 failover-gateway-pub-1776420028 技能

通过命令行安装

skillhub install failover-gateway-pub-1776420028

下载

⬇ 下载 failover-gateway v1.0.0(免费)

文件大小: 5.28 KB | 发布时间: 2026-4-17 18:57

v1.0.0 最新 2026-4-17 18:57
Initial release — deploy active-passive failover gateway for OpenClaw:

- Provides automated failover with standby node auto-promotion/demotion when primary changes state.
- Includes health monitor script, systemd services, and a channel splitting strategy to avoid split-brain.
- Workspace kept in sync via Git on promotion.
- Full deployment guide covers prerequisites, system hardening, OpenClaw configuration, and testing.
- Ensures high availability and redundancy for OpenClaw, with typical failover in ~30–60 seconds.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部