Linux 服务器部署 OpenClaw
在任意 VPS 上通过命令行部署 OpenClaw
服务器推荐
| 提供商 | 价格 | 特点 |
|---|---|---|
| DigitalOcean | $6/月起 | 简单易用,全球节点 |
| Hetzner | €4/月起 | 性价比高,德国/芬兰 |
| Vultr | $5/月起 | 全球节点,按小时计费 |
| Hostinger | $4/月起 | 便宜,适合入门 |
系统要求
- Ubuntu 20.04+ / Debian 11+ / CentOS 8+
- Node.js 22+
- 2GB+ RAM(建议 4GB)
- 20GB+ 可用磁盘空间
部署步骤
1SSH 登录服务器
ssh root@你的服务器IP
2更新系统
# Ubuntu/Debian
apt update && apt upgrade -y
# CentOS
yum update -y
3安装 Node.js 22
# 方法1: 使用 nodesource
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs
# 方法2: 使用 nvm(推荐)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 22
4安装 OpenClaw
curl -fsSL https://openclaw.ai/install.sh | bash
安装程序会自动:
- 检测 Node.js 版本
- 下载最新 OpenClaw
- 创建配置目录
5初始化配置
openclaw onboard
按提示完成:
- 输入 API Key
- 选择 AI 模型
- 配置聊天平台
6配置防火墙
# Ubuntu (ufw)
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw deny 18789/tcp
sudo ufw enable
# CentOS (firewalld)
sudo firewall-cmd --permanent --add-port=22/tcp
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=443/tcp
sudo firewall-cmd --permanent --add-port=18789/tcp --remove
sudo firewall-cmd --reload
7配置 Systemd 服务(可选)
sudo tee /etc/systemd/system/openclaw.service > /dev/null <
⚠️ 内存不足解决方案
如果服务器内存小于 2GB,需要创建 Swap:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
常用命令
# 启动
openclaw start
# 停止
openclaw stop
# 重启
openclaw restart
# 查看状态
openclaw status
# 查看日志
openclaw logs -f
# 更新
openclaw update
配置 HTTPS(可选)
使用 Caddy 自动配置 SSL:
# 安装 Caddy
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian-versioned.gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-versioned-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/caddy/stable/debian any-version" | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
# 配置反向代理
sudo cat > /etc/caddy/Caddyfile <