Hetzner 部署
在 Hetzner Cloud 上部署 OpenClaw
概述
Hetzner 是一家德国云服务提供商,以高性价比著称。 其 VPS 价格远低于 AWS、GCP 等大厂,非常适合个人和小团队部署 OpenClaw。
高性价比
€3.79/月起,性价比极高
欧洲机房
德国、芬兰机房可选
高性能
NVMe SSD,高速网络
推荐配置
| 用途 | 型号 | 配置 | 价格 |
|---|---|---|---|
| 个人使用 | CX11 | 1 vCPU, 2GB RAM | €3.79/月 |
| 推荐 | CX21 | 2 vCPU, 4GB RAM | €5.83/月 |
| 多用户 | CX31 | 2 vCPU, 8GB RAM | €10.59/月 |
创建服务器
步骤 1: 注册账户
- 访问 Hetzner Cloud
- 注册账户并完成验证
- 添加支付方式
步骤 2: 创建项目
- 登录 Hetzner Cloud Console
- 创建新项目(如 "OpenClaw")
步骤 3: 创建服务器
- 点击 "Add Server"
- 选择位置(推荐 Falkenstein 或 Helsinki)
- 选择镜像:Ubuntu 22.04
- 选择类型:CX21(推荐)
- 添加 SSH Key(强烈推荐)
- 点击 "Create & Buy now"
使用 CLI 创建
# 安装 hcloud CLI
brew install hcloud
# 配置 API Token
hcloud context create openclaw
# 创建服务器
hcloud server create \
--name openclaw \
--type cx21 \
--image ubuntu-22.04 \
--location fsn1 \
--ssh-key your-key-name安装配置
连接服务器
ssh root@your-server-ip系统更新
apt update && apt upgrade -y安装 Node.js
# 安装 Node.js 20
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
# 验证
node --version安装 OpenClaw
# 安装 OpenClaw
npm install -g openclaw
# 初始化配置
openclaw init
# 配置 API Key
openclaw config set anthropic.api_key "sk-..."
# 配置频道(如 Telegram)
openclaw telegram setup测试运行
# 前台运行测试
openclaw gateway
# 测试成功后 Ctrl+C 停止系统服务
使用 systemd 让 OpenClaw 作为系统服务运行:
创建服务文件
cat > /etc/systemd/system/openclaw.service << 'EOF'
[Unit]
Description=OpenClaw Gateway
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/root
ExecStart=/usr/bin/openclaw gateway
Restart=always
RestartSec=10
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
EOF启动服务
# 重载 systemd
systemctl daemon-reload
# 启动服务
systemctl start openclaw
# 开机自启
systemctl enable openclaw
# 查看状态
systemctl status openclaw查看日志
# 实时日志
journalctl -u openclaw -f
# 最近日志
journalctl -u openclaw --since "1 hour ago"安全设置
配置防火墙
# 安装 ufw
apt install -y ufw
# 允许 SSH
ufw allow ssh
# 如果需要外部访问 Gateway API
ufw allow 8080/tcp
# 启用防火墙
ufw enable创建非 root 用户
# 创建用户
adduser openclaw
# 添加 sudo 权限
usermod -aG sudo openclaw
# 切换用户
su - openclaw配置 SSH
# 编辑 SSH 配置
nano /etc/ssh/sshd_config
# 推荐设置:
# PermitRootLogin no
# PasswordAuthentication no
# 重启 SSH
systemctl restart sshd监控管理
Hetzner Cloud Metrics
Hetzner Console 提供基本的 CPU、内存、网络监控。
安装监控工具
# 安装 htop
apt install -y htop
# 查看资源使用
htop配置自动更新
# 安装 unattended-upgrades
apt install -y unattended-upgrades
# 启用自动安全更新
dpkg-reconfigure -plow unattended-upgrades设置备份
在 Hetzner Console 中启用自动快照:
- 进入服务器详情
- 点击 "Snapshots"
- 启用自动快照