6. 综合练习:部署一个 24/7 助手
这是什么:一次端到端部署 = 选机器 → 装 OpenClaw → 接渠道 → 收紧权限 → 教它记住你 → 让它主动开口 → 建立运维习惯,最后跑一遍验收清单。
为什么用:前五章是零件,这一章是装配。会装 ≠ 会用——真正的 24/7 助手意味着你关机、它重启、你换设备,它都还在那儿守着,而且不会半夜把你的密钥发给别人。
如何用:本章按 7 步走,每步都有明确的「完成的标志」。跟着走完,你的助手就能上线了。
6.1 先写下验收标准
动手前先把这张表贴出来,最后一项一项打勾:
| # | 验收项 | 怎么算过 |
|---|---|---|
| 1 | Gateway 常驻 | 重启机器后 openclaw gateway status 仍是 running |
| 2 | 渠道通 | 从手机 Telegram 发消息,10 秒内有回复 |
| 3 | 陌生人进不来 | 另一个账号发消息只拿到配对码 |
| 4 | 群不乱说话 | 群里不 @ 它,它一声不吭 |
| 5 | 权限收紧了 | openclaw security audit 没有高危 warn |
| 6 | 它记得你 | 新会话里问「我喜欢什么语言」,它答得对 |
| 7 | 会主动 | 定时任务按时把日报推到你的聊天里 |
| 8 | 备份存在 | openclaw backup create 成功,文件在 |
6.2 第 1 步:选机器
真正的 24/7 首选一台 VPS(DigitalOcean / Hetzner / 腾讯云都行)——你的笔记本一合盖就断线;想省钱可以用家里的小主机或 NAS,但断电就断;想试水就在本机手动跑 openclaw gateway,但那只适合验证流程。
服务器建议单独开一个 Linux 用户跑 OpenClaw,别用 root。这是第 5 章「一个信任域一个身份」的直接落地。
6.3 第 2 步:安装并常驻
curl -fsSL https://openclaw.ai/install.sh | bash
openclaw onboard --install-daemon
openclaw gateway status
你会看到(示意):
service: running (systemd user unit)
listen: 127.0.0.1:18789
agents: main
看到 running 才算过第 1 条验收。还有两点要确认:openclaw onboard 里的真实推理验证必须通过(只保存了配置但没验通,等于没模型);systemd user service 依赖用户会话 linger,要 7×24 不断,登录一次后执行 sudo loginctl enable-linger $USER。
6.4 第 3 步:接渠道
按第 3 章的 Telegram 流程走完四步:
openclaw channels add --channel telegram --token <bot-token>
openclaw channels status --probe
openclaw pairing list telegram
openclaw pairing approve telegram <CODE>
你会看到(示意):
Configured channel: telegram (account "default")
telegram default enabled probe: ok
pending: telegram sender=987654321 code=7KQ4M2XP expires in 58m
approved: telegram sender=987654321 (DM access granted)
要点:用助手的专用账号,别绑你本人的私人 Telegram 号;群 ID(-100 开头)和你的 user ID 都要拿到,配到 groups 和 allowFrom;requireMention: true 别省。
6.5 第 4 步:写一份「敢上线」的配置
打开 ~/.openclaw/openclaw.json,把第 5.4 节的基线抄进去,再按自己的渠道改:
{
gateway: {
mode: "local",
bind: "loopback",
auth: { mode: "token", token: "换成你自己的长随机串" },
},
session: { dmScope: "per-channel-peer" },
tools: {
profile: "messaging",
deny: ["group:automation", "group:runtime", "group:fs", "sessions_spawn", "sessions_send"],
fs: { workspaceOnly: true },
exec: { security: "deny", ask: "always" },
elevated: { enabled: false },
sessions: { visibility: "agent" },
agentToAgent: { enabled: false },
},
channels: {
telegram: {
dmPolicy: "pairing",
allowFrom: ["你的 user id"],
groups: { "*": { requireMention: true } },
},
},
}
你会看到(示意):
$ openclaw config get tools.exec
{ security: "deny", ask: "always" }
改完立刻体检:
openclaw security audit
chmod 700 ~/.openclaw && chmod 600 ~/.openclaw/openclaw.json
你会看到(示意):
openclaw security audit
[ok] gateway.bind_loopback Gateway 只监听 127.0.0.1
[ok] gateway.auth_token Gateway auth 已启用(token)
[ok] fs.state_dir_permissions ~/.openclaw 权限 700
0 warnings, 0 findings.
第 5 条验收(没有高危 warn)到这里才有机会过。
想让它以后能跑命令,别急着把
exec.security改成"full"。先开沙箱(agents.defaults.sandbox.mode: "all"),让它在没凭据的容器里跑。
6.6 第 5 步:教会它
教它做事——写一个技能:mkdir -p ~/.openclaw/workspace/skills/daily-digest,把 SKILL.md 写好(格式见第 4 章),比如让它每天读 ~/projects/*/git log --since=1 day 汇总成一段话。
教它记住你——直接说就行:
「记住我主要写 Python,代码风格偏简洁,提交信息用中文。」
然后去 ~/.openclaw/workspace/USER.md 检查它写进去了。想让 MEMORY.md 别乱涨,可以关掉后台做梦:{ plugins: { entries: { "memory-core": { config: { dreaming: { enabled: false } } } } } }。
6.7 第 6 步:让它主动开口
这是「助手」和「工具」的分水岭。OpenClaw 有两个主动机制。
心跳(heartbeat)——定期醒来看看有没有该做的事。默认每 30 分钟跑一次(用 Anthropic OAuth 时是 1 小时)。评估期建议先关掉:{ agents: { defaults: { heartbeat: { every: "0m" } } } }。
定时任务(automations)——到点干活并把结果推给你:
openclaw automations create "0 8 * * *" \
"汇总昨天的 Git 提交和未完成 Todo,输出一段简报。" \
--name "Morning brief" \
--tz "Asia/Shanghai" \
--session isolated \
--announce \
--channel telegram \
--to "你的私聊 chat id"
你会看到(示意):
created: Morning brief cron="0 8 * * *" tz=Asia/Shanghai
next run: 2026-10-22 08:00:00 +08:00
delivery: telegram -> user:987654321
openclaw automations 是主命令,openclaw cron 是它的别名。常用操作:
openclaw automations list # 列出(加 --all 连禁用的也看)
openclaw automations runs <jobId> # 运行历史
openclaw automations run <jobId> --wait # 立刻跑一次并等结果
openclaw automations disable <jobId> # 临时停掉
你会看到(示意):
id name schedule next run status
cron_a1b2c3 Morning brief 0 8 * * * 2026-10-22 08:00 +08 enabled
推送到私聊而不是群。群里的日报是所有人的信息泄露面。
6.8 第 7 步:日常运维三件套
① 更新:openclaw update → openclaw doctor --fix → openclaw gateway restart。更新前先备份。
② 备份:
openclaw backup create --output ~/Backups/openclaw --verify
openclaw storage init offsite
openclaw storage test offsite
openclaw backup enable --to offsite --every 24h --keep-daily 7 --keep-weekly 4 --keep-monthly 12
你会看到(示意):
created: 2026-10-21T09-00-00.000+08-00-openclaw-backup.tar.gz (48.2 MiB)
verified: manifest OK, 412 files, sha256 OK
offsite: initialized, test OK, backup schedule enabled (every 24h)
后面三条是配置「每天自动归档到异地」的存储位置。
备份里含凭据和会话历史——加密存、限制访问。怀疑泄露就轮换密钥。
③ 体检:openclaw status --all(已脱敏,可直接贴给别人看)、openclaw doctor、openclaw security audit。
6.9 最终验收
把 6.1 那张表从头过一遍。特别验证重启之后(sudo reboot,或者重启 Gateway 服务):
openclaw gateway status
openclaw channels status --probe
openclaw pairing list telegram # 应该没有待批的陌生请求
openclaw security audit # 不该有新的高危 warn
你会看到(示意):
service: running (systemd user unit) listen: 127.0.0.1:18789
telegram default enabled probe: ok
pending: none
0 warnings, 0 findings.
再从手机 Telegram 随手发一句,确认它还活着、还记得你。
动手改
- 把 6.1 的验收表按你的实际情况改一改——比如加一条「能在 VPS 上远程通过 Tailscale 访问控制台」,然后逐条打勾
- 给助手再写一个技能:比如
check-disk(跑df -h并在超过 90% 时告警),再配一条每小时的定时任务 - 故意模拟一次事故:把
openclaw.json的bind改成"lan"且删掉auth,跑一次openclaw security audit看看它怎么报——然后改回来再跑一次对比
小结
- 先写验收标准再动手;「24/7」的第一要件是常驻,第二是权限收紧
- VPS + 独立 Linux 用户 + systemd user service +
loginctl enable-linger,是真正的 7×24 - 上线配置照抄第 5 章基线,
security audit必须过 - 教它靠技能(
SKILL.md)和记忆(USER.md/MEMORY.md);推送走私聊不走群 - 主动能力靠心跳和定时任务;运维三件套是
update、backup create、status/doctor/audit - 出事按第 5.9 节:隔离 → 轮换 → 审计 → 取证
恭喜,你已经有一套跑在自己机器上、24/7 待命、且边界清晰的 AI 助手了 🦞
接下来可以做的事:给它接第二个渠道(第 3 章)、把重复的手工流程继续沉淀成技能(第 4 章)、或者去 Agent 循环 补一补底层原理。
返回 OpenClaw 教程目录,或回到 AI 板块 看看其他教程 🐸