主题
Linux
概述
Linux 是 OpenClaw 服务器部署的首选平台,支持所有主流发行版。推荐使用 Ubuntu 22.04 LTS 或 Debian 12 作为生产环境。
安装方式
Node.js 安装(推荐)
bash
# 安装 Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash -
sudo apt install -y nodejs
# 验证
node --version # v22.x.x
# 安装 OpenClaw
npm install -g openclaw@latest
# 验证
openclaw --versionDocker 安装
bash
# 使用官方一键脚本
curl -fsSL https://get.openclaw.ai/docker-setup.sh | bash或使用 Docker Compose:
yaml
version: '3.8'
services:
openclaw:
image: openclaw/openclaw:latest
restart: unless-stopped
ports:
- "127.0.0.1:18789:18789"
volumes:
- ~/.openclaw:/root/.openclaw
environment:
- TZ=Asia/Shanghai详见 Docker 安装。
系统服务配置
Systemd 服务(推荐)
使用 OpenClaw 内置命令自动创建服务:
bash
openclaw onboard --install-daemon或手动创建服务文件:
ini
# /etc/systemd/system/openclaw.service
[Unit]
Description=OpenClaw Gateway
After=network.target
[Service]
Type=simple
User=openclaw
WorkingDirectory=/home/openclaw
ExecStart=/usr/local/bin/openclaw gateway start
Restart=always
RestartSec=10
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.targetbash
# 启用并启动服务
sudo systemctl enable openclaw
sudo systemctl start openclaw
# 查看状态
sudo systemctl status openclaw
# 查看日志
sudo journalctl -u openclaw -f创建专用用户
生产环境建议使用专用用户运行 OpenClaw:
bash
# 创建用户
sudo useradd -m -s /bin/bash openclaw
# 切换到该用户安装
sudo -u openclaw bash
npm install -g openclaw@latest
openclaw onboard防火墙配置
bash
# 使用 UFW
sudo ufw allow ssh
sudo ufw allow 18789/tcp # 仅在需要远程访问时开启
sudo ufw enable
# 建议:仅绑定 localhost,通过反代或 Tailscale 暴露
openclaw config set gateway.port 18789
openclaw config set gateway.host "127.0.0.1"反向代理
Nginx 配置
nginx
server {
listen 443 ssl;
server_name openclaw.example.com;
ssl_certificate /etc/letsencrypt/live/openclaw.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/openclaw.example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:18789;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}性能优化
系统要求
| 配置 | 最低 | 推荐 |
|---|---|---|
| CPU | 1 核 | 2 核+ |
| 内存 | 1 GB | 4 GB+ |
| 磁盘 | 10 GB | 40 GB SSD |
| 网络 | 1 Mbps | 10 Mbps+ |
调优建议
- 内存:OpenClaw 本身占用不大(~200MB),但如果启用浏览器工具(Puppeteer)需要额外内存
- 磁盘:会话历史和记忆文件会逐渐增长,建议定期清理 30 天以前的日志
- 交换分区:小内存 VPS 建议开启 2GB swap
bash
# 创建 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常用运维命令
bash
# 查看状态
openclaw status --deep
# 诊断问题
openclaw doctor
# 实时日志
openclaw logs --follow
# 重启网关
openclaw gateway restart
# 备份工作区
tar -czf openclaw-backup-$(date +%Y%m%d).tar.gz ~/.openclaw/
# 清理旧会话
find ~/.openclaw/workspace/memory/ -name "*.md" -mtime +30 -delete发行版支持
| 发行版 | 状态 | 备注 |
|---|---|---|
| Ubuntu 22.04/24.04 | ✅ 完整支持 | 推荐 |
| Debian 11/12 | ✅ 完整支持 | 推荐 |
| CentOS Stream 9 | ✅ 支持 | 需手动安装 Node.js |
| Fedora 38+ | ✅ 支持 | |
| Arch Linux | ✅ 支持 | 滚动更新,注意兼容性 |
| Alpine | ✅ 支持 | Docker 镜像基础 |
| openSUSE | ⚠️ 社区支持 | 未官方测试 |