安装 OpenClaw 与 Hermes

什么是 OpenClaw 和 Hermes

OpenClaw 是一款开源的分布式任务调度与爬取框架,适合需要在服务器上运行自动化脚本、定时任务或数据采集服务的用户。

Hermes 是一个高性能异步消息队列与通知系统,常与 OpenClaw 搭配使用,负责任务分发、结果推送和事件通知。两者组合可构建稳定的自动化后端服务。

典型应用场景:

  • 定时数据采集与处理
  • 自动化脚本任务调度
  • 异步消息推送与通知
  • 轻量级后台任务处理

系统要求

  • 支持系统:Ubuntu 20.04 / Ubuntu 22.04 / Debian 11+
  • 最低配置:1 核 CPU、1GB 内存、10GB 磁盘(推荐 2GB 内存)
  • 运行环境:Python 3.9+、Node.js 18+(Hermes 需要)

RackNerd 2GB 套餐($17.98/年)可流畅运行 OpenClaw + Hermes 全套服务。

准备工作

1. SSH 连接到 VPS

ssh root@你的IP地址

2. 更新系统并安装基础依赖

apt update && apt upgrade -y
apt install -y curl wget git build-essential python3 python3-pip python3-venv

3. 安装 Node.js 18

curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt install -y nodejs
node -v   # 确认版本 >= 18

安装 OpenClaw

1. 创建专用用户(推荐)

useradd -m -s /bin/bash openclaw
su - openclaw

2. 克隆项目

git clone https://github.com/openclaw/openclaw.git
cd openclaw

3. 创建虚拟环境并安装依赖

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

4. 初始化配置

cp config/config.example.yaml config/config.yaml

编辑配置文件,按需修改数据库路径、日志级别等参数:

nano config/config.yaml

5. 初始化数据库

python3 manage.py migrate

6. 测试启动

python3 manage.py runserver

看到类似 OpenClaw started on port 8080 的输出即表示启动成功,按 Ctrl+C 停止。

安装 Hermes

1. 全局安装 Hermes CLI

切换回 root 用户:

exit   # 从 openclaw 用户退出
npm install -g @hermes-mq/server

2. 初始化 Hermes 服务

mkdir -p /opt/hermes && cd /opt/hermes
hermes init

按提示完成配置:

  • 端口:默认 5672(可改为其他端口)
  • 管理员密码:设置一个强密码
  • 存储路径:默认 /opt/hermes/data

3. 生成配置文件

hermes config --host 0.0.0.0 --port 5672 --auth true > hermes.config.json

配置 Systemd 服务(开机自启)

OpenClaw 服务

创建 /etc/systemd/system/openclaw.service

cat > /etc/systemd/system/openclaw.service << 'EOF'
[Unit]
Description=OpenClaw Task Scheduler
After=network.target

[Service]
Type=simple
User=openclaw
WorkingDirectory=/home/openclaw/openclaw
ExecStart=/home/openclaw/openclaw/venv/bin/python manage.py runserver
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

Hermes 服务

创建 /etc/systemd/system/hermes.service

cat > /etc/systemd/system/hermes.service << 'EOF'
[Unit]
Description=Hermes Message Queue
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/hermes
ExecStart=/usr/bin/hermes start --config hermes.config.json
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

启用并启动服务

systemctl daemon-reload
systemctl enable openclaw hermes
systemctl start openclaw hermes

检查运行状态

systemctl status openclaw
systemctl status hermes

两个服务均显示 active (running) 即为正常。

连接 OpenClaw 与 Hermes

在 OpenClaw 配置文件中指定 Hermes 地址:

# config/config.yaml
message_queue:
  host: 127.0.0.1
  port: 5672
  password: 你设置的密码

重启 OpenClaw 使配置生效:

systemctl restart openclaw

查看日志

# OpenClaw 日志
journalctl -u openclaw -f

# Hermes 日志
journalctl -u hermes -f

防火墙配置

如需外部访问 Hermes,开放对应端口(仅在需要时操作):

ufw allow 5672/tcp
ufw reload

OpenClaw 的 8080 端口通常只在本机使用,不建议对外暴露。

适用场景与推荐套餐

使用场景 推荐套餐
个人轻量任务调度 768MB($11.29/年)
OpenClaw + Hermes 完整部署 2GB($17.98/年)
高频任务 + 多队列 2.5GB 或以上

RackNerd 续费不涨价,长期运行 OpenClaw 和 Hermes 成本极低,是自建自动化服务的理想选择。