Appearance
Hermes AI Agent 微信多用户配置教程。每个微信用户有独立的会话、权限和用量统计,通过 HERMES_HOME 环境变量实现完全隔离。
背景
在本地电脑配置 Hermes 微信多用户,每个用户有独立的会话、权限和用量统计。
关键限制:iLink bot 只支持绑定 1 个微信用户,每个 iLink bot 需要有独立的 Gateway。
核心架构
┌─────────────────────────────────────────────────────────────┐
│ 服务器架构 │
├─────────────────────────────────────────────────────────────┤
│ │
│ 服务器 │
│ ├── Gateway 1 (systemd 服务) │
│ │ ├── Bot: clawbot#1 │
│ │ └── 用户 A 的微信 │
│ │ │
│ └── Gateway 2 (systemd 服务) │
│ ├── Bot: clawbot#2 │
│ └── 用户 B 的微信 │
│ │
└─────────────────────────────────────────────────────────────┘关键点
| 关键点 | 说明 |
|---|---|
| 每个微信用户绑定 | 独立的 iLink bot |
| 每个 bot 运行 | 独立的 Gateway 进程 |
| 各自使用 | 独立的配置目录 |
| 通过 | HERMES_HOME 环境变量隔离 |
前置条件
| 条件 | 说明 |
|---|---|
| Linux 服务器 | Ubuntu/Debian |
| Hermes Agent 已安装 | pip install hermes-agent |
| 已配置第一个微信 bot | 能正常使用 |
| sudo 权限 | 用于 systemd 服务 |
配置步骤
Step 1:确认第一个 Gateway 正常运行
确保你的微信能正常收发消息。
bash
# 检查运行状态
systemctl status hermes-gateway-1
# 查看日志
journalctl -u hermes-gateway-1 -fStep 2:创建第二个用户目录
bash
# 创建配置目录
sudo mkdir -p /opt/hermes/user-b
sudo chown -R $USER:$USER /opt/hermes/user-b
# 复制配置模板
cp -r ~/.hermes/* /opt/hermes/user-b/Step 3:生成第二个 bot
在 iLink 平台创建新的 bot,获取 Bot ID 和 Secret。
bash
# 配置环境变量
export HERMES_HOME=/opt/hermes/user-b
export BOT_ID=your-new-bot-id
export BOT_SECRET=your-new-bot-secret
# 初始化配置
cd /opt/hermes/user-b
hermes initStep 4:配置 systemd 服务
创建 systemd 服务文件 /etc/systemd/system/hermes-gateway-2.service:
ini
[Unit]
Description=Hermes Gateway 2
After=network.target
[Service]
Type=simple
User=your-user
WorkingDirectory=/opt/hermes/user-b
Environment="HERMES_HOME=/opt/hermes/user-b"
ExecStart=/usr/local/bin/hermes gateway start --port 3002
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetStep 5:启动服务
bash
# 重载 systemd
sudo systemctl daemon-reload
# 启动服务
sudo systemctl start hermes-gateway-2
# 设置开机自启
sudo systemctl enable hermes-gateway-2
# 检查状态
sudo systemctl status hermes-gateway-2配置隔离机制
HERMES_HOME 环境变量
| 用户 | HERMES_HOME | 端口 | Bot ID |
|---|---|---|---|
| 用户 A | ~/.hermes | 3001 | bot-1 |
| 用户 B | /opt/hermes/user-b | 3002 | bot-2 |
独立配置项
| 配置项 | 隔离方式 |
|---|---|
| 配置文件 | 独立目录 |
| 会话记录 | 独立目录 |
| 记忆库 | 独立目录 |
| 技能配置 | 独立目录 |
| API 密钥 | 独立 .env |
日志管理
| 命令 | 功能 |
|---|---|
journalctl -u hermes-gateway-2 -f | 实时查看日志 |
journalctl -u hermes-gateway-2 --since "1 hour ago" | 查看最近1小时日志 |
journalctl -u hermes-gateway-2 -p err | 只看错误日志 |
常用管理命令
服务管理
bash
# 启动
sudo systemctl start hermes-gateway-2
# 停止
sudo systemctl stop hermes-gateway-2
# 重启
sudo systemctl restart hermes-gateway-2
# 查看状态
sudo systemctl status hermes-gateway-2配置检查
bash
# 检查配置
export HERMES_HOME=/opt/hermes/user-b
hermes config show
# 检查连接
hermes status
# 查看用户统计
hermes stats --user user-b多用户管理
查看所有 Gateway
bash
# 列出所有 Gateway 进程
systemctl list-units 'hermes-gateway-*'
# 查看所有用户会话
hermes sessions list --all切换用户配置
bash
# 切换到用户 B
export HERMES_HOME=/opt/hermes/user-b
# 执行用户 B 的命令
hermes chat --user user-b常见问题
Q:iLink bot 能否绑定多个微信?
A: 不能。每个 iLink bot 只支持绑定 1 个微信用户。
Q:如何确保用户间数据隔离?
A: 通过 HERMES_HOME 环境变量,每个用户使用独立的配置目录。
Q:需要自建域名或服务器吗?
A: 使用 iLink bot 不需要自建域名或服务器,这是 iLink 的优势。
Q:如何查看每个用户的用量统计?
A: 使用 hermes stats --user <username> 查看指定用户的统计信息。
一句话总结
Hermes 微信多用户 = 每个微信用户独立 Gateway + HERMES_HOME 隔离配置。
核心架构:独立 iLink bot + 独立 Gateway 进程 + 独立配置目录。
5 步配置:确认 Gateway → 创建目录 → 生成 bot → 配置 systemd → 启动服务。
