Files
nexus/wiki/sources/self-healing-home-server.md

119 lines
8.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Self-Healing Home Server & Infrastructure Management"
type: source
tags: [openclaw, self-healing, home-server, infrastructure, agentic-ai, cron, ssh, iac, security]
date: 2026-04-26
---
## Source File
- [[raw/Agent/usecases/self-healing-home-server.md]]
## Summary用中文描述
- 核心主题AI Agent 作为家庭服务器基础设施的全天候自动驾驶代理
- 问题域:家庭服务器 24/7 运维负担凌晨故障、证书过期、磁盘爆满、Pod崩溃
- 方法/机制OpenClaw + SSH + Cron Job 系统 + 自动化健康监控 + 故障自愈 + 基础设施即代码Terraform/Ansible/Kubernetes
- 结论/价值Cron Job 是真正的产品力——定时自动化(健康检查、邮件分拣、晨报)比偶发命令提供更多日常价值;知识提取随时间复利增长
## Skills
- `ssh` — 访问家庭网络机器192.168.1.0/24
- `kubectl` — K3s 集群管理
- `terraform` / `ansible` — 基础设施即代码
- `1password` CLI — secrets 管理Agent 专用只读 vault
- `gog` CLI — Gmail 邮件访问
- Calendar API — 日历(本人 + 伴侣)
- Obsidian vault — 知识库5000+ 笔记)
- `openclaw doctor` — 自我诊断
## How to Set It Up
### Core Agent Configuration
在 AGENTS.md 中定义 Agent 名称和访问范围,例如名为 **Reef** 的基础设施 Agent
- SSH 到家庭网络所有机器
- kubectl 操作 K3s 集群
- 1Password vault只读凭证专用 AI vault
- Gmail via gog CLI
- 日历(本人 + 伴侣)
- Obsidian vault at ~/Documents/Obsidian/
规则:永远不用硬编码 secrets永远通过 PR 而非直接推送 main每次自检运行 `openclaw doctor`;所有基础设施变更记录到 ~/logs/infra-changes.md
### Automated Cron Job System
配置 HEARTBEAT.md 调度系统:
- 每 15 分钟:看板任务续做
- 每小时健康检查Gatus/ArgoCD、邮件分拣、告警检查
- 每 6 小时知识库录入、自检openclaw doctor/磁盘/内存/日志)
- 每 12 小时代码质量审计、日志分析Loki
- 每日 4:00 AM夜间头脑风暴8:00 AM晨报天气/日历/系统/看板1:00 AM速率评估
- 每周:知识库 QA、安全审计
### Security Setup关键
- Pre-push hooks所有仓库安装 TruffleHog阻止含 API Key/Token/Password 的提交
- 本地优先 Git用私有 Gitea 实例作为中转CI 扫描后才推公共 GitHub主分支合并需人工审核
- 纵深防御AI Agent 专用 1Password vault受限范围、网络分段、每日自动化安全审计特权容器/硬编码 secrets/权限过宽/已知漏洞)
- Agent 约束PR 保护主分支、只读访问优先、所有变更可审计
### Morning Briefing Template
每日 8:00 AM 自动生成并投递:
- 天气:当前位置当前状况和预报
- 日历:本人和伴侣今日事件,冲突标记
- 系统健康:所有机器 CPU/RAM/存储,服务 UP/DOWN最近部署ArgoCD过去 24h 告警
- 任务看板:昨日完成/进行中/阻塞项
- 要点:昨夜头脑风暴亮点、待操作邮件、本周截止
## Key Claims用中文描述
- **AI 会硬编码 secrets**AI Agent 会在代码中直接写入 API Key这是 #1 安全风险。必须强制推行 pre-push hooks 和 secrets scanningTruffleHog
- **本地优先 Git 是必须的**:绝不能让 Agent 直接推送到公共仓库。使用私有 Gitea 实例作为中转,配合 CI 扫描 pipeline
- **Cron Job 是真正的产品**:定时自动化(健康检查、邮件分拣、晨报)比偶发命令提供更多日常价值
- **知识提取具有复利效应**:将笔记、对话导出和邮件处理成结构化知识库,时间越久价值越大——一位用户从 ChatGPT 历史中提取了 49,079 条原子事实
## Key Quotes
> "I can't believe I have a self-healing server now" — 代理可以在你不知情的情况下通过 SSH、Terraform、Ansible 和 kubectl 修复基础设施问题
> "AI assistants will happily hardcode secrets. They sometimes don't have the same instincts humans do." — Nathan 的惨痛教训第1天即发生 API Key 泄露)
> "The scheduled automation (health checks, email triage, briefings) provides more daily value than ad-hoc commands." — Cron Job 才是真正的产品
## Key Concepts
- [[Self-Healing-Systems]]:通过健康检查检测问题并自动执行修复(重启 Pod、扩缩容、修复配置
- [[Agentic AI]]:具有自主决策和任务执行能力的 AI 系统——驱动整个自愈管道的核心
- [[Infrastructure-as-Code]]IaCAgent 编写并应用 Terraform、Ansible、Kubernetes manifests 管理基础设施
- [[Morning Briefing]]:每日 8 AM 自动生成天气/日历/系统状态/任务看板晨报的自动化流程
- [[Email Triage]]AI 自动扫描收件箱,标记待办项,归档噪音邮件
- [[Local-first Git]]:通过私有 Gitea + CI 扫描 pipeline 防止 Agent 直接推送到公共仓库
- [[Defense-in-Depth]]纵深防御AI 安全多层策略——TruffleHog pre-push hooks + 1Password 专用保管库 + 网络分段 + 每日安全审计
## Key Entities
- [[OpenClaw]]multi-agent framework驱动 Reef 基础设施代理的核心平台
- [[K3s]]:轻量级 Kubernetes 发行版Reef 管理的家庭 K8s 集群
- [[Gitea]]:自托管 Git 服务,用于私有代码中转(推送到公共 GitHub 前的 CI 扫描)
- [[TruffleHog]]Git secrets scanning 工具pre-push hooks 必需组件
- [[1Password]]密码保管库Agent 专用 AI vault只读凭证访问
- [[ArgoCD]]GitOps 持续交付工具Reef 监控部署状态的组件
- [[Gatus]]:自托管健康检查工具,与 ArgoCD/服务端点共同构成本地监控层
- [[Loki]]:日志聚合系统,配合监控栈进行日志分析
- [[n8n]]:工作流自动化平台,与 OpenClaw 共同编排复杂工作流
## Connections
- [[Self-Healing-Systems]] ← extends ← [[Agentic AI]]
- [[Morning Briefing]] ← depends_on ← [[OpenClaw]]
- [[Local-first Git]] ← required_by ← [[OpenClaw]]
- [[TruffleHog]] ← part_of ← [[Defense-in-Depth]]
- [[K3s]] ← managed_by ← [[OpenClaw]]
- [[Infrastructure-as-Code]] ← implements ← [[Self-Healing-Systems]]
- [[self-healing-home-server]] ← extends ← [[dynamic-dashboard]](系统健康监控场景)
- [[self-healing-home-server]] ← extends ← [[custom-morning-brief]]Reef 的 Morning Briefing 是 custom-morning-brief 的家庭服务器垂直场景实例)
## Contradictions
- 与 [[家庭监控方案-prometheus-grafana-node-exporter-cadvisor-blackbox]] 的监控方案对比:
- 冲突点:自愈能力 —— Prometheus/Grafana 方案专注于"监控+告警",需要人工介入;本文档方案通过 OpenClaw Agent 实现"检测+诊断+修复"全自动闭环
- 当前观点AI Agent 驱动的自愈系统可以做到"在你知道问题前就修复它"
- 对方观点Prometheus + Alertmanager + 人工 runbook 是更可控的运维模式
## Inspired By
本文档基于 Nathan 的详细文章 [\"Everything I've Done with OpenClaw (So Far)\"](https://madebynathan.com/2026/02/03/everything-ive-done-with-openclaw-so-far/),描述了他的 OpenClaw Agent **Reef** 运行在家庭服务器上,通过 SSH 访问所有机器、管理 K3s 集群、集成 1Password 和 Obsidian vault5000+ 笔记。Reef 运行 15 个活跃 cron job、24 个自定义脚本,自主构建并部署了包括任务管理 UI 在内的多个应用。Nathan 第 1 天 API Key 泄露的惨痛教训:"AI assistants will happily hardcode secrets." 他的纵深防御安全方案TruffleHog pre-push hooks、私有 Gitea、CI 扫描、每日审计)是任何尝试此模式者的必读内容。亦参考 [OpenClaw Showcase](https://openclaw.ai/showcase) 上 `@georgedagg_` 的类似模式:部署监控、日志审查、配置修复和 PR 提交——遛狗时完成。
## Related Links
- [Nathan's Full Writeup](https://madebynathan.com/2026/02/03/everything-ive-done-with-openclaw-so-far/)
- [OpenClaw Documentation](https://github.com/openclaw/openclaw)
- [TruffleHog (Secret Scanning)](https://github.com/trufflesecurity/trufflehog)
- [K3s (Lightweight Kubernetes)](https://k3s.io/)
- [Gitea (Self-hosted Git)](https://gitea.io/)
- [n8n (Workflow Automation)](https://n8n.io/)