自愈式家庭服务器:让基础设施自己照顾自己
用 OpenClaw 打造 7x24 小时自动巡检、故障自愈的家庭服务器管理系统
运行一台家庭服务器意味着你要全天候给自己的基础设施当值班人员。凌晨三点服务挂了、SSL 证书悄悄过期了、磁盘满了、Pod 在无限重启——而你还在睡觉或者在外面。
这个用例把 OpenClaw 变成一个常驻的基础设施智能体,拥有 SSH 访问权限、自动化定时任务,以及在你发现问题之前就检测、诊断和修复问题的能力。
痛点
家庭实验室玩家和自托管爱好者面临着持续不断的维护负担:
- 健康检查、日志监控和告警需要手动设置和持续关注
- 出了问题你得 SSH 上去排查修复——经常还是在手机上操作
- 基础设施即代码(Terraform、Ansible、Kubernetes 配置文件)需要定期更新
- 关于你的服务器配置的知识都在你脑子里,没有可搜索的文档
- 日常任务(邮件分拣、部署检查、安全审计)每周要吃掉好几个小时
它能做什么
- 自动健康监控:通过定时任务检查服务、部署和系统资源
- 故障自愈:通过健康检查发现问题后自动修复(重启 Pod、扩容资源、修正配置)
- 基础设施管理:编写和应用 Terraform、Ansible 和 Kubernetes 配置
- 晨间简报:每日推送系统健康、日历、天气和任务看板汇总
- 邮件分拣:扫描收件箱,标记需要处理的邮件,归档噪音
- 知识提取:将笔记和对话记录整理为结构化、可搜索的知识库
- 博客发布流水线:草稿 -> 生成封面图 -> 发布到 CMS -> 部署到主机——全程自动
- 安全审计:定期扫描硬编码的密钥、特权容器和过于宽松的权限
需要的技能
ssh访问家庭网络机器kubectl管理 Kubernetes 集群terraform和ansible基础设施即代码1passwordCLI 密钥管理gogCLI 访问邮箱- 日历 API 访问
- Obsidian 笔记库或笔记目录(知识库用)
openclaw doctor自我诊断
搭建步骤
1. 核心智能体配置
在 AGENTS.md 中命名你的智能体并定义其访问范围:
## Infrastructure Agent
You are Reef, an infrastructure management agent.
Access:
- SSH to all machines on the home network (192.168.1.0/24)
- kubectl for the K3s cluster
- 1Password vault (read-only for credentials, dedicated AI vault)
- Gmail via gog CLI
- Calendar (yours + partner's)
- Obsidian vault at ~/Documents/Obsidian/
Rules:
- NEVER hardcode secrets — always use 1Password CLI or environment variables
- NEVER push directly to main — always create a PR
- Run `openclaw doctor` as part of self-health checks
- Log all infrastructure changes to ~/logs/infra-changes.md
2. 自动化定时任务系统
这套方案的精髓在于定时任务系统。在 HEARTBEAT.md 中配置:
## Cron Schedule
Every 15 minutes:
- Check kanban board for in-progress tasks -> continue work
Every hour:
- Monitor health checks (Gatus, ArgoCD, service endpoints)
- Triage Gmail (label actionable items, archive noise)
- Check for unanswered alerts or notifications
Every 6 hours:
- Knowledge base data entry (process new Obsidian notes)
- Self health check (openclaw doctor, disk usage, memory, logs)
Every 12 hours:
- Code quality and documentation audit
- Log analysis via Loki/monitoring stack
Daily:
- 4:00 AM: Nightly brainstorm (explore connections between notes)
- 8:00 AM: Morning briefing (weather, calendars, system stats, task board)
- 1:00 AM: Velocity assessment (process improvements)
Weekly:
- Knowledge base QA review
- Infrastructure security audit
3. 安全设置(关键步骤)
这一步没有商量余地。在给智能体 SSH 权限之前:
## Security Checklist
1. Pre-push hooks:
- Install TruffleHog or similar secret scanner on ALL repositories
- Block any commit containing hardcoded API keys, tokens, or passwords
2. Local-first Git workflow:
- Use Gitea (self-hosted) for private code before pushing to public GitHub
- CI scanning pipeline (Woodpecker or similar) runs before any public push
- Human review required before main branch merges
3. Defense in depth:
- Dedicated 1Password vault for AI agent (limited scope)
- Network segmentation for sensitive services
- Daily automated security audits checking for:
* Privileged containers
* Hardcoded secrets in code or configs
* Overly permissive file/network access
* Known vulnerabilities in deployed images
4. Agent constraints:
- Branch protection: PR required for main, agent cannot override
- Read-only access where write isn't needed
- All changes logged and auditable via git
4. 晨间简报模板
## Daily Briefing Format
Generate and deliver at 8:00 AM:
### Weather
- Current conditions and forecast for [your location]
### Calendars
- Your events today
- Partner's events today
- Conflicts or overlaps flagged
### System Health
- CPU / RAM / Storage across all machines
- Services: UP/DOWN status
- Recent deployments (ArgoCD)
- Any alerts in last 24h
### Task Board
- Cards completed yesterday
- Cards in progress
- Blocked items needing attention
### Highlights
- Notable items from nightly brainstorm
- Emails requiring action
- Upcoming deadlines this week
核心洞察
- "没想到我真的有了一台自愈服务器":智能体可以执行 SSH、Terraform、Ansible 和 kubectl 命令,在你还没意识到有问题的时候就把故障修好了
- AI 会硬编码密钥:这是头号安全风险。如果不设防,智能体会毫不犹豫地把 API Key 直接写到代码里。Pre-push hooks 和密钥扫描是必须的
- 本地优先的 Git 工作流至关重要:永远不要让智能体直接推送到公共仓库。用自托管的 Gitea 作为暂存区,配合 CI 扫描
- 定时任务才是真正的产品:定期自动执行的健康检查、邮件分拣、晨间简报,比临时起意的命令带来更多日常价值
- 知识提取会产生复利:把笔记、对话记录、邮件整理到结构化知识库中,时间越长越有价值——有用户光从 ChatGPT 历史记录中就提取出了 49,079 条原子知识
灵感来源
这个用例基于 Nathan 的详细文章 "Everything I've Done with OpenClaw (So Far)"。他在文中描述了自己的 OpenClaw 智能体"Reef"——运行在家庭服务器上,SSH 连接所有机器,管理着一个 Kubernetes 集群,集成了 1Password,还有一个包含 5,000 多条笔记的 Obsidian 知识库。Reef 运行着 15 个定时任务、24 个自定义脚本,已经自主构建并部署了包括任务管理界面在内的多个应用。Nathan 在第一天就遭遇了 API Key 泄露,他用血的教训总结道:"AI 助手会毫不犹豫地硬编码密钥。它们有时候没有人类那样的安全直觉。"他的纵深防御安全方案(TruffleHog pre-push hooks、本地 Gitea、CI 扫描、每日审计)是所有想尝试这种模式的人的必读内容。
OpenClaw Showcase 上 @georgedagg_ 也描述了类似的模式:监控部署、检查日志、修复配置、提交 PR——全程遛狗的时候完成。
相关链接
本文翻译自 awesome-openclaw-usecases 开源项目。英文能力过得去的朋友欢迎阅读原版,体验原汁原味的表达。