系统 : Ubuntu 22.04
默认目录 : /root/.openclaw
目标:复制 → 执行 → 验证,即可完成部署。
一、系统初始化
bash
apt update && apt upgrade -y
apt install -y curl wget vim git unzip lrzsz ufw ffmpeg
二、安全配置
bash
ufw enable
ufw allow 22/tcp
ufw status
安装 fail2ban
bash
apt install fail2ban -y
编辑配置
bash
vim /etc/fail2ban/jail.local
配置内容
ini
[sshd]
enabled = true
port = ssh
logpath = %(sshd_log)s
maxretry = 5
findtime = 600
bantime = 3600
启动
bash
systemctl restart fail2ban
systemctl enable fail2ban
验证
bash
fail2ban-client status sshd
三、安装 OpenClaw
bash
curl -fsSL https://openclaw.ai/install.sh | bash
验证
bash
openclaw --version
检查运行
bash
openclaw gateway status
查看日志
bash
journalctl -u openclaw -f
说明:
OpenClaw 安装脚本会自动安装:
- Node.js
- npm
- 运行环境
推荐顺序:
- 安装 OpenClaw
- 再安装 QMD
四、创建 Telegram 机器人
Telegram 搜索:
@BotFather
执行:
/newbot
获得 BOT TOKEN
<你的Telegram_BOT_TOKEN>
五、安装 QMD
bash
cd /root
git clone https://github.com/tobi/qmd.git
cd qmd
npm install
npm run build
六、创建 qmd 命令
bash
ln -s /root/qmd/dist/cli/qmd.js /usr/local/bin/qmd
验证
bash
qmd
七、创建索引
bash
node /root/qmd/dist/cli/qmd.js collection add /root/.openclaw/workspace --name workspace-index --mask "*.md"
node /root/qmd/dist/cli/qmd.js embed workspace-index
八、查询测试
bash
qmd query VPS
九、OpenClaw 常用命令
bash
openclaw gateway status
openclaw gateway start
openclaw gateway stop
openclaw gateway restart
十、获取 Telegram 用户 ID
搜索机器人
@userinfobot
发送
/start
即可获得 Telegram 用户 ID。
十一、Telegram 命令审批配置
作用:
当 AI 需要执行服务器命令(例如 exec、shell 操作)时,不会自动执行,而是发送审批请求到 Telegram。
只有 approvers 列表中的用户确认后才会执行命令。
示例:
json
"execApprovals": {
"enabled": true,
"approvers": ["<你的Telegram用户ID>"],
"target": "dm"
}
说明:
- enabled:开启命令审批
- approvers:允许审批命令的 Telegram 用户 ID
- target:审批消息发送位置
十二、BotFather 隐私设置
在 BotFather 执行:
/setprivacy
选择机器人
@你的机器人用户名
然后选择
Enable
十三、Gateway 配置
json
"gateway": {
"port": 18789,
"mode": "local",
"bind": "loopback"
}
说明:
loopback 表示仅本机访问。
十四、Memory (QMD) 配置
json
"memory": {
"backend": "qmd",
"citations": "auto",
"qmd": {
"command": "qmd",
"searchMode": "search",
"paths": [
{
"path": "/root/.openclaw/workspace",
"name": "workspace",
"pattern": "**/*.{md,txt}"
}
],
"update": {
"interval": "60m",
"debounceMs": 150000,
"onBoot": true
},
"limits": {
"maxResults": 6,
"maxSnippetChars": 6000,
"maxInjectedChars": 36000,
"timeoutMs": 100000
}
}
}
十五、服务器内存不足解决
bash
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
free -h
十六、完整 openclaw.json 示例
需要替换:
<你的Azure_ENDPOINT>
<你的Azure_API_KEY>
<你的Telegram_BOT_TOKEN>
<你的Telegram用户ID>
<你的OpenClaw_GATEWAY_TOKEN>
json
{
"wizard": {
"lastRunAt": "2026-03-18T14:55:39.087Z",
"lastRunVersion": "2026.3.13",
"lastRunCommand": "onboard",
"lastRunMode": "local"
},
"models": {
"mode": "merge",
"providers": {
"azure-openai-responses": {
"baseUrl": "<你的Azure_ENDPOINT>",
"apiKey": "<你的Azure_API_KEY>",
"api": "openai-responses",
"headers": {"api-key": "<你的Azure_API_KEY>"},
"authHeader": false,
"models": [{
"id": "gpt-5.3-chat",
"name": "GPT-5.3 Chat (Azure)",
"reasoning": false,
"input": ["text","image"],
"contextWindow": 128000,
"maxTokens": 4096
}]
}
}
},
"agents": {
"defaults": {
"model": {"primary": "azure-openai-responses/gpt-5.3-chat"},
"workspace": "/root/.openclaw/workspace",
"compaction": {"mode": "safeguard"},
"maxConcurrent": 4,
"subagents": {"maxConcurrent": 8}
}
},
"tools": {
"profile": "full",
"allow": ["*"],
"deny": [],
"elevated": {
"enabled": true,
"allowFrom": {"telegram": ["<你的Telegram用户ID>"]}
}
},
"commands": {
"native": "auto",
"nativeSkills": "auto",
"restart": true,
"ownerDisplay": "raw"
},
"session": {
"dmScope": "per-channel-peer"
},
"hooks": {
"internal": {
"enabled": true,
"entries": {
"boot-md": {"enabled": true},
"bootstrap-extra-files": {"enabled": true},
"command-logger": {"enabled": true},
"session-memory": {"enabled": true}
}
}
},
"channels": {
"telegram": {
"enabled": true,
"dmPolicy": "allowlist",
"botToken": "<你的Telegram_BOT_TOKEN>",
"allowFrom": ["<你的Telegram用户ID>"],
"groupPolicy": "disabled",
"streaming": "partial",
"execApprovals": {
"enabled": true,
"approvers": ["<你的Telegram用户ID>"],
"target": "dm"
}
}
},
"gateway": {
"port": 18789,
"mode": "local",
"bind": "loopback",
"auth": {
"mode": "token",
"token": "<你的OpenClaw_GATEWAY_TOKEN>"
}
},
"memory": {
"backend": "qmd",
"citations": "auto"
},
"skills": {
"install": {"nodeManager": "npm"}
},
"plugins": {
"entries": {"telegram": {"enabled": true}}
},
"meta": {
"lastTouchedVersion": "2026.3.13"
}
}
部署完成
OpenClaw + QMD 已完成安装与配置。