华为云ECS手动部署OpenClaw
【摘要】 # 方案三:华为云 ECS 手动部署> 在华为云 ECS Ubuntu 服务器上手动部署 OpenClaw## 方案概述在华为云 ECS 上使用 Ubuntu 系统,手动安装 Node.js 和 OpenClaw。适合需要自定义配置、更高性能或企业生产环境的用户。---## 方案特点| 特点 | 说明 ||------|------|| 系统要求 | Ubuntu 20.04/22.04/2...
# 方案三:华为云 ECS 手动部署
> 在华为云 ECS Ubuntu 服务器上手动部署 OpenClaw
## 方案概述
在华为云 ECS 上使用 Ubuntu 系统,手动安装 Node.js 和 OpenClaw。适合需要自定义配置、更高性能或企业生产环境的用户。
---
## 方案特点
| 特点 | 说明 |
|------|------|
| 系统要求 | Ubuntu 20.04/22.04/24.04 |
| 部署方式 | 手动安装,完全可控 |
| 配置灵活 | 可自定义服务器规格 |
| 适合场景 | 企业生产、高并发、自定义需求 |
---
## 部署步骤
### Step 1:创建华为云 ECS 实例
1. 登录 [华为云控制台](https://console.huaweicloud.com)
2. 进入 **弹性云服务器 ECS** → **购买弹性云服务器**
3. 选择配置:
| 配置项 | 推荐值 |
|--------|--------|
| 镜像 | Ubuntu 22.04 LTS |
| 规格 | 2核4G 或更高 |
| 系统盘 | 40GB 或更高 |
| 网络 | VPC + 弹性公网 IP |
| 安全组 | 放行 443 端口(HTTPS) |
4. 完成购买,获取服务器 IP 和登录密码
### Step 2:连接服务器
使用 SSH 连接服务器:
```bash
ssh root@<your-server-ip>
```
### Step 3:更新系统
```bash
apt update && apt upgrade -y
```
### Step 4:安装 Node.js
**方式一:使用 NodeSource 仓库(推荐)**
```bash
# 安装 Node.js 22.x (最新 LTS)
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
# 验证安装
node --version
npm --version
```
**方式二:使用 nvm 安装**
```bash
# 安装 nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# 加载 nvm
source ~/.bashrc
# 安装最新 LTS 版本
nvm install --lts
# 验证安装
node --version
npm --version
```
### Step 5:安装 OpenClaw
**一键安装**
```bash
npm install -g openclaw
```
**验证安装**
```bash
openclaw --version
```
### Step 6:初始化 OpenClaw
```bash
# 创建配置目录
mkdir -p ~/.openclaw
# 初始化配置
openclaw init
```
### Step 7:配置模型
编辑配置文件 `~/.openclaw/openclaw.json`,添加模型提供商:
```json
{
"providers": {
"huawei": {
"type": "openai",
"baseUrl": "https://maas-api.cn-east-3.myhuaweicloud.com/v1",
"apiKey": "your-api-key"
}
},
"models": {
"default": "huawei/deepseek-v3"
}
}
```
> **获取 API Key**:访问 [华为云 ModelArts MaaS](https://developer.huaweicloud.com/space/developerspace/tokens.html)
### Step 8:启动 OpenClaw
**前台启动(测试用)**
```bash
openclaw gateway start
```
**后台启动(生产用)**
```bash
# 使用 systemd 管理
openclaw gateway install-service
systemctl start openclaw
systemctl enable openclaw
```
### Step 9:配置安全组
在华为云控制台配置安全组规则:
| 方向 | 协议 | 端口 | 说明 |
|------|------|------|------|
| 入方向 | TCP | 443 | HTTPS 访问 |
| 入方向 | TCP | 22 | SSH 管理(可选限制 IP) |
### Step 10:访问 OpenClaw
打开浏览器访问:
```
https://<your-server-ip>
```
---
## 生产环境建议
### 1. 使用 HTTPS
配置 SSL 证书:
```bash
# 使用 Let's Encrypt 免费证书
apt install certbot
certbot certonly --standalone -d your-domain.com
```
在 `openclaw.json` 中配置:
```json
{
"gateway": {
"tls": {
"cert": "/etc/letsencrypt/live/your-domain.com/fullchain.pem",
"key": "/etc/letsencrypt/live/your-domain.com/privkey.pem"
}
}
}
```
### 2. 配置防火墙
```bash
# 使用 ufw
ufw allow 22
ufw allow 443
ufw enable
```
### 3. 设置开机自启
```bash
systemctl enable openclaw
```
### 4. 配置日志
```json
{
"logging": {
"level": "info",
"file": "/var/log/openclaw/openclaw.log"
}
}
```
### 5. 监控告警
建议配置:
- 华为云云监控:监控 CPU、内存、网络
- 日志服务:收集 OpenClaw 日志
- 告警规则:异常时发送通知
---
## 常见问题
### Q:Node.js 安装速度慢怎么办?
使用国内镜像:
```bash
# 使用淘宝镜像
npm config set registry https://registry.npmmirror.com
# 或使用华为云镜像
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
```
### Q:端口被占用怎么办?
检查端口占用:
```bash
lsof -i :443
```
修改 OpenClaw 端口:
```json
{
"gateway": {
"port": 8443
}
}
```
### Q:如何更新 OpenClaw?
```bash
npm update -g openclaw
systemctl restart openclaw
```
### Q:如何查看日志?
```bash
# systemd 日志
journalctl -u openclaw -f
# 或查看文件日志
tail -f /var/log/openclaw/openclaw.log
```
---
## 优缺点分析
### 优点
| 优点 | 说明 |
|------|------|
| ✅ 完全可控 | 手动安装,配置灵活 |
| ✅ 高性能 | 可选择任意规格 ECS |
| ✅ 企业级 | 适合生产环境 |
| ✅ 自定义 | 可按需调整配置 |
| ✅ 成本可控 | 按需选择配置 |
### 缺点
| 缺点 | 说明 |
|------|------|
| ❌ 需要技术基础 | 需要熟悉 Linux 操作 |
| ❌ 手动配置 | 步骤较多,需要耐心 |
| ❌ 运维成本 | 需要自行维护服务器 |
---
## 适用场景
| 场景 | 推荐度 |
|------|--------|
| 企业生产环境 | ⭐⭐⭐⭐⭐ |
| 高并发场景 | ⭐⭐⭐⭐⭐ |
| 自定义配置需求 | ⭐⭐⭐⭐⭐ |
| 有运维能力 | ⭐⭐⭐⭐⭐ |
| 新手入门 | ⭐⭐(建议先选方案一或二) |
---
## 相关链接
- [华为云 ECS 控制台](https://console.huaweicloud.com/ecm)
- [华为云 ModelArts MaaS](https://developer.huaweicloud.com/space/developerspace/tokens.html)
- [OpenClaw 官方文档](https://docs.openclaw.ai)
- [Node.js 官网](https://nodejs.org)
---
[返回目录](../openclaw-enterprise-hands-on-guide.md)
*最后更新:2026-03-17*
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)