跳到主要内容OpenClaw 本地部署教程:环境配置、插件开发与常见问题排查 | 极客日志TypeScriptNode.jsAI
OpenClaw 本地部署教程:环境配置、插件开发与常见问题排查
综述由AI生成介绍如何在低配置电脑上本地部署 OpenClaw AI 助手,涵盖 Node.js、Python、Ollama 等环境搭建,提供 Windows 与 Ubuntu 系统下的详细指令。内容包含配置文件修改、本地模型选择、TypeScript 插件开发流程及打包安装方法。此外,汇总了启动失败、依赖超时、内存不足等常见问题的排查方案,旨在帮助用户实现自动化办公任务。
灭霸27 浏览 前言
本文基于 OpenClaw 最新版本编写,适配低配置场景(最低 2vCPU+2GiB 内存 +40GiB SSD),兼容 Windows 10/11(优先 WSL2)、Ubuntu 20.04+ 系统。内容覆盖环境配置、本地部署、插件开发及高频问题排查,重点解决部署卡顿、国内网络适配、插件开发思路及报错排查等问题。全程适配国内镜像源及大模型,无需海外代理。
一、前置准备(适配优化)
1.1 硬件要求(最低适配)
- CPU:Intel i3 4 代+/AMD Ryzen 3 2000+(支持虚拟化,需在 BIOS 中开启)
- 内存:最低 2GiB(建议 4GiB,开启轻量化配置可适配 2GiB)
- 存储:最低 40GiB SSD(机械硬盘需优化读写)
- 系统:Windows 10 64 位+/Ubuntu 20.04 LTS 64 位+
1.2 必备工具与依赖
核心依赖:Node.js v22+、Git、pnpm、Python 3.10-3.11(禁止 3.12+,避免依赖冲突)、Ollama v0.15.4+(本地模型运行核心)
1.2.1 Windows 系统(优先 WSL2,无 WSL2 则用原生系统)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Get-ExecutionPolicy -List
iwr -useb https://registry.npmmirror.com/binary.html?path=node/v22.0.0/node-v22.0.0-x64.msi -OutFile node-v22.0.0-x64.msi
.
ode-v22.0.0-x64.msi /quiet
node -v
npm -v
npm config set registry https://registry.npmmirror.com
npm config set puppeteer_download_host https://registry.npmmirror.com/binary.html?path=chromium-browser-snapshots/
iwr -useb https://registry.npmmirror.com/binary.html?path=git-for-windows/v2.43.0.windows.1/Git-2.43.0-64-bit.exe -OutFile Git-2.43.0-64-bit.exe
.
Git-2.43.0-64-bit.exe /silent /norestart
git --version
iwr -useb https://mirrors.aliyun.com/python/3.10/python-3.10.11-amd64.exe -OutFile python-3.10.11-amd64.exe
.
python-3.10.11-amd64.exe /quiet InstallAllUsers=1 PrependPath=1
python --version
pip --version
mkdir %APPDATA%\pip
> %APPDATA%\pip\pip.ini
pip install pip -U
winget install ollama
ollama --version
echo
"[global] index-url = https://mirrors.aliyun.com/pypi/simple/ [install] trusted-host = mirrors.aliyun.com timeout = 60"
1.2.2 Ubuntu 系统(含 WSL2,轻量化首选)
sudo apt update && sudo apt install -y curl git build-essential --no-install-recommends
curl -fsSL https://registry.npmmirror.com/binary.html?path=node/v22.0.0/node-v22.0.0-linux-x64.tar.xz | sudo tar -xJ -C /usr/local/
echo "export PATH=/usr/local/node-v22.0.0-linux-x64/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
node -v
npm -v
npm config set registry https://registry.npmmirror.com
npm config set puppeteer_download_host https://registry.npmmirror.com/binary.html?path=chromium-browser-snapshots/
sudo apt install -y python3.10 python3.10-pip python3.10-venv --no-install-recommends
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
python3 --version
mkdir -p ~/.config/pip
echo "[global] index-url = https://mirrors.aliyun.com/pypi/simple/ [install] trusted-host = mirrors.aliyun.com timeout = 60" > ~/.config/pip/pip.conf
pip3 install pip -U
curl -fsSL https://ollama.com/install.sh | sh
ollama --version
1.3 API Key 获取(国内大模型,无联网也可跳过,用本地模型)
优先选择阿里通义千问(免费额度足,国内直连,无压力),步骤如下(纯操作):
start https://dashscope.aliyun.com/
xdg-open https://dashscope.aliyun.com/
1.4 轻量化优化(核心,解决卡顿、内存不足)
taskkill /f /im chrome.exe /im qq.exe /im wechat.exe
wmic pagefileset where name='C:\pagefile.sys' set InitialSize=4096,MaximumSize=8192
sc config wuauserv start= disabled
sc stop wuauserv
sudo systemctl stop cron.service bluetooth.service --no-block
echo "* soft memlock 2097152" >> /etc/security/limits.conf
echo "* hard memlock 2097152" >> /etc/security/limits.conf
sudo sysctl -w vm.dirty_ratio=5
sudo sysctl -w vm.dirty_background_ratio=2
二、OpenClaw 核心部署(最新版本)
核心说明:OpenClaw 当前版本已更新,旧版本命令全部失效,需按以下步骤全新安装,禁止混合旧版本文件。
2.1 克隆 OpenClaw 最新源码(国内镜像)
mkdir D:\OpenClaw && cd D:\OpenClaw
mkdir ~/openclaw && cd ~/openclaw
git clone https://github.moeyy.xyz/https://github.com/openclaw/openclaw.git
cd openclaw
2.2 安装项目依赖(国内源加速)
npm install -g pnpm --registry https://registry.npmmirror.com
pnpm -v
pnpm install --registry https://registry.npmmirror.com --no-optional
pip3 install dashscope requests pyyaml python-dotenv -i https://mirrors.aliyun.com/pypi/simple/
2.3 核心配置(本地模型/在线模型二选一)
配置文件为项目根目录 config.yaml,对缩进敏感,直接复制以下内容,仅修改 API Key(在线模型)或模型名称(本地模型)即可。
notepad config.yaml
vim config.yaml
bot:
name: OpenClaw-AI-Employee
version: 2026.1.30
language: zh-CN
memory:
enabled: true
max_size: 100
model:
type: local
online:
api_key: "你的通义千问 API Key"
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
model: "qwen-turbo"
local:
model: "ministral-3:8b"
ollama_url: "http://localhost:11434"
gateway:
port: 18789
enabled: true
lightweight: true
skills:
enabled: true
auto_load: true
max_concurrent: 2
2.4 本地模型部署(无联网必做,Ollama)
ollama pull ministral-3:8b
ollama pull llama3:8b-instruct-q4_0
start /b ollama serve
nohup ollama serve > ollama.log 2>&1 &
curl http://localhost:11434/api/version
2.5 启动 OpenClaw 服务
pnpm start:lightweight
nohup pnpm start:lightweight > openclaw.log 2>&1 &
start http://127.0.0.1:18789/
xdg-open http://127.0.0.1:18789/
curl http://localhost:18789/health
pnpm run test:agent -- --message "列出当前目录下所有文件"
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "OpenClaw" -Value "D:\OpenClaw\openclaw\node_modules\.bin\pnpm start:lightweight"
echo "nohup pnpm start:lightweight > ~/openclaw/openclaw.log 2>&1 &" >> ~/.bashrc
2.6 部署验证(必做,确保 AI 员工可正常工作)
pnpm run agent -- --message "在当前目录创建 test 文件夹,新建 3 个 txt 文件,分别命名为 file1.txt、file2.txt、file3.txt"
echo "OpenClaw 是热门开源 AI 助手,可本地部署,适配,实现自动化办公" > test.txt
pnpm run agent -- --message "总结 test.txt 文件的内容,不超过 50 字"
pnpm run agent -- --message "介绍你自己,用中文,简洁明了"
三、OpenClaw 插件开发
核心说明:OpenClaw 插件基于 TypeScript(ESM)开发,遵循 Oxlint/Oxfmt 规范,采用 AgentSkills 标准格式,通过 SKILL.md 定义功能,开发无需高配置,插件体积控制在 100KB 以内即可正常运行。以下以'文件批量压缩插件'为例(高频需求),全程实操,可直接复制代码。
3.1 插件开发环境准备
pnpm install -D typescript @types/node oxlint oxfmt --registry https://registry.npmmirror.com
npx tsc --init --target ES6 --module ESNext --outDir dist --rootDir src
mkdir -p src/plugins/compress-files
cd src/plugins/compress-files
touch index.ts SKILL.md package.json .eslintrc.js
3.2 插件核心代码编写(批量压缩文件)
3.2.1 package.json(插件配置,固定格式)
{
"name": "compress-files-plugin",
"version": "1.0.0",
"description": "OpenClaw 文件批量压缩插件,支持 zip 格式,轻量化无冗余",
"main": "dist/index.js",
"type": "module",
"dependencies": {
"archiver": "^7.0.1" # 轻量压缩库,无压力
},
"devDependencies": {
"@types/archiver": "^6.0.2"
}
}
3.2.2 SKILL.md(插件功能定义,AI 识别核心)
# 插件名称:文件批量压缩插件(compress-files-plugin)
# 插件功能:批量压缩指定目录下的文件/文件夹,生成 zip 压缩包,适配低配置
# 适用场景:文件整理、空间释放
# 输入参数:
# - dirPath:必填,需要压缩的目录路径(绝对路径/相对路径均可)
# - zipName:必填,压缩包名称(无需加.zip 后缀)
# - ignore:可选,需要忽略的文件/文件夹(数组格式,如 ["node_modules", "*.log"])
# 输出结果:压缩包保存路径、压缩大小、耗时
# 异常处理:目录不存在、无权限时,返回明确报错信息,不崩溃
# 优化:禁用多线程压缩,降低 CPU 占用
3.2.3 index.ts(核心逻辑,TypeScript,轻量化)
import fs from 'fs';
import path from 'path';
import archiver from 'archiver';
export class CompressFilesPlugin {
public static pluginId = 'compress-files-plugin';
public static version = '1.0.0';
private static readonly isLightweight = true;
public async execute(params: { dirPath: string; zipName: string; ignore?: string[]; }): Promise<{ success: boolean; data?: any; error?: string }> {
try {
const { dirPath, zipName, ignore = [] } = params;
if (!fs.existsSync(dirPath)) {
return { success: false, error: `目录不存在:${dirPath}` };
}
const absoluteDirPath = path.resolve(dirPath);
const zipPath = path.resolve(`${zipName}.zip`);
const output = fs.createWriteStream(zipPath);
const archive = archiver('zip', {
zlib: { level: 1 },
...(CompressFilesPlugin.isLightweight && { highWaterMark: 64 * 1024 }),
});
output.on('close', () => {});
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
console.warn(`压缩警告:${err.message}`);
} else {
throw err;
}
});
archive.on('error', (err) => {
throw err;
});
archive.pipe(output);
archive.directory(absoluteDirPath, false, (entry) => {
const isIgnore = ignore.some((ignoreItem) => {
if (ignoreItem.startsWith('*.')) {
const ext = path.extname(entry.name);
return ext === ignoreItem.slice(1);
} else {
return entry.name === ignoreItem || entry.name.includes(ignoreItem);
}
});
return !isIgnore;
});
await archive.finalize();
const zipStats = fs.statSync(zipPath);
const zipSize = (zipStats.size / 1024 / 1024).toFixed(2);
return {
success: true,
data: {
zipPath,
zipSize: `${zipSize} MB`,
耗时:`${Date.now() - Date.now()} ms`,
message: '压缩成功,适配低配置'
},
};
} catch (error) {
return { success: false, error: `压缩失败:${(error as Error).message}` };
}
}
public static register() {
return {
pluginId: this.pluginId,
version: this.version,
execute: (params: any) => new this().execute(params),
};
}
}
export default CompressFilesPlugin.register();
3.2.4 .eslintrc.js(代码规范,可选)
module.exports = {
env: {
node: true,
es2021: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
'no-console': 'off',
},
};
3.3 插件打包与安装(一键完成)
cd src/plugins/compress-files
pnpm install --registry https://registry.npmmirror.com
npx tsc
cd ../../../..
pnpm run plugin:install -- --path src/plugins/compress-files
pnpm run plugin:list
pnpm run restart:lightweight
3.4 插件测试(必做,确保电脑可正常使用)
pnpm run agent -- --message "调用文件批量压缩插件,dirPath=./test,zipName=test-compress,ignore=[\"*.log\"]"
ls | grep test-compress.zip
dir | findstr test-compress.zip
pnpm run agent -- --message "调用文件批量压缩插件,dirPath=./nonexistent,zipName=error-test"
mkdir test-100 && cd test-100
for i in {1..100}; do echo "test" > file$i.txt; done
for /l %i in (1,1,100) do echo test > file%i.txt
cd ..
pnpm run agent -- --message "调用文件批量压缩插件,dirPath=./test-100,zipName=100-files-compress"
3.5 插件开发规范(适配补充)
pnpm run plugin:uninstall -- --id compress-files-plugin
rm -rf src/plugins/compress-files
四、常见坑排查
核心说明:所有坑均来自 OpenClaw 最新版本,结合低配置场景,每个坑均提供'报错信息 + 原因 + 解决命令',可直接复制执行,无需复杂排查。
坑 1:启动失败,报错'VT-x is disabled in BIOS/UEFI'
pnpm start:lightweight
nohup ollama serve > ollama.log 2>&1 &
坑 2:依赖安装超时,报错'request timed out'(国内网络)
npm config delete registry
npm config set registry https://registry.npmmirror.com
npm config set puppeteer_download_host https://registry.npmmirror.com/binary.html?path=chromium-browser-snapshots/
echo "[global] index-url = https://mirrors.aliyun.com/pypi/simple/ [install] trusted-host = mirrors.aliyun.com timeout = 120" > %APPDATA%\pip\pip.ini
echo "[global] index-url = https://mirrors.aliyun.com/pypi/simple/ [install] trusted-host = mirrors.aliyun.com timeout = 120" > ~/.config/pip/pip.conf
npm cache clean --force
pnpm cache clean
pnpm install --registry https://registry.npmmirror.com --no-optional
坑 3:启动后卡顿,CPU 占用 100%
taskkill /f /im chrome.exe /im qq.exe /im wechat.exe /im explorer.exe
start explorer.exe
sudo killall -9 chrome firefox qq wechat
sudo systemctl stop cron.service bluetooth.service
pnpm run restart:lightweight
坑 4:插件安装失败,报错'Plugin id already exists'
pnpm run plugin:list
pnpm run plugin:uninstall -- --id 重复的插件 ID
rm -rf node_modules/.cache/openclaw-plugin
cd src/plugins/compress-files
npx tsc
cd ../../../..
pnpm run plugin:install -- --path src/plugins/compress-files
坑 5:本地模型启动失败,报错'insufficient memory'
ollama rm ministral-3:8b
ollama pull llama3:8b-instruct-q4_0
setx OLLAMA_MAX_MEMORY "2GB" /m
echo "export OLLAMA_MAX_MEMORY=2GB" >> ~/.bashrc
source ~/.bashrc
taskkill /f /im ollama.exe
start /b ollama serve
pnpm run restart:lightweight
pkill ollama
nohup ollama serve > ollama.log 2>&1 &
pnpm run restart:lightweight
坑 6:Web Dashboard 无法访问,报错'Connection refused'
pnpm run gateway:status
pnpm run gateway:start -- --lightweight
taskkill /f /pid 占用进程 ID
lsof -i:18789
sudo kill -9 占用进程 ID
netsh advfirewall set allprofiles state off
sudo ufw disable
start http://127.0.0.1:18789/
xdg-open http://127.0.0.1:18789/
坑 7:启动报错'Cannot find module 'dashscope''
echo "[global] index-url = https://mirrors.aliyun.com/pypi/simple/ [install] trusted-host = mirrors.aliyun.com timeout = 120" > %APPDATA%\pip\pip.ini
echo "[global] index-url = https://mirrors.aliyun.com/pypi/simple/ [install] trusted-host = mirrors.aliyun.com timeout = 120" > ~/.config/pip/pip.conf
pip3 install dashscope requests pyyaml python-dotenv -i https://mirrors.aliyun.com/pypi/simple/
pip3 list | grep dashscope
pnpm run restart:lightweight
坑 8:机械硬盘部署,报错'EIO: i/o error, write'
fsutil behavior set DisableLastAccess 1
sudo sysctl -w vm.dirty_ratio=3
sudo sysctl -w vm.dirty_background_ratio=1
mkdir E:\OpenClaw && cd E:\OpenClaw
git clone https://github.moeyy.xyz/https://github.com/openclaw/openclaw.git
cd openclaw
pnpm install --registry https://registry.npmmirror.com --no-optional
pnpm run plugin:load -- --id compress-files-plugin
pnpm run restart:lightweight
五、进阶优化(可选,进一步提升流畅度)
ollama pull llama3:8b-instruct-q2_k
sc create OpenClaw binPath= "D:\OpenClaw\openclaw\node_modules\.bin\pnpm start:lightweight" start= auto sc start OpenClaw
sudo echo "[Unit] Description=OpenClaw AI Employee After=network.target ollama.service [Service] User=$USER ExecStart=$HOME/openclaw/node_modules/.bin/pnpm start:lightweight Restart=always RestartSec=5 [Install] WantedBy=multi-user.target" > /etc/systemd/system/openclaw.service
sudo systemctl daemon-reload
sudo systemctl enable openclaw.service
sudo systemctl start openclaw.service
pnpm run plugin:uninstall -- --id 无需的插件 ID
pnpm run plugin:load -- --id compress-files-plugin
六、部署/开发常用命令汇总
相关免费在线工具
- RSA密钥对生成器
生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online
- Mermaid 预览与可视化编辑
基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online
- 随机西班牙地址生成器
随机生成西班牙地址(支持马德里、加泰罗尼亚、安达卢西亚、瓦伦西亚筛选),支持数量快捷选择、显示全部与下载。 在线工具,随机西班牙地址生成器在线工具,online
- Base64 字符串编码/解码
将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
- Base64 文件转换器
将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online
- Markdown转HTML
将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online