← 返回首页

如何在 Linux 系统下部署 OpenClaw

从零开始,在 Linux 服务器上安装配置 OpenClaw,打造你的 AI 自动化助手

2026年3月14日
OpenClawLinux部署教程AI 助手

如何在 Linux 系统下部署 OpenClaw

💡 本文适合人群:想要在 Linux 服务器上部署 OpenClaw 的开发者,实现自动化任务管理和 AI 助手功能。

📋 前言

OpenClaw 是一个强大的自动化框架,可以帮助你管理任务、连接各种服务(如 Feishu、Telegram 等),并通过 AI 实现智能自动化。

本教程将带你完成

  • 环境准备
  • Node.js 安装
  • OpenClaw 安装配置
  • 连接 Feishu 服务
  • 部署到生产环境

🚀 第一步:环境准备

1.1 系统要求

  • 操作系统:Linux(Ubuntu/CentOS/OpenCloudOS 等)
  • 内存:至少 2GB RAM
  • 磁盘:至少 10GB 可用空间
  • 网络:可以访问外网(用于下载依赖和连接服务)

1.2 检查系统信息

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

# 查看内存
free -h

# 查看磁盘空间
df -h

📦 第二步:安装 Node.js

OpenClaw 基于 Node.js 开发,需要 Node.js 18 或更高版本。

2.1 使用 nvm 安装(推荐)

# 安装 nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# 加载 nvm
source ~/.bashrc

# 验证 nvm 安装
nvm --version

# 安装 Node.js 22 LTS
nvm install 22
nvm use 22

# 设置默认版本
nvm alias default 22

# 验证安装
node --version
npm --version

2.2 验证安装

node -v  # 应该显示 v22.x.x
npm -v   # 应该显示 10.x.x

🔧 第三步:安装 OpenClaw

3.1 全局安装 OpenClaw

npm install -g openclaw

3.2 验证安装

openclaw --version
openclaw help

3.3 初始化工作区

# 创建工作目录
mkdir -p ~/openclaw-workspace
cd ~/openclaw-workspace

# 初始化 OpenClaw
openclaw init

⚙️ 第四步:配置 OpenClaw

4.1 创建配置文件

在工作区创建 config.json

{
  "gateway": {
    "port": 8080,
    "host": "0.0.0.0"
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxxxxxxx",
      "encryptKey": "xxxxxxxxxxxxxxxxxxxxx",
      "verificationToken": "xxxxxxxxxxxxxxxxxxxxx"
    }
  },
  "models": {
    "default": "bailian/qwen3.5-plus",
    "bailian": {
      "apiKey": "sk-xxxxxxxxxxxxxxxxxxxxx"
    }
  }
}

4.2 获取 Feishu 应用凭证

  1. 访问 Feishu 开发者后台
  2. 创建企业自建应用
  3. 获取 App IDApp Secret
  4. 配置事件订阅,获取 Encrypt KeyVerification Token
  5. 添加机器人权限

4.3 配置阿里云百炼模型

  1. 访问 阿里云百炼
  2. 创建 API Key
  3. 将 API Key 填入配置文件

🌐 第五步:配置 Nginx 反向代理(可选)

如果需要外网访问,配置 Nginx 反向代理:

5.1 安装 Nginx

# Ubuntu/Debian
sudo apt update
sudo apt install nginx

# CentOS/OpenCloudOS
sudo yum install nginx

5.2 配置 Nginx

创建 /etc/nginx/conf.d/openclaw.conf

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:8080;
        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;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_cache_bypass $http_upgrade;
    }
}

5.3 重启 Nginx

sudo nginx -t
sudo systemctl restart nginx

🔒 第六步:配置 HTTPS(推荐)

6.1 安装 Certbot

# Ubuntu/Debian
sudo apt install certbot python3-certbot-nginx

# CentOS/OpenCloudOS
sudo yum install certbot python3-certbot-nginx

6.2 申请证书

sudo certbot --nginx -d your-domain.com

6.3 自动续期

Certbot 会自动配置定时任务,证书会在到期前自动续期。


🚀 第七步:启动 OpenClaw

7.1 使用 PM2 管理进程

# 安装 PM2
npm install -g pm2

# 启动 OpenClaw Gateway
cd ~/openclaw-workspace
pm2 start $(which openclaw) --name openclaw -- gateway start

# 查看状态
pm2 status

# 查看日志
pm2 logs openclaw

7.2 设置开机自启

# 配置 PM2 开机自启
pm2 startup

# 保存当前进程列表
pm2 save

✅ 第八步:验证部署

8.1 检查服务状态

# 检查 Gateway 状态
openclaw gateway status

# 检查 PM2 进程
pm2 status openclaw

8.2 测试连接

在 Feishu 群聊中添加机器人,发送消息测试:

你好

如果机器人回复,说明部署成功!


📝 常用命令

OpenClaw 命令

# 查看帮助
openclaw help

# Gateway 管理
openclaw gateway status
openclaw gateway start
openclaw gateway stop
openclaw gateway restart

# 查看日志
openclaw gateway logs

PM2 命令

# 查看所有进程
pm2 status

# 重启应用
pm2 restart openclaw

# 查看日志
pm2 logs openclaw

# 停止应用
pm2 stop openclaw

# 删除应用
pm2 delete openclaw

🔧 故障排查

问题 1:Gateway 无法启动

# 检查端口占用
netstat -tlnp | grep 8080

# 查看日志
pm2 logs openclaw --lines 100

问题 2:Feishu 消息不响应

  1. 检查 Feishu 应用配置是否正确
  2. 确认事件订阅已启用
  3. 检查机器人是否已添加到群聊
  4. 查看 Gateway 日志是否有错误

问题 3:模型调用失败

  1. 检查 API Key 是否正确
  2. 确认账户有足够余额
  3. 检查网络连接

🎯 进阶配置

添加更多渠道

OpenClaw 支持多种消息渠道:

{
  "channels": {
    "feishu": { /* ... */ },
    "telegram": {
      "enabled": true,
      "botToken": "xxxxxxxxxxxxxxxxxxxxx"
    },
    "discord": {
      "enabled": true,
      "token": "xxxxxxxxxxxxxxxxxxxxx"
    }
  }
}

配置多个模型

{
  "models": {
    "default": "bailian/qwen3.5-plus",
    "bailian": { /* ... */ },
    "openai": {
      "apiKey": "sk-xxxxxxxxxxxxxxxxxxxxx"
    }
  }
}

📚 总结

通过以上步骤,你已经成功在 Linux 服务器上部署了 OpenClaw:

✅ Node.js 环境配置
✅ OpenClaw 安装与配置
✅ Feishu 机器人连接
✅ Nginx 反向代理
✅ HTTPS 安全配置
✅ PM2 进程管理

接下来你可以

  • 创建自动化工作流
  • 连接更多服务
  • 配置自定义技能
  • 搭建 AI 助手

相关资源


祝你使用愉快! 🎉