🔧 **适用系统**:CentOS 7.x(本文基于 CentOS 7.9 编写)
🏗️ **架构要求**:x86_64
👤 **操作用户**:root(为简化操作,本文全程使用 root 用户)
—
## 📑 目录
– [一、环境准备](#一环境准备)
– [二、安装 Node.js 22.16.0](#二安装-nodejs-22160)
– [三、安装 CMake 3.28.3](#三安装-cmake-3283)
– [四、升级 GCC 到 9.x 版本](#四升级-gcc-到-9x-版本)
– [五、安装 OpenClaw](#五安装-openclaw)
– [六、配置 OpenClaw 网关服务](#六配置-openclaw-网关服务centos-7-专用)
– [七、配置外部访问](#七配置外部访问从物理机访问虚拟机)
– [八、常用管理命令](#八常用管理命令)
– [九、常见问题排查](#九常见问题排查)
– [十、安全建议](#十安全建议)
—
## 一、环境准备
### 📦 安装基础工具
```bash
# 安装必要的基础工具
yum install -y wget curl tar net-tools
```
✅ **验证方法**:
```bash
wget –version | head -1
curl –version | head -1
```
—
## 二、安装 Node.js 22.16.0
> 💡 **说明**:使用官方非标准构建版本,适配 CentOS 7 的 glibc 2.17
### 2.1 下载 Node.js 二进制包
```bash
# 创建下载目录
mkdir -p /usr/local/src/nodejs && cd /usr/local/src/nodejs
# 下载适配 CentOS 7 的 Node.js 版本
wget https://unofficial-builds.nodejs.org/download/release/v22.16.0/node-v22.16.0-linux-x64-glibc-217.tar.gz
```
### 2.2 安装 Node.js
```bash
# 解压到目标目录
tar -zxf node-v22.16.0-linux-x64-glibc-217.tar.gz -C /opt/local/
# 创建软链接
ln -s /opt/local/node-v22.16.0-linux-x64-glibc-217 /usr/local/nodejs
# 配置环境变量(永久生效)
echo 'export PATH=/usr/local/nodejs/bin:$PATH' >> /etc/profile
source /etc/profile
```
### 2.3 验证安装
```bash
node -v # 预期输出:v22.16.0
npm -v # 预期输出:10.x.x
```
📌 **成功标志**:
```
v22.16.0
10.8.2
```
—
## 三、安装 CMake 3.28.3
### 3.1 下载 CMake 二进制包
```bash
mkdir -p /usr/local/src/cmake && cd /usr/local/src/cmake
wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3-linux-x86_64.tar.gz
```
### 3.2 安装 CMake
```bash
# 解压到 /usr/local
tar -zxf cmake-3.28.3-linux-x86_64.tar.gz -C /usr/local/
# 创建软链接
cd /usr/local
ln -s cmake-3.28.3-linux-x86_64 cmake
# 配置环境变量
export PATH=/usr/local/cmake/bin:$PATH
echo 'export PATH=/usr/local/cmake/bin:$PATH' >> /etc/profile
source /etc/profile
```
### 3.3 验证安装
```bash
cmake –version # 预期输出:cmake version 3.28.3
```
📌 **成功标志**:
```
cmake version 3.28.3
```
—
## 四、升级 GCC 到 9.x 版本
### 4.1 配置 SCL 软件源
```bash
# 创建 SCLo-scl 源配置文件
cat > /etc/yum.repos.d/CentOS-SCLo-scl.repo << 'EOF'
[centos-sclo-sclo]
name=CentOS-7 – SCLo sclo
baseurl=http://vault.centos.org/centos/7/sclo/x86_64/sclo/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
enabled=1
EOF
# 创建 SCLo-rh 源配置文件
cat > /etc/yum.repos.d/CentOS-SCLo-rh.repo << 'EOF'
[centos-sclo-rh]
name=CentOS-7 – SCLo rh
baseurl=http://vault.centos.org/centos/7/sclo/x86_64/rh/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
enabled=1
EOF
```
### 4.2 导入正确的 GPG 密钥
```bash
# 下载正确的 SCLo 密钥
curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo \\
https://www.centos.org/keys/RPM-GPG-KEY-CentOS-SIG-SCLo
# 导入密钥
rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
# 清理并重建 yum 缓存
yum clean all && yum makecache
```
### 4.3 安装 GCC 9
```bash
# 安装 devtoolset-9 套件
yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++ \\
devtoolset-9-binutils scl-utils
# 永久启用 GCC 9(所有会话生效)
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
source /etc/profile
# 验证 GCC 版本
gcc –version # 应显示 gcc 9.x.x
```
📌 **成功标志**:
```
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
```
—
## 五、安装 OpenClaw
### 5.1 执行官方安装脚本
```bash
# 安装最新版 OpenClaw
export OPENCLAW_VERSION=2026.3.8
curl -fsSL https://openclaw.ai/install.sh | bash
```
⏱️ **安装耗时**:约 3-5 分钟,取决于网络速度
### 5.2 验证安装
```bash
openclaw –version # 应显示 2026.3.8
```
📌 **成功标志**:
```
2026.3.8
```
—
## 六、配置 OpenClaw 网关服务(CentOS 7 专用)
> ⚠️ **重要说明**:**CentOS 7 不支持 `systemctl –user`**,必须将服务转换为系统服务。
### 6.1 转换服务为系统级
```bash
# 复制服务文件到系统目录
sudo cp /root/.config/systemd/user/openclaw-gateway.service /etc/systemd/system/
# 重新加载 systemd 配置
sudo systemctl daemon-reload
# 启动服务
sudo systemctl start openclaw-gateway
# 设置开机自启
sudo systemctl enable openclaw-gateway
```
### 6.2 验证服务状态
```bash
# 查看服务状态(应显示 active (running))
sudo systemctl status openclaw-gateway
# 查看网关详细状态
openclaw gateway status –deep
```
📌 **预期输出**:
```
Runtime: running
RPC probe: ok
```
### 6.3 查看访问令牌
```bash
# 从配置文件中获取令牌
cat ~/.openclaw/openclaw.json | grep token
```
📌 **示例输出**:
```
"token": "0f79a5210512af21cccf1622c02492cf7d587096a894bc84"
```
🔐 **请保存好此令牌**,后续登录 Web 界面需要。
—
## 七、配置外部访问(从物理机访问虚拟机)
### 7.1 获取虚拟机网络信息
```bash
# 查看虚拟机 IP 地址
ip addr show | grep inet
```
📌 **示例输出**:
```
inet 192.168.184.153/24 brd 192.168.184.255 scope global dynamic ens33
```
👉 记录下类似 `192.168.184.153` 的 IP 地址
### 7.2 SSH 端口转发(推荐方式)
> ✅ **优点**:安全,兼容 loopback 模式,无需修改防火墙
在**物理机**的终端中执行:
```bash
# 语法:ssh -L 本地端口:localhost:远程端口 用户名@虚拟机IP -N
ssh -L 8888:localhost:18789 xiaolongxia123@192.168.184.153 -N
```
| 参数 | 说明 |
|:—|:—|
| `8888` | 物理机的本地端口(可自定义) |
| `18789` | OpenClaw 网关端口 |
| `xiaolongxia123` | 虚拟机用户名 |
| `192.168.184.153` | 虚拟机 IP 地址 |
| `-N` | 仅转发,不执行远程命令 |
⚠️ **注意**:该终端需保持运行,关闭即断开隧道
### 7.3 访问 OpenClaw Web 界面
1. 在物理机打开浏览器
2. 访问:`http://localhost:8888`
3. 输入第 6.3 步获取的令牌登录
🎉 **登录成功**!你将看到 OpenClaw 的控制面板。
—
## 八、常用管理命令
### 8.1 服务管理
| 操作 | 命令 |
|:—|:—|
| 启动服务 | `sudo systemctl start openclaw-gateway` |
| 停止服务 | `sudo systemctl stop openclaw-gateway` |
| 重启服务 | `sudo systemctl restart openclaw-gateway` |
| 查看状态 | `sudo systemctl status openclaw-gateway` |
| 查看日志 | `journalctl -u openclaw-gateway -n 100 -f` |
### 8.2 OpenClaw 命令
| 操作 | 命令 |
|:—|:—|
| 查看节点列表 | `openclaw nodes list` |
| 查看技能列表 | `openclaw skill list` |
| 运行安全审计 | `openclaw security audit –quick` |
| 查看完整状态 | `openclaw status –all` |
| 查看帮助 | `openclaw –help` |
—
## 九、常见问题排查
### 9.1 网关无法启动
```bash
# 检查端口是否被占用
ss -tlnp | grep 18789
# 查看详细日志
journalctl -u openclaw-gateway -n 50 –no-pager
```
### 9.2 SSH 隧道连接失败
```bash
# 在虚拟机中检查 SSH 服务状态
sudo systemctl status sshd
# 检查防火墙是否允许 SSH
sudo firewall-cmd –list-all
# 临时关闭防火墙测试(如必要)
# sudo systemctl stop firewalld
```
### 9.3 Web 界面无法访问
🔍 **排查清单**:
– [ ] SSH 隧道终端是否保持运行?
– [ ] 令牌输入是否正确?
– [ ] 虚拟机 IP 是否变化?
– [ ] 网关服务是否运行?(`sudo systemctl status openclaw-gateway`)
```bash
# 重启网关试试
sudo systemctl restart openclaw-gateway
```
### 9.4 GCC 9 未生效
```bash
# 手动启用 GCC 9
source /opt/rh/devtoolset-9/enable
# 检查版本
gcc –version
# 重新检查 /etc/profile 配置
cat /etc/profile | grep devtoolset
```
—
## 十、安全建议
### 🔐 基础安全配置
1. **定期更新**
```bash
openclaw update # 更新 OpenClaw
```
2. **令牌管理**
– 妥善保管访问令牌
– 建议每 3 个月更换一次
```bash
# 生成新令牌
openclaw token generate
```
3. **防火墙配置**
```bash
# 仅开放必要端口
sudo firewall-cmd –permanent –add-port=22/tcp # SSH
sudo firewall-cmd –reload
```
4. **日志监控**
```bash
# 定期检查异常
tail -f /var/log/messages | grep openclaw
```
### 📚 参考文档
– [OpenClaw 官方文档](https://docs.openclaw.ai/)
– [安全配置指南](https://docs.openclaw.ai/security)
– [故障排查手册](https://docs.openclaw.ai/troubleshooting)
—
## 🎉 结语
恭喜你!🎊 至此,你已成功在 CentOS 7 上完成 OpenClaw 的完整安装和配置。现在可以通过 Web 界面开始使用你的 AI 助手了!



