综合整理自官方新手指南、内网部署实践、云服务器部署指南及 Skills 安装说明。
一、安装 OpenClaw
系统要求
- Node.js ≥ 22(必须)
- 操作系统:macOS / Linux / Windows WSL2
- 内存建议 4GB+,磁盘 5GB+
安装 Node.js(Ubuntu)
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs
node --version # 应显示 v22.x.x
国内 npm 加速(可选):
npm config set registry https://registry.npmmirror.com
安装 OpenClaw
# 方式一:一键脚本(推荐)
curl -fsSL https://openclaw.ai/install.sh | bash
# 方式二:npm
npm install -g openclaw@latest
# 方式三:pnpm(内存占用更低)
pnpm add -g openclaw@latest
修复 PATH(Ubuntu 常见问题)
echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
二、初始化配置
# 完整引导向导 + 安装系统服务(推荐)
openclaw onboard --install-daemon
# 仅运行配置向导
openclaw onboard
# 分段配置
openclaw configure
openclaw configure --section model
openclaw configure --section gateway
三、Gateway 管理
# 启动(前台调试)
openclaw gateway --port 18789 --verbose
# 启动/停止/重启(守护进程)
openclaw gateway start
openclaw gateway stop
openclaw gateway restart
# 强制重启(2026.3.x 版本用此命令)
openclaw gateway --force
# 查看状态
openclaw gateway status
# 健康检查
openclaw health
# 查看监听端口
sudo ss -ltnp | grep 18789
# 查看日志
openclaw logs --follow
openclaw logs --level warn
四、内网多设备访问配置
4.1 修改 bind 为 LAN
openclaw configure --section gateway
# 选择:Gateway bind mode → LAN (All interfaces)
# 选择:Gateway auth → Password(设置强密码)
4.2 修改 ~/.openclaw/openclaw.json(关键)
内网 HTTP 直连需在 gateway.controlUi 下添加以下字段:
"gateway": {
"port": 18789,
"mode": "local",
"bind": "lan",
"auth": {
"mode": "password",
"password": "请改成强密码"
},
"controlUi": {
"allowInsecureAuth": true,
"dangerouslyDisableDeviceAuth": true,
"allowedOrigins": [
"http://10.0.0.82:18789"
]
}
}
⚠️ allowInsecureAuth 和 dangerouslyDisableDeviceAuth 必须写在 gateway.controlUi 下,不是 gateway 顶层。
4.3 防火墙放行
sudo ufw allow 18789/tcp
sudo ufw reload
sudo ufw status
4.4 内网访问地址
http://10.0.0.82:18789/chat?session=main
4.5 SSH 隧道方式(替代方案)
ssh -N -L 18789:127.0.0.1:18789 user@10.0.0.82
五、云服务器(外网)部署要点
创建 Swap(2GB 内存机器必做)
fallocate -l 4G ~/swapfile
chmod 600 ~/swapfile
sudo mkswap ~/swapfile
echo "$HOME/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
sudo swapon --all
free -h # 验证
安装系统依赖
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl wget git libatomic1 ufw
系统服务化(开机自启)
# 查看服务状态
systemctl --user status openclaw
# 设置开机自启(关键)
sudo loginctl enable-linger $USER
Nginx 反向代理(生产环境)
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";
}
六、Skills 安装
# 安装 ClawHub CLI
npm install -g clawhub
# 搜索技能
clawhub search "weather"
clawhub search "image generation"
# 安装技能
clawhub install weather
clawhub install baoyu-image-gen
npx clawhub@latest install {技能名称} # 无需全局安装时用此方式
# 管理技能
clawhub list # 列出已安装
clawhub update weather # 更新指定技能
clawhub update --all # 更新全部
clawhub update --force # 强制更新
# 手动安装自定义 Skill(将文件放入指定目录)
cd ~/.openclaw/workspace/skills
# 在此创建技能目录和 SKILL.md 文件即可,无需重启
七、常见问题修复
模型 contextWindow 被限制为 4096
vi ~/.openclaw/openclaw.json
# 找到对应模型,修改:
# "contextWindow": 131072,
# "maxTokens": 16384
重启网关使配置生效
openclaw gateway --force
诊断与自动修复
openclaw doctor
openclaw doctor --fix
八、常用配置速查
| 场景 | 命令 |
|---|---|
| 查看 dashboard token | openclaw dashboard --no-open |
| 修改配置项 | openclaw config set agents.defaults.model.primary "openai/gpt-5.2" |
| 存储 API Key | openclaw vault set ANTHROPIC_API_KEY sk-ant-... |
| 打开控制面板 | openclaw dashboard |
| 重置会话 | 在对话中发送 /new |