3.0 KiB
3.0 KiB
Claw
云主机管理工具,命令行搞定 SSH 连接、脚本执行。
目录结构
Claw/
├── claw.bat # 入口 (PowerShell 包装器)
├── claw.ps1 # 主控脚本
├── hosts/ # 主机描述文件 (.yml)
├── keys/ # SSH 私钥 (.pem)
└── scripts/ # 可执行脚本 (.sh)
命令
claw list # 列出所有主机
claw ssh <主机名> # SSH 连接
claw run <主机名> <脚本名> # 执行脚本
claw key add <名称> <pem文件路径> # 注册密钥
claw key list # 列出密钥
命名格式
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
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
快速开始
# 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:
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";C:\Code\Claw", "User")
TODO
- 域名备案完成后 nginx 二级域名分流
blog.fukun.net→ Hugo 博客 (:443)vault.fukun.net→ Vaultwarden (:8443)git.fukun.net→ Git 仓库- 全部统一 443 nginx 按 server_name 分发