旧主机部署openclaw

admin
3
2026-07-31

旧主机部署openclaw

前提

  • 最近红螃蟹大火,我也整一个玩玩,正好有大半个替换下来的老主机,淘点配件组装起来,架构如下:
    • CPU:锐龙R5 1600
    • 内存:威刚 DDR4 8GB
    • SSD:建兴T10 256GB nvme
    • 机箱:18块钱咸鱼
    • 电源:50块钱咸鱼
    • 显卡:200块钱淘宝亮机卡
  • 用软碟通做好Debian 12安装U盘(官网下载debian-12.xx-amd64-netinst.iso)
  • 有豆包API密钥(https://console.volcengine.com/ark/)
  • 使用家庭宽带,通过NPS穿透到云服务器使用,划分一个3级子域名使用
  • JD云服务器,只能在家里用可不行,我在公司也得可以用

1. 安装Debian 12(极简适配老硬件)

  1. 插U盘启动,选“Install”,语言选English(避免中文乱码,后续可改),地区选China,时区选Asia/Shanghai
  2. 分区(256G SSD):
    • / :200G(ext4)
    • swap:8G(和内存等大)
    • 剩余空间给/var(日志/缓存用)
  3. 软件选择:只勾选“SSH Server”+“standard system utilities”(极简,省资源)
  4. 设root密码、普通用户(比如claw),完成安装,拔U盘重启

2. 系统基础配置(ssh登录后操作)

2.1 换国内源(提速)

# 备份原源
cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 清空并写入清华源
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" > /etc/apt/sources.list

2.2 更新系统+装依赖

apt update && apt upgrade -y
# 安装基础依赖(适配openclaw)
apt install -y git python3 python3-pip python3-venv build-essential libssl-dev libffi-dev
# 升级pip
python3 -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple

3. 部署openclaw

3.1 克隆仓库(默认用官方最新版,若有指定分支自行改)

mkdir -p /opt/claw && cd /opt/claw
git clone https://github.com/openclaw/openclaw.git .

3.2 创建虚拟环境(避免污染系统Python)

python3 -m venv venv
source venv/bin/activate

3.3 安装openclaw依赖

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 额外装豆包API依赖(volcengine-sdk)
pip install volcengine -i https://pypi.tuna.tsinghua.edu.cn/simple

4. 配置豆包API接入

4.1 新建API配置文件

cd /opt/claw/config
cp example.yaml douban.yaml  # 复制示例配置改
vim douban.yaml

4.2 写入豆包API配置(核心配置,其他默认)

# 豆包API核心配置
llm:
  type: doubao  # 指定豆包LLM
  api_key: "你的豆包API密钥"  # 替换成自己的
  endpoint: "https://ark.cn-beijing.volces.com/api/v3/chat/completions"  # 豆包API端点
  model: "doubao-pro"  # 模型名,根据自己的选择改(比如doubao-lite)
  temperature: 0.7
  max_tokens: 2000

4.3 验证配置

# 测试API连通性(新建test.py)
cat > /opt/claw/test.py << EOF
from volcengine.ark.runtime import Ark
client = Ark(
    api_key="你的豆包API密钥"
)
completion = client.chat.completions.create(
    model="doubao-pro",
    messages=[{"role": "user", "content": "测试"}]
)
print(completion.choices[0].message.content)
EOF
# 运行测试
python3 test.py

能输出“测试”相关回复,说明API配置正常。

5. 启动openclaw

cd /opt/claw
source venv/bin/activate
# 启动服务(默认端口8000,老主机无端口冲突)
python3 main.py --config config/douban.yaml

6. 验证访问

本地浏览器访问:http://主机IP:8000,能看到openclaw界面,输入问题能调用豆包API返回结果即部署完成。

7. 云服务器部署NPS服务端

# 下载NPS(amd64架构,适配云服务器)
wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_server.tar.gz -O nps-server.tar.gz
# 解压
tar -zxvf nps-server.tar.gz && cd linux_amd64_server
# 安装+启动
./nps install
./nps start
# 查看初始配置(记住管理账号密码)
cat /etc/nps/conf/nps.conf | grep -E "web_username|web_password"

8. 云服务器配置穿透规则(浏览器操作)

  1. 访问云服务器管理面板:http://云服务器公网IP:8024,用上面查到的账号密码登录
  2. 左侧选「客户端」→「新增客户端」:随便填备注(比如claw-host),其他默认,保存后记下方的「客户端ID」
  3. 左侧选「隧道」→「新增隧道」:
    • 客户端ID:选刚创建的那个
    • 协议:TCP
    • 本地端口:8000(老主机openclaw的端口)
    • 服务器端口:8080(云服务器对外暴露的端口)
      保存即可

9. 老主机(运行openclaw)部署NPS客户端

# 下载NPS客户端(amd64,适配锐龙R5 1600)
wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_client.tar.gz -O nps-client.tar.gz
# 解压
tar -zxvf nps-client.tar.gz && cd linux_amd64_client
# 启动客户端(替换参数:云服务器IP、客户端ID)
./npc -server=云服务器公网IP:8024 -vkey=客户端ID -type=tcp

看到「start proxy success」说明客户端连接成功。

10. 验证穿透访问

任意能联网的设备访问:http://云服务器公网IP:8080,能打开openclaw界面,调用豆包API正常返回结果,即穿透成功。

可选:老主机设置NPS客户端开机自启(避免重启失效)

# 写入自启脚本
cat > /etc/systemd/system/npc.service << EOF
[Unit]
Description=NPS Client
After=network.target

[Service]
Type=simple
ExecStart=/root/linux_amd64_client/npc -server=云服务器公网IP:8024 -vkey=客户端ID -type=tcp
Restart=always
User=root

[Install]
WantedBy=multi-user.target
EOF
# 启动并设置自启
systemctl daemon-reload
systemctl start npc
systemctl enable npc

总结

  1. 核心是云服务器部署NPS服务端,老主机部署客户端,映射8080(云)→8000(老主机);
  2. 云服务器需放行8024(管理)、8080(穿透)端口,否则无法访问;
  3. 客户端启动成功后,通过云服务器公网IP+8080即可访问老主机的openclaw。

总结

  1. 老主机装Debian 12选极简安装,只保留SSH和基础组件,适配8G内存;
  2. 所有依赖通过虚拟环境安装,避免污染系统Python,国内源提速;
  3. 核心配置是豆包API密钥+端点,测试连通后启动openclaw即可。
动物装饰