# 使用远程 Gateway 网关运行 OpenSoul.app
OpenSoul.app 使用 SSH 隧道连接到远程 Gateway 网关。本指南向你展示如何设置。
# 概述
┌─────────────────────────────────────────────────────────────┐
│ Client Machine │
│ │
│ OpenSoul.app ──► ws://127.0.0.1:18789 (local port) │
│ │ │
│ ▼ │
│ SSH Tunnel ────────────────────────────────────────────────│
│ │ │
└─────────────────────┼──────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Remote Machine │
│ │
│ Gateway WebSocket ──► ws://127.0.0.1:18789 ──► │
│ │
└─────────────────────────────────────────────────────────────┘# 快速设置
# 步骤 1:添加 SSH 配置
编辑 ~/.ssh/config 并添加:
ssh
Host remote-gateway
HostName <REMOTE_IP> # e.g., 172.27.187.184
User <REMOTE_USER> # e.g., jefferson
LocalForward 18789 127.0.0.1:18789
IdentityFile ~/.ssh/id_rsa将 <REMOTE_IP> 和 <REMOTE_USER> 替换为你的值。
# 步骤 2:复制 SSH 密钥
将你的公钥复制到远程机器(输入一次密码):
bash
ssh-copy-id -i ~/.ssh/id_rsa <REMOTE_USER>@<REMOTE_IP># 步骤 3:设置 Gateway 网关令牌
bash
launchctl setenv OPENSOUL_GATEWAY_TOKEN "<your-token>"# 步骤 4:启动 SSH 隧道
bash
ssh -N remote-gateway &# 步骤 5:重启 OpenSoul.app
bash
# Quit OpenSoul.app (⌘Q), then reopen:
open /path/to/OpenSoul.app应用现在将通过 SSH 隧道连接到远程 Gateway 网关。
# 登录时自动启动隧道
要在登录时自动启动 SSH 隧道,请创建一个 Launch Agent。
# 创建 PLIST 文件
将此保存为 ~/Library/LaunchAgents/ai.opensoul.ssh-tunnel.plist:
xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>ai.opensoul.ssh-tunnel</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/ssh</string>
<string>-N</string>
<string>remote-gateway</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist># 加载 Launch Agent
bash
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/ai.opensoul.ssh-tunnel.plist隧道现在将:
- 登录时自动启动
- 崩溃时重新启动
- 在后台持续运行
旧版注意事项:如果存在任何遗留的 com.opensoul.ssh-tunnel LaunchAgent,请将其删除。
# 故障排除
检查隧道是否正在运行:
bash
ps aux | grep "ssh -N remote-gateway" | grep -v grep
lsof -i :18789重启隧道:
bash
launchctl kickstart -k gui/$UID/ai.opensoul.ssh-tunnel停止隧道:
bash
launchctl bootout gui/$UID/ai.opensoul.ssh-tunnel# 工作原理
| 组件 | 功能 |
|---|---|
LocalForward 18789 127.0.0.1:18789 | 将本地端口 18789 转发到远程端口 18789 |
ssh -N | SSH 不执行远程命令(仅端口转发) |
KeepAlive | 隧道崩溃时自动重启 |
RunAtLoad | 代理加载时启动隧道 |
OpenSoul.app 连接到你的客户端机器上的 ws://127.0.0.1:18789。SSH 隧道将该连接转发到运行 Gateway 网关的远程机器的端口 18789。