🍀 简窝 Blog
📃 文章详情

Moltbot (OpenClaw) 完整部署指南

1. 环境要求

  • 操作系统:Ubuntu 20.04+ / Debian 11+ / Rocky Linux 8+
  • Node.js:v22.22.0 或更高
  • 内存:至少 2GB RAM
  • 磁盘:至少 10GB 可用空间

不兼容环境:

  • CentOS 7(系统库过旧,GLIBC 不足)
  • Node.js ​< v22(OpenClaw 要求 Node 22+)

检查命令:

# 检查系统版本
cat /etc/os-release

# 检查 Node.js 版本
node -v

# 检查内存
free -h

2. 安装步骤

# 方法一:官方安装脚本(推荐)
curl -fsSL https://openclaw.ai/install.sh | bash

# 方法二:npm 全局安装
npm install -g moltbot@latest

PATH 配置:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
openclaw --version

初始化:

openclaw configure
# 或
openclaw doctor --fix

3. 阿里云百炼配置

  1. 登录 阿里云百炼平台,在「密钥管理」创建 API Key(格式:sk-xxxxxxxxxxxxx)。
  2. 设置环境变量:
export DASHSCOPE_API_KEY='sk-xxxxxxxxxxxxx'
echo "export DASHSCOPE_API_KEY='sk-xxxxxxxxxxxxx'" >> ~/.bashrc
source ~/.bashrc
  1. ~/.openclaw/openclaw.json 中配置 gatewayagentsmodels(含 bailian 的 baseUrl、apiKey、模型 id 等),并生成 Gateway Token:
openssl rand -hex 32

将生成的 token 填入配置中的 gateway.auth.token


4. Gateway 配置

  • 编辑 systemd 服务(如 ~/.config/systemd/user/openclaw-gateway.service),在 [Service] 中设置:
    • Environment="DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxx"
    • Environment="OPENCLAW_GATEWAY_TOKEN=YOUR_TOKEN"
    • 以及 PATHOPENCLAW_GATEWAY_PORT=18789 等。
  • 重载并启动:
systemctl --user daemon-reload
systemctl --user enable openclaw-gateway
systemctl --user start openclaw-gateway
systemctl --user status openclaw-gateway

5. Web UI 访问

  • HTTP(局域网):在配置中设置 gateway.controlUi.allowInsecureAuth: true,重启 Gateway,访问 http://服务器IP:18789/,首次需输入 Gateway Token。
  • SSH 隧道:本地执行​ssh -N -L 18789:127.0.0.1:18789 root@服务器IP,浏览器访问 http://localhost:18789/
  • 生产环境:建议用 Nginx 反向代理并配置 HTTPS。

6. 常用命令

  • Gateway:openclaw gateway start/stop/restart/status
  • 发消息:openclaw agent --message "你好"
  • 模型:openclaw models listopenclaw models status --probe
  • 配置:openclaw config set gateway.mode local 等,查看:cat ~/.openclaw/openclaw.json

7. 故障排查(摘要)

  • Gateway 无法启动:查 journalctl --user -u openclaw-gateway.service/tmp/openclaw/*.log;确认 DASHSCOPE_API_KEYgateway.mode=localgateway.auth.token 已配置。
  • 模型不识别:检查 ~/.openclaw/openclaw.jsonmodels.providers 和 agent 的 models.json
  • 无法访问 Web UI:检查端口监听、防火墙、allowInsecureAuth,或使用 SSH 隧道。
  • 收到内置回复而非百炼回复:检查 ~/.openclaw/agents/main/agent.jsonmodel 是否为 bailian/qwen3-max-2026-01-23,并重启 Gateway。

8. 注意事项

  • 安全:勿在公网暴露 API Key 和 Gateway Token;生产建议 HTTPS + 防火墙。
  • 成本:关注百炼定价与用量,按需选模型。
  • 维护:日志在 /tmp/openclaw/journalctl --user -u openclaw-gateway;定期备份 ~/.openclaw/openclaw.json~/.openclaw/agents

9. 问题修复方案(摘要)

  • CentOS 7 不兼容:升级到 Rocky/Alma 8+ 或换 Ubuntu/Debian,或用 Docker 部署。
  • openclaw 命令找不到export PATH="$HOME/.local/bin:$PATH" 并写入 .bashrc,或 sudo ln -sf ~/.local/bin/openclaw /usr/local/bin/openclaw
  • 环境变量未生效:在 systemd 的 [Service] 里显式写 Environment="DASHSCOPE_API_KEY=...",或在 openclaw.jsonmodels.providers.bailian.apiKey 里直接写 Key。
  • 仅本机可访问:设置 gateway.bind: "lan" 并重启。
  • 浏览器安全策略:局域网用 allowInsecureAuth: true,或 SSH 隧道,或 Nginx HTTPS。
  • Agent 用错模型:在 ~/.openclaw/agents/main/agent.json 中指定 "model": "bailian/qwen3-max-2026-01-23"

10. 快速部署脚本

原文提供了一整段 deploy-moltbot.sh 脚本,主要步骤包括:检查系统与 Node、配置 PATH、验证 openclaw、生成 Gateway Token、创建 ~/.openclaw/openclaw.json(含 gateway/agents/models)、配置 systemd 服务、创建 agents/main/agent.json、启动并验证 Gateway 与端口 18789。
使用方式:

chmod +x deploy-moltbot.sh
./deploy-moltbot.sh

运行时会提示输入阿里云百炼 API Key。


参考链接

  • OpenClaw 官方文档:https://docs.openclaw.ai/
  • 阿里云百炼:https://bailian.console.aliyun.com
  • 故障排查:https://docs.openclaw.ai/troubleshooting
  • GitHub:https://github.com/moltbot/moltbot

📑 目录