我的 openclaw 环境配置指南
本文分享我的 openclaw 环境搭建经验,包含工具配置、代理设置、多模型接入等内容。适合有一定技术基础的开发者参考。
> 本文分享我的 openclaw 环境搭建经验,包含工具配置、代理设置、多模型接入等内容。适合有一定技术基础的开发者参考。
## 📋 目录
- [网络架构](#网络架构)
- [开发环境](#开发环境)
- [AI 模型接入](#ai-模型接入)
- [工具配置](#工具配置)
- [运维技巧](#运维技巧)
---
## 🌐 网络架构
### 桥接模式
我的开发环境采用**桥接网络模式**,虚拟机和宿主机在同一局域网,可直接通信。
```
┌─────────────────────────────────────┐
│ 宿主机 (DESKTOP-H7SATA2) │
│ │
│ ┌──────────────────────────────┐ │
│ │ 虚拟机 (Linux) │ │
│ │ 192.168.x.x │ │
│ └──────────────────────────────┘ │
└─────────────────────────────────────┘
```
**目录映射:**
```bash
mklink /D H:\goShare\goPro\pro2026 H:\tzj\pro2026
```
### 共享磁盘挂载
```bash
# Windows 共享目录挂载到 Linux
sudo mount -t cifs -o uid=1000,gid=1000,username=flyShare,password:**** //192.168.23.1/gShare /mnt/shared_disk
```
---
## 🔧 开发环境
### OpenClaw 配置
OpenClaw 是我使用的 AI Agent 框架,需要 root 权限运行。
**安装方式:**
```bash
curl -fsSL https://clawd.bot/install.sh | bash -x
```
**国内镜像加速(可选):**
```bash
npm config set registry https://registry.npmmirror.com
npm install -g openclaw@latest
```
**配置示例:**
```json
{
"channels": {
"telegram": {
"name": "fly",
"enabled": true,
"dmPolicy": "allowlist",
"botToken": "your-bot-token",
"allowFrom": ["your-user-id"],
"groupPolicy": "allowlist",
"streamMode": "partial",
"proxy": "http://your-proxy:10809"
}
}
}
```
### 给用户 sudo 权限
```bash
# 切换到 root
su -
# 创建用户专用配置文件
echo "ai008 ALL=(ALL:ALL) ALL" > /etc/sudoers.d/ai008
# 设置正确的权限
chmod 0440 /etc/sudoers.d/ai008
# 验证
sudo whoami # 应该输出 root
```
---
## 🤖 AI 模型接入
### 多模型平台配置
我配置了多个 AI 模型平台,以应对不同场景需求:
#### 1. OpenRouter (推荐)
支持多种模型切换,API 风格统一。
```json
{
"baseUrl": "https://openrouter.ai/api/v1",
"apiKey": "sk-or-v1-xxxxx"
}
```
**优点:**
- 模型选择丰富
- 价格透明
- API 兼容 OpenAI 格式
#### 2. NVIDIA API
适合需要高性能 GPU 推理的场景。
```json
{
"baseUrl": "https://integrate.api.nvidia.com/v1",
"apiKey": "nvapi-xxxxx"
}
```
**推荐模型:**
- glm-4.7
- minimax-m2.1
#### 3. Moonshot AI (Kimi)
国产模型,国内访问速度快。
```json
{
"baseUrl": "https://api.moonshot.cn/v1",
"apiKey": "sk-xxxxx"
}
```
**推荐模型:**
- kimi-k2.5
#### 4. 本地 Ollama
适合离线或隐私敏感场景。
```bash
# 安装
curl -fsSL https://ollama.com/install.sh | sh
# 安装模型 (需支持工具调用)
ollama run qwen3-coder:latest
ollama run deepseek-coder:6.7b
# 检查模型是否支持工具调用
# 前往 ollama.com 搜索模型,看是否带有 "tools" 标志
```
**资源优化:**
```bash
# 内存不足时,配置交换文件
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# 永久生效
echo '/swapfile none swap sw 0 0' >> /etc/fstab
```
### 模型查询命令
```bash
# 查询 OpenRouter 可用模型
curl https://api.openai.com/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"
# 测试连接超时
curl -m 10 https://api.openai.com/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"
```
---
## 🛠️ 工具配置
### SSH 远程访问
```bash
# 连接远程服务器
ssh root@192.168.23.142
# 禁用用户登录(安全加固)
sudo usermod -L ai008
# 查看开放端口
ss -tulpn
```
### OpenClaw 技能生态
**官方技能仓库:**
- https://skills.sh/openclaw/openclaw
- https://skills.sh/openclaw/skills
- https://github.com/VoltAgent/awesome-openclaw-skills
**安装技能:**
```bash
# MCP 技能
npx clawhub@latest install exa-web-search-free
npx clawhub@latest install coding-agent
npx clawhub@latest install python
npx clawhub@latest install git-essentials
# 查找可用技能
npx skills add https://github.com/openclaw/skills --skill find-skills
```
### OpenClaw 控制台
```bash
# TUI 控制台
openclaw tui
# 重置配置
openclaw onboard
# 查看配置
cat ~/.openclaw/openclaw.json
# 健康检查
openclaw health --
```
---
## 💡 运维技巧
### 1. 快速切换模型配置
```bash
# 备份当前配置
cat /root/.openclaw/openclaw.json > openclaw.json.back.qwen
# 切换到不同模型配置
cat openclaw.json.back.nvidia > /root/.openclaw/openclaw.json
# 重新激活
openclaw gateway restart
```
### 2.Hosts 文件管理
```bash
# 切换开发/生产环境
sed -i 's/^192\.168\.10\.19 hostpc/192.168.1.13 hostpc/' /etc/hosts
sed -i 's/^192\.168\.1\.13 hostpc/192.168\.10\.19 hostpc/' /etc/hosts
```
### 3. 代理配置
```bash
# 验证代理是否生效
curl ipinfo.io
```
---
## 📚 经验总结
### 最佳实践
1. **多模型策略**:不同任务用不同模型,平衡成本和效果
2. **本地+云端结合**:常用模型本地部署,特殊需求调用云端
3. **配置备份**:重要配置文件定期备份,便于快速回滚
4. **安全第一**:API Keys 不提交到代码仓库,使用环境变量
### 推荐配置方案
| 场景 | 推荐方案 |
|------|---------|
| 日常编码 | OpenRouter + Qwen/Coder |
| 复杂推理 | NVIDIA + glm-4.7 |
| 中文长文本 | Moonshot + Kimi |
| 离线开发 | Ollama + 本地模型 |
---
## 🔗 参考资源
- [OpenClaw 文档](https://docs.openclaw.ai)
- [OpenRouter 模型列表](https://openrouter.ai/models)
- [Ollama 模型库](https://ollama.com)
- [Moonshot AI](https://platform.moonshot.cn)
---
> **声明**:本文仅分享技术配置思路。如有疑问,欢迎交流讨论。
更多推荐

所有评论(0)