跳到主要内容
极客日志极客日志面向AI+效率的开发者社区
首页博客我的书AI学习GitHub 精选镜像AI 生图工具UI配色美学关于
搜索内容 / 工具 / 仓库 / 镜像...⌘K搜索
注册
博客列表
PowerShellNode.jsAI大前端

OpenClaw Gateway 连接被拒绝与端口占用排查指南

OpenClaw Gateway 启动时出现连接被拒绝错误,常见原因为端口 18789 被占用、旧版 Cladbot 残留配置冲突或权限不足。解决方案包括使用 PowerShell 检查并终止占用进程、清理环境变量与配置文件、调整防火墙规则或更换高位端口。通过验证端口监听状态与服务响应可确认修复成功。

黑客帝国发布于 2026/2/27更新于 2026/9/380 浏览

问题现象

用户在 Windows 11 上全新安装 OpenClaw 后,完成 onboarding 流程,但在启动 Gateway 时遇到 连接被拒绝 错误:

ERR_CONNECTION_REFUSED
http://127.0.0.1:18789/__openclaw__/canvas/

环境信息:

  • OS: Windows 11
  • OpenClaw: latest
  • Node.js: latest
  • 特殊情况:之前安装过 Cladbot

诊断过程

1. 确认 Gateway 状态
# 检查 Gateway 状态
openclaw gateway status

# 可能的输出:
# ❌ Gateway 未运行
# 或
# ⚠️ Gateway 运行中但端口未监听
2. 检查端口占用
# PowerShell - 查看端口 18789 占用情况
netstat -ano | findstr :18789

# 或 PowerShell 5.0+ 方式
Get-NetTCPConnection -LocalPort 18789

# 查看占用进程
Get-Process -Id (Get-NetTCPConnection -LocalPort 18789).OwningProcess
3. 检查残留进程

由于用户之前安装过 Cladbot,可能存在冲突:

# 查找 OpenClaw/Cladbot 相关进程
Get-Process | Where-Object {$_.ProcessName -match "openclaw|cladbot|node"}

# 查找端口监听
netstat -ano | findstr LISTENING | findstr 18789

常见原因

原因 1:端口被占用

症状:Gateway 启动后立即退出 日志:Error: listen EADDRINUSE: address already in use :::18789

解决方案:

# 1. 查找占用进程
netstat -ano | findstr :18789
# 输出:TCP    127.0.0.1:18789   0.0.0.0:0   LISTENING   12345
#                                              ↑ PID

# 2. 结束进程
taskkill /PID 12345 /F

# 或 PowerShell 方式
Stop-Process -Id 12345 -Force
原因 2:残留配置冲突

Cladbot 和 OpenClaw 可能使用相同的配置目录或环境变量。

解决方案:

# 1. 清理环境变量
[Environment]::SetEnvironmentVariable("CLADBOT_HOME", $null, "User")
[Environment]::SetEnvironmentVariable("OPENCLAW_HOME", $null, "User")

# 2. 清理旧配置(谨慎操作!)
# 备份后删除 Cladbot 配置
Rename-Item -Path "$env:USERPROFILE\.cladbot" -NewName "$env:USERPROFILE\.cladbot.backup"

# 3. 重新初始化 OpenClaw
openclaw onboard
原因 3:权限问题

Windows 可能需要管理员权限绑定端口。

解决方案:

# 以管理员身份运行 PowerShell,然后
openclaw gateway restart

# 或修改端口为高位端口(不需要管理员权限)
# 在 openclaw.json 中:
{
  "gateway": {
    "port": 58789  # ← 改为高位端口
  }
}
原因 4:防火墙/安全软件

Windows Defender 或其他安全软件可能阻止了 Node.js 的网络访问。

解决方案:

# 1. 检查防火墙规则
Get-NetFirewallRule | Where-Object {$_.DisplayName -like "*node*" -or $_.DisplayName -like "*openclaw*"}

# 2. 添加入站规则(管理员权限)
New-NetFirewallRule -DisplayName "OpenClaw Gateway" -Direction Inbound -LocalPort 18789 -Protocol TCP -Action Allow

完整排查流程

  1. 检查 Gateway 状态 └─ openclaw gateway status
  2. 检查端口占用 └─ netstat -ano | findstr :18789
  3. 检查残留进程 └─ Get-Process | ?{$_.Name -match "node|openclaw"}
  4. 检查日志 └─ Get-Content ~/.openclaw/logs/gateway.log -Tail 50
  5. 尝试手动启动 └─ openclaw gateway start --verbose
  6. 检查防火墙 └─ Get-NetFirewallRule | ?{$_.DisplayName -like "openclaw"}

解决方案汇总

方案 A:快速修复(推荐先尝试)
# 1. 停止所有相关进程
taskkill /F /IM node.exe 2>$null

# 2. 清理端口
$port = 18789
$process = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue
if ($process) {
    Stop-Process -Id $process.OwningProcess -Force
    Write-Host "已结束占用端口 $port 的进程"
}

# 3. 重启 Gateway
openclaw gateway restart

# 4. 验证
openclaw gateway status
方案 B:完全重置
# 1. 停止服务
openclaw gateway stop

# 2. 备份配置
Copy-Item -Path "$env:USERPROFILE\.openclaw" -Destination "$env:USERPROFILE\.openclaw.backup.$(Get-Date -Format 'yyyyMMdd')" -Recurse

# 3. 清理所有 Node 进程
Get-Process node -ErrorAction SilentlyContinue | Stop-Process -Force

# 4. 重新安装
npm uninstall -g openclaw
npm install -g openclaw

# 5. 重新配置
openclaw onboard
方案 C:更换端口

如果 18789 端口持续被占用:

// ~/.openclaw/openclaw.json
{
  "gateway": {
    "port": 58789,
    "host": "127.0.0.1"
  }
}

然后:

openclaw gateway restart
# 访问:http://127.0.0.1:58789/__openclaw__/canvas/

验证步骤

1. 端口监听验证
# 应该看到 LISTENING 状态
netstat -ano | findstr :18789
# TCP    127.0.0.1:18789   0.0.0.0:0   LISTENING   [PID]
2. 服务响应验证
# 测试 HTTP 响应
Invoke-RestMethod -Uri "http://127.0.0.1:18789/__openclaw__/canvas/" -Method GET

# 或使用 curl
curl http://127.0.0.1:18789/__openclaw__/canvas/
3. 浏览器访问

打开浏览器访问:

  • http://127.0.0.1:18789/__openclaw__/canvas/
  • 应该看到 OpenClaw Web UI

预防措施

1. 使用固定端口前检查
# 创建启动脚本 check-and-start.ps1
$port = 18789

# 检查端口
$existing = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue
if ($existing) {
    Write-Host "⚠️ 端口 $port 被占用,尝试释放..."
    Stop-Process -Id $existing.OwningProcess -Force
    Start-Sleep -Seconds 2
}

# 启动 Gateway
openclaw gateway start
2. 配置 Systemd/Windows Service
# 使用 nssm 创建 Windows 服务
nssm install OpenClawGateway "C:\Program Files\nodejs\node.exe"
nssm set OpenClawGateway AppDirectory "$env:USERPROFILE"
nssm set OpenClawGateway AppParameters "openclaw gateway start"
nssm set OpenClawGateway DisplayName "OpenClaw Gateway"
nssm start OpenClawGateway
3. 监控脚本
# monitor.ps1
while ($true) {
    try {
        $response = Invoke-RestMethod -Uri "http://127.0.0.1:18789/health" -TimeoutSec 5
        Write-Host "$(Get-Date) ✅ Gateway 运行正常"
    } catch {
        Write-Host "$(Get-Date) ❌ Gateway 无响应,尝试重启..."
        openclaw gateway restart
    }
    Start-Sleep -Seconds 60
}

Windows 环境特殊注意事项

问题解决方案
路径过长使用 \\?\ 前缀或缩短路径
权限不足以管理员身份运行 PowerShell
杀毒软件拦截将 OpenClaw 目录加入白名单
WSL 冲突检查 WSL 是否占用了相同端口
快速启动禁用 Windows 快速启动功能

总结

问题类型快速解决
端口被占用taskkill /PID [PID] /F
残留进程taskkill /F /IM node.exe
配置冲突备份后删除 .openclaw 重新配置
权限问题以管理员身份运行
防火墙添加入站规则允许 18789 端口

目录

  1. 问题现象
  2. 诊断过程
  3. 1. 确认 Gateway 状态
  4. 检查 Gateway 状态
  5. 可能的输出:
  6. ❌ Gateway 未运行
  7. 或
  8. ⚠️ Gateway 运行中但端口未监听
  9. 2. 检查端口占用
  10. PowerShell - 查看端口 18789 占用情况
  11. 或 PowerShell 5.0+ 方式
  12. 查看占用进程
  13. 3. 检查残留进程
  14. 查找 OpenClaw/Cladbot 相关进程
  15. 查找端口监听
  16. 常见原因
  17. 原因 1:端口被占用
  18. 1. 查找占用进程
  19. 输出:TCP 127.0.0.1:18789 0.0.0.0:0 LISTENING 12345
  20. ↑ PID
  21. 2. 结束进程
  22. 或 PowerShell 方式
  23. 原因 2:残留配置冲突
  24. 1. 清理环境变量
  25. 2. 清理旧配置(谨慎操作!)
  26. 备份后删除 Cladbot 配置
  27. 3. 重新初始化 OpenClaw
  28. 原因 3:权限问题
  29. 以管理员身份运行 PowerShell,然后
  30. 或修改端口为高位端口(不需要管理员权限)
  31. 在 openclaw.json 中:
  32. 原因 4:防火墙/安全软件
  33. 1. 检查防火墙规则
  34. 2. 添加入站规则(管理员权限)
  35. 完整排查流程
  36. 解决方案汇总
  37. 方案 A:快速修复(推荐先尝试)
  38. 1. 停止所有相关进程
  39. 2. 清理端口
  40. 3. 重启 Gateway
  41. 4. 验证
  42. 方案 B:完全重置
  43. 1. 停止服务
  44. 2. 备份配置
  45. 3. 清理所有 Node 进程
  46. 4. 重新安装
  47. 5. 重新配置
  48. 方案 C:更换端口
  49. 访问:http://127.0.0.1:58789/openclaw/canvas/
  50. 验证步骤
  51. 1. 端口监听验证
  52. 应该看到 LISTENING 状态
  53. TCP 127.0.0.1:18789 0.0.0.0:0 LISTENING [PID]
  54. 2. 服务响应验证
  55. 测试 HTTP 响应
  56. 或使用 curl
  57. 3. 浏览器访问
  58. 预防措施
  59. 1. 使用固定端口前检查
  60. 创建启动脚本 check-and-start.ps1
  61. 检查端口
  62. 启动 Gateway
  63. 2. 配置 Systemd/Windows Service
  64. 使用 nssm 创建 Windows 服务
  65. 3. 监控脚本
  66. monitor.ps1
  67. Windows 环境特殊注意事项
  68. 总结

更多推荐文章

查看全部
  • Kimi-VL-A3B-Thinking 部署与 vLLM 性能调优实战
  • AIGC 降重工具排行榜:免费功能实测与性能深度评测
  • 微服务韧性演进史:从 Hystrix 到 Service Mesh
  • 算力调度算法:基于AI的智能算力分配方法
  • OpenClaw Windows 部署:Node.js 22+Git+Kimi+ 飞书
  • Python 爬虫实战:音乐平台歌曲信息采集与处理
  • 91n 边缘计算设备部署轻量 TensorFlow 模型全流程
  • Qwen3-32B 本地部署实践:Clawdbot CLI 与 Web UI 双入口
  • UML 类图及六大关系详解:继承、实现、依赖、关联、聚合、组合
  • 纯 C# 自研轻量 UI 引擎 XchyUI:内核<200KB,支持.NET8 AOT 跨平台
  • ESP32 无人机远程识别实战:ArduRemoteID 配置与部署
  • Windows 本地部署 Ollama 与 OpenClaw 构建 AI 自动化工作流
  • 使用 MCP Server 插件将 Dify 工作流暴露为第三方服务
  • 基于 Web 的红色旅游网站的设计与实现
  • Spring AI 重塑 Java 生态 AI 开发实践
  • MySQL 约束详解:非空、主键、外键与自增机制实战
  • Web 架构深度解析:前后端分离与传统模式对比
  • 前端代码生成测评:GLM 4.7、MiniMax 与 Claude Opus 对比分析
  • Web Components 封装实战:实现跨框架复用组件
  • VS Code 远程连接服务器后 GitHub Copilot 无法使用解决方案

相关免费在线工具

  • RSA密钥对生成器

    生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online

  • Mermaid 预览与可视化编辑

    基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online

  • 随机西班牙地址生成器

    随机生成西班牙地址(支持马德里、加泰罗尼亚、安达卢西亚、瓦伦西亚筛选),支持数量快捷选择、显示全部与下载。 在线工具,随机西班牙地址生成器在线工具,online

  • Base64 字符串编码/解码

    将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online

  • Base64 文件转换器

    将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online

  • Markdown转HTML

    将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online