openclaw安装教程

/ 邓工 / 247阅读 / 7评论 / 分类: 学习

第一步:安装Node.js,打开https://nodejs.org/zh-cn/download,获取新版去官网安装;

# 下载并安装 nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

# 代替重启 shell
\. "$HOME/.nvm/nvm.sh"

# 下载并安装 Node.js:
nvm install 24

# 验证 Node.js 版本:
node -v # Should print "v24.14.0".

# 验证 npm 版本:
npm -v # Should print "11.9.0".

第二步:安装openclaw,打开https://openclaw.ai/  ,获取安装代码选择npm安装,记住你的token

# Install OpenClaw
npm i -g openclaw
# Meet your lobster
openclaw onboard
 
第三步:安装tmux,
apt update
apt install -y tmux
tmux kill-session -t openclaw 2>/dev/null
tmux new -s openclaw -d 'openclaw gateway --port 18789 --force'
ss -lntp | grep 18789
curl -I http://127.0.0.1:18789/
第四步:访问前端出现“”origin not allowed (open the Control UI from the gateway host or allow it in gateway.controlUi.allowedOrigins),这是 Origin 白名单没匹配上。直接一次性修好并重启网关:
openclaw config set gateway.controlUi.allowedOrigins '["https://ai.hzpm.com","http://ai.hzpm.com","https://chat.hzpm.com","http://chat.hzpm.com"]' --strict-json
openclaw config set gateway.trustedProxies '["127.0.0.1","::1"]' --strict-json
tmux kill-session -t openclaw 2>/dev/null
tmux new -s openclaw -d 'openclaw gateway --port 18789 --force'

确认生效:

openclaw config get gateway.controlUi.allowedOrigins curl -I http://127.0.0.1:18789/

然后用无痕窗口打开:

https://XXX.com/#token=当前token 或者https://XXX.com/?token=当前token

 

你自定义的token(如果需要)

openclaw config set gateway.auth.mode token
openclaw config set gateway.auth.token "你自定义的token"
tmux kill-session -t openclaw 2>/dev/null
tmux new -s openclaw -d 'openclaw gateway --port 18789 --force'

pairing required 这是正常的,说明 token 和 origin 已经过了,现在只差设备配对授权。

执行:

openclaw devices list

找到当前浏览器对应的 pending requestId,然后批准:

openclaw devices approve <requestId>

如果只有一条待审批,也可直接:

openclaw devices approve --latest

批准后刷新 https://XXX.com/#token=你的token 即可。

发表评论
7 条评论
avatar
邓工 2 个月前

openclaw models set openai-codex/gpt-5.4
如果你要默认模型用 gpt-5.4,再执行一次:

avatar
邓工 2 个月前

可以,不用 API Key,直接走 OpenAI 登录授权(OAuth)。

在 SSH 里按这个做:

# 1) 进入登录流程
openclaw models auth login --provider openai-codex
它会给你一个登录链接。你在本地浏览器打开完成登录后:

如果自动回调失败(SSH/无桌面常见),把浏览器最终跳转的完整 URL 粘贴回终端
或按提示粘贴 code#state
然后设置默认模型并重启你当前 tmux 网关:

# 2) 看可用模型(先确认具体名字)
openclaw models list | grep openai-codex

# 3) 设置默认模型(示例,按你 list 出来的名字改)
openclaw models set openai-codex/gpt-5.3-codex

# 4) 重启后台
tmux kill-session -t openclaw 2>/dev/null || true
tmux new-session -d -s openclaw '/usr/local/bin/openclaw_tmux_runner.sh'

# 5) 验证
ss -lntp | grep 18789
tail -n 80 /var/log/openclaw.log

avatar
邓工 2 个月前

如果你把 command -v openclaw 的输出发我,我可以给你一版“可直接粘贴”的最终命令(不用你改路径)。



Welcome to Alibaba Cloud Elastic Compute Service !

The current terminal create by BT-Panel.
root@iZwz97jmlw77qk0e9gsg15Z:~# command -v openclaw
/usr/bin/openclaw
root@iZwz97jmlw77qk0e9gsg15Z:~#


















































直接用你这个路径,整套可一键执行:

cat >/usr/local/bin/openclaw_tmux_runner.sh <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

OPENCLAW_BIN="/usr/bin/openclaw"
PORT="18789"
LOG="/var/log/openclaw.log"

mkdir -p /var/log

while true; do
  "$OPENCLAW_BIN" gateway --port "$PORT" --force >>"$LOG" 2>&1 || true
  echo "$(date '+%F %T') openclaw exited, restart in 3s" >>"$LOG"
  sleep 3
done
EOF

chmod +x /usr/local/bin/openclaw_tmux_runner.sh

tmux kill-session -t openclaw 2>/dev/null || true
tmux new-session -d -s openclaw '/usr/local/bin/openclaw_tmux_runner.sh'

(crontab -l 2>/dev/null | grep -v 'openclaw_tmux_runner.sh'; \
echo '@reboot /usr/bin/tmux has-session -t openclaw 2>/dev/null || /usr/bin/tmux new-session -d -s openclaw "/usr/local/bin/openclaw_tmux_runner.sh"'; \
echo '* * * * * /usr/bin/tmux has-session -t openclaw 2>/dev/null || /usr/bin/tmux new-session -d -s openclaw "/usr/local/bin/openclaw_tmux_runner.sh"') | crontab -
验证:

tmux ls
ss -lntp | grep 18789
curl -I http://127.0.0.1:18789/
tail -n 50 /var/log/openclaw.log
这样就实现了:开机自启、后台常驻、SSH断开不影响。

avatar
邓工 2 个月前

问题已经很明确了:openclaw gateway 没有成功启动,所以 18789 端口没监听,curl 才会连不上。

按这个顺序排查最快:

# 1) 看 tmux 会话是否还在(如果命令启动失败,session 常会立刻退出)
tmux ls

# 2) 检查 openclaw 命令是否存在
which openclaw
openclaw --version

# 3) 先前台直接跑一次,看真实报错
openclaw gateway --port 18789 --force

avatar
邓工 2 个月前

加开机自启用这一条就行:

(crontab -l 2>/dev/null; echo '@reboot /usr/bin/tmux new-session -d -s openclaw "/root/.nvm/versions/node/v24.14.0/bin/openclaw gateway --port 18789 --force"') | crontab -
立即验证一次:

crontab -l
tmux ls
ss -lntp | grep 18789
如果重启后未起来,再把 crontab -l 和 tmux ls 输出贴我。

avatar
邓工 2 个月前

可以,tmux 也能稳定跑(比 supervisor 简单)。

用这组命令:

# 1) 清理旧进程和旧会话
pkill -f "openclaw gateway --port 18789" 2>/dev/null
tmux kill-session -t openclaw 2>/dev/null

# 2) 后台启动到 tmux
tmux new-session -d -s openclaw '/root/.nvm/versions/node/v24.14.0/bin/openclaw gateway --port 18789 --force'

# 3) 验证
sleep 2
tmux ls
ss -lntp | grep 18789
curl -i http://127.0.0.1:18789/

avatar
360 2 个月前

502重启网关
按下面顺序执行即可:

# 1) 确认配置(单独执行,不要和 curl 写一行)
openclaw config get gateway.controlUi.allowedOrigins
openclaw config get gateway.trustedProxies

# 2) 重启 tmux 里的网关进程
tmux kill-session -t openclaw 2>/dev/null
tmux new -s openclaw -d 'openclaw gateway --port 18789 --force'

# 3) 看进程日志(最关键)
tmux capture-pane -pt openclaw -S -200
# 或实时看
tmux attach -t openclaw
再检查监听和本机连通:

ss -lntp | grep 18789
curl -I http://127.0.0.1:18789/
如果 ss 还是没端口,说明网关启动即退出;把 tmux capture-pane 输出贴出来,我可以直接定位是哪一步报错导致 502。