当前位置: 首页 > news >正文

免死金牌: OpenClaw + keepalived

文章目录

    • 背景
    • 解决方案
    • 查看IP
    • 检测脚本
    • keepalived 配置
    • 演练故障
    • openclaw-gateway.service

背景

问题来自小龙虾自杀, 当我让 OpenClaw 更新一些配置时, 它执行了一条openclaw gateway stop命令, 导致 OpenClaw 服务停止, 然后我就干瞪眼了, 还在傻等, 它甚至一句分别的话都没有说…

openclaw gateway stop

解决方案

用 keeplived 来保持 OpenClaw 服务的运行, 在服务停止时, 能够自动重启服务, 顺便也学一下 keepalived 的用法

查看IP

ifconfig

eth0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST>mtu1450inet172.16.0.9 netmask255.255.0.0 broadcast172.16.255.255 inet6 fe80::f816:3eff:fedc:b5a8 prefixlen64scopeid 0x20<link>ether fa:16:3e:dc:b5:a8 txqueuelen1000(Ethernet)RX packets67391273bytes27877705315(27.8GB)RX errors0dropped0overruns0frame0TX packets110078632bytes24769427866(24.7GB)TX errors0dropped0overruns0carrier0collisions0lo:flags=73<UP,LOOPBACK,RUNNING>mtu65536inet127.0.0.1 netmask255.0.0.0 inet6 ::1 prefixlen128scopeid 0x10<host>loop txqueuelen1000(Local Loopback)RX packets2288521bytes373008683(373.0MB)RX errors0dropped0overruns0frame0TX packets2288521bytes373008683(373.0MB)TX errors0dropped0overruns0carrier0collisions0

检测脚本

check_openclaw.sh脚本, 用于检查 OpenClaw 服务是否运行

#!/bin/bashexportXDG_RUNTIME_DIR="/run/user/0"ifsystemctl--useris-active openclaw-gateway.service>/dev/null2>&1;thenifcurl-s-f-o/dev/null http://127.0.0.1:18789/health2>/dev/null;then#logger -t openclaw-health "Health check PASSED"exit0elselogger-topenclaw-health"Health check FAILED - service not responding"exit1fielselogger-topenclaw-health"Health check FAILED - service is not active"# 尝试启动服务logger-topenclaw-health"Attempting to start service"systemctl--userstart openclaw-gateway.servicesleep3# 检查启动是否成功ifsystemctl--useris-active openclaw-gateway.service>/dev/null2>&1;thenlogger-topenclaw-health"Service started successfully"exit0elselogger-topenclaw-health"Failed to start service"exit1fifi

keepalived 配置

keepalived 配置/etc/keepalived/keepalived.conf, 因为就一台服务器, 所以 state 为 MASTER

global_defs { router_id OPENCLAW_MONITOR script_user root enable_script_security } vrrp_script chk_openclaw { script "/usr/local/bin/check_openclaw.sh" interval 10 # 每10秒检查一次(更频繁) timeout 5 # 脚本执行超时5秒 weight -20 # 检查失败时优先级降低20 fall 2 # 连续2次失败判定为故障 rise 1 # 1次成功就恢复 } vrrp_instance OPENCLAW_MONITOR { state MASTER # 单机必须用 MASTER interface eth0 # 使用 eth0 virtual_router_id 51 priority 100 # 优先级 advert_int 2 # 心跳间隔2秒 # 虚拟IP配置 virtual_ipaddress { 172.16.0.100/16 dev eth0 # VIP 绑定到 eth0 } track_script { chk_openclaw } }

启动 keepalived 服务

# 重启 keepalivedsystemctl restart keepalived# 启用 keepalived 服务systemctlenablekeepalived# 查看 keepalived 状态systemctl status keepalived

查看 VIP(虚拟IP)

ipaddr show eth0|grep172.16.0.100 inet172.16.0.100/16 scope global secondary eth0

演练故障

# 停止 OpenClaw 服务openclaw gateway stop

journalctl -t openclaw-health -f查看日志

Apr 02 16:06:24 lavm-0sdc09108n openclaw-health[1567604]: Attempting to start service Apr 02 16:06:27 lavm-0sdc09108n openclaw-health[1567623]: Service started successfully Apr 02 16:06:34 lavm-0sdc09108n openclaw-health[1567638]: Health check FAILED - service not responding

nc -z localhost 18789验证:

Connection to localhost(127.0.0.1)18789port[tcp/*]succeeded!

也可以执行openclaw gateway status查看服务状态

🦞 OpenClaw 2026.3.24 (cff6dc9) I can grep it, git blame it, and gently roast it—pick your coping mechanism. │ ◇ Service: systemd (enabled) File logs: /tmp/openclaw/openclaw-2026-04-02.log Command: /root/.nvm/versions/node/v22.22.1/bin/node /root/.pnpm-global/5/.pnpm/openclaw@2026.3.24_@napi-rs+canvas@0.1.97/node_modules/openclaw/dist/index.js gateway --port 18789 Service file: ~/.config/systemd/user/openclaw-gateway.service Service env: OPENCLAW_GATEWAY_PORT=18789 Service config looks out of date or non-standard. Service config issue: Gateway service PATH includes version managers or package managers; recommend a minimal PATH. (/root/.nvm/versions/node/v22.22.1/bin) Service config issue: Gateway service uses Node from a version manager; it can break after upgrades. (/root/.nvm/versions/node/v22.22.1/bin/node) Service config issue: System Node 22 LTS (22.14+) or Node 24 not found; install it before migrating away from version managers. Recommendation: run "openclaw doctor" (or "openclaw doctor --repair"). Config (cli): ~/.openclaw/openclaw.json Config (service): ~/.openclaw/openclaw.json Gateway: bind=loopback (127.0.0.1), port=18789 (service args) Probe target: ws://127.0.0.1:18789 Dashboard: http://127.0.0.1:18789/ Probe note: Loopback-only gateway; only local clients can connect. Runtime: running (pid 1567606, state active, sub running, last exit 0, reason 0) RPC probe: ok Listening: 127.0.0.1:18789 Troubles: run openclaw status Troubleshooting: https://docs.openclaw.ai/troubleshooting

openclaw-gateway.service

还有更简单的方法, 直接在/etc/systemd/system/openclaw-gateway.service中配置Restart=always即可, 这样它就会在服务停止时自动重启服务

[Unit]Description=OpenClaw GatewayAfter=network-online.targetWants=network-online.target[Service]Type=simple#User=$(whoami)User=rootEnvironmentFile=/opt/openclaw/.envWorkingDirectory=/home/$(whoami)/.openclawExecStart=$(whichopenclaw)gateway--forceRestart=alwaysRestartSec=2[Install]WantedBy=multi-user.target
http://www.jsqmd.com/news/583172/

相关文章:

  • 2025届学术党必备的十大降重复率平台推荐榜单
  • 《新班主任》期刊简介及影响力
  • 读取Excel数据(替换your_data.xlsx即可)
  • 递推限幅消抖数字滤波函数的实现(C 语言,嵌入式 / Keil 通用)
  • 【热搜爆了】格行3.0代理模式席卷全网!主播日入过万的合规带货新选择! - 格行官方招商总部
  • 2026跨境电商数据采集避坑指南:实测实在Agent如何终结“数字员工”的幻觉时代
  • 丧尸危机模拟:灾备系统的终极压力测试
  • 【枕上节令笺】清明食青团,一口咬尽江南春
  • 联合索引设计:最左前缀、选择性、覆盖索引与落地方法
  • 【软件部署】在docker环境部署vsftpd
  • 2.4.快速排序——先分区再递归,为什么它平均这么快却可能退化?
  • Applite终极指南:如何在3分钟内掌握Mac软件管理
  • Android上部署Linux环境的方案总结对比
  • OpenClaw安装部署Mac操作系统版 - 打造你的专属AI助理
  • 越用越好用:OpenClaw的进化型Agent
  • Sprague-Grundy (SG) 函数及其应用
  • 多车环境下车载毫米波雷达是否会相互干扰?
  • 【深伪检测】论文整体调研与梳理方法
  • 战争环境软件测试:乌克兰开发者的生存报告
  • 2025-2026年靠谱移民机构评测:五家口碑服务推荐评价顶尖 - 十大品牌推荐
  • **Compose原理深度剖析:从声明式UI到高效渲染的核心机制**在现代Android开发中
  • 【Linux】关于 mmap 文件映射
  • 贵州公考面试选机构
  • An-Labeler:AudioLabellerV3 AI 辅助标注工具详解(自研Qt + FFT/模型自动标注)
  • SAP ABAP 根据表名上传数据,简易版
  • 2025届学术党必备的五大AI辅助写作平台实际效果
  • 《AI 小游戏开发(2)|带倒计时的 30 秒点方块,AI 生成完整游戏)》
  • 2025-2026年国内十大移民机构评测:五家口碑服务推荐评价 - 十大品牌推荐
  • 文理单片机课堂作业_数码管显示_0311
  • **发散创新:基于PyTorch的自定义深度学习框架实战与架构演进解析**在当前主流深度学习框架(如TensorFlow、P