Files
claw/README.md
T

177 lines
4.5 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.
# Claw
云主机管理工具,命令行搞定 SSH 连接、脚本执行。
## 目录结构
```
Claw/
├── claw.bat # 入口 (PowerShell 包装器)
├── claw.ps1 # 主控脚本
├── hosts/ # 主机描述文件 (.yml)
├── keys/ # SSH 私钥 (.pem)
├── nginx/ # Nginx 配置 + SSL 证书
└── scripts/ # 可执行脚本 (.sh)
```
## 命令
```cmd
claw list # 列出所有主机
claw ssh <主机名> # SSH 连接
claw run <主机名> <脚本名> # 执行脚本
claw key add <名称> <pem文件路径> # 注册密钥
claw key list # 列出密钥
```
## tx-ubuntu 服务器概况
腾讯云轻量应用服务器 · 北京七区 · 4核4G · SSD 40G + 数据盘 20G
### 用户
| 用户 | 用途 |
|------|------|
| ubuntu | 系统管理、OpenClaw 运维 |
| hugo | Hugo 博客构建 (nginx 托管) |
| cmcc | Work 项目同步 |
| git | Git 裸仓库托管 |
| bitwarden | Vaultwarden 密码服务 |
| gallery | Photoview 相册服务 |
### 服务
| 服务 | 域名 | 用户 | 说明 |
|------|------|------|------|
| Hugo 博客 | `fukun.net` | hugo | `~/hugo-blog` → nginx → public |
| Vaultwarden | `pwd.fukun.net` | bitwarden | Docker 容器 |
| Photoview | `gallery.fukun.net` | gallery | 相册,端口 :8000 |
| Git 仓库 | `git@fukun.net` | git | 裸仓库 `/data/git-repos/Work.git` |
| OpenClaw | — | root | AI 网关,端口 :17581 (内) |
| Nginx | 80/443 | root | 反向代理,www-data worker |
### 磁盘
| 挂载点 | 设备 | 大小 | 用途 |
|--------|------|------|------|
| / | vda2 | 40G | 系统盘 |
| /data | vdb | 20G | 数据盘 (Git/Vaultwarden/Work/Photos) |
### 脚本
| 脚本 | 主机 | 说明 |
|------|------|------|
| sysinfo@tx-ubuntu-ubuntu.sh | ubuntu | 系统健康速览 |
| sync-blog@tx-ubuntu-hugo.sh | hugo | 拉代码 + Hugo 构建 |
| git-repo-create@tx-ubuntu-git.sh | git | 创建裸仓库 |
## 命名格式
### hosts/ — 主机描述
```
<主机标识>-<操作系统>-<用户名>.yml
```
例:`tx-ubuntu-ubuntu.yml` = 腾讯云主机 · Ubuntu · ubuntu 用户
同一台机器的不同用户用独立文件:
```
tx-ubuntu-ubuntu.yml # → 62.234.90.54 用户 ubuntu
tx-ubuntu-hugo.yml # → 62.234.90.54 用户 hugo
tx-ubuntu-cmcc.yml # → 62.234.90.54 用户 cmcc
tx-ubuntu-git.yml # → 62.234.90.54 用户 git
tx-ubuntu-bitwarden.yml # → 62.234.90.54 用户 bitwarden
tx-ubuntu-gallery.yml # → 62.234.90.54 用户 gallery
```
YAML 格式,新建主机复制下面模板改:
```yaml
# ╔══════════════════════════════════════════════════╗
# ║ example · 示例主机 ║
# ╚══════════════════════════════════════════════════╝
host:
ip: 1.2.3.4
user: root
port: 22
key: keys/example-ubuntu-root.pem
info:
name: example-server
id: lhins-xxxxxxxx
status: 运行中
region:
city: 北京
zone: 北京七区
spec:
cpu: 4核
memory: 4GB
disk: SSD云硬盘 40GB
image: Ubuntu 24.04 LTS
network:
public_ip: 1.2.3.4
private_ip: 10.0.0.1
bandwidth: 3Mbps
traffic: 300GB/月
billing:
expire: 2027-01-01
auto_renew: false
```
### scripts/ — 脚本
```
<用途>@<主机名>.sh
```
例:`sysinfo@tx-ubuntu-ubuntu.sh` = 系统信息脚本 → 用于 tx-ubuntu-ubuntu
### keys/ — 密钥
与 hosts 文件名一一对应:
```
tx-ubuntu-ubuntu.pem
tx-ubuntu-hugo.pem
tx-ubuntu-cmcc.pem
tx-ubuntu-git.pem
tx-ubuntu-bitwarden.pem
tx-ubuntu-gallery.pem
```
## 快速开始
```cmd
# 1. 注册密钥
claw key add my-host C:\Users\me\Downloads\key.pem
# 2. 写主机描述 (YAML 格式)
notepad hosts\my-host-ubuntu-root.yml
# 3. 开工
claw ssh my-host-ubuntu-root
claw run my-host-ubuntu-root sysinfo@my-host-ubuntu-root.sh
```
## 全局命令
把项目路径加入 PATH 即可在任何目录使用 `claw`:
```powershell
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";C:\Code\Claw", "User")
```
## TODO
- [x] 域名备案 + nginx 二级域名分流
- `fukun.net` → Hugo 博客
- `pwd.fukun.net` → Vaultwarden
- `gallery.fukun.net` → Photoview 相册
- [ ] 部署 Photoview 相册服务