Deploy ttstd relay and configure secure public WSS clients

This commit is contained in:
tongtong committed 2026-11-12 13:08:04 +08:00
1 parent 82adce545d
commit c38f067bea
16 files changed
+384 -24

No files matched your search

+94
View File
@@ -0,0 +1,94 @@
# ttstd.com 实际部署
## 服务器与连接地址
- 服务器:`175.178.213.60`,Debian 12 amd64。
- 中继基地址:`wss://ttstd.com/ads`,已设为两端程序的默认值。
- 健康检查:`https://ttstd.com/ads/healthz`。
- 源站直连配置:`--connect-address 175.178.213.60:443`,或环境变量 `ADS_CONNECT_ADDRESS`。
`ttstd.com` 当前通过 Cloudflare 解析。部署测试中,当前电脑直连 Cloudflare 的 TLS 连接超时,而直连服务器正常。因此启动脚本默认指定源站地址:TCP 连接公网 IP,HTTP Host / TLS SNI 仍为 `ttstd.com`,证书链与主机名校验保持开启,不修改系统 hosts,也不关闭证书校验。
根域名已有解析和证书,当前方案**不需要添加或修改 DNS 记录**,主站内容仍由原配置处理。Nginx 仅新增 `/ads/` 路径,中继路径不缓存、不记录含票据的访问 URL。
## 服务器安装位置
| 项目 | 位置 |
|---|---|
| 程序 | `/opt/ads/ads-server` |
| 角色令牌 | `/etc/ads/server.env`,root 专用,0600 |
| systemd | `/etc/systemd/system/ads-server.service` |
| 内部监听 | `127.0.0.1:18081`,不开放公网 |
| Nginx 路径配置 | `/etc/nginx/snippets/ads-path.conf` |
| 主站配置 | 在现有 `zz-ttstd-main.conf` 的 `ttstd.com:443` 块中加入 include |
| 配置备份 | `/var/backups/ads/<UTC 时间>/` |
中继使用独立的 `ads` 系统用户,已设置开机启动、故障重启、`GOMEMLIMIT=128MiB` 和 systemd `MemoryMax=256M`。部署后 systemd 报告空闲服务内存约 2.8 MiB;这是当时的服务 cgroup 计量,不是负载峰值或完整机器内存。
管理命令:
```sh
systemctl status ads-server --no-pager
journalctl -u ads-server -n 50 --no-pager
systemctl restart ads-server
curl --noproxy '*' --resolve ttstd.com:443:127.0.0.1 https://ttstd.com/ads/healthz
```
TLS 沿用现有主站证书,核验到的有效期截止 `2026-11-28 06:59:59 UTC`。需要按现有主站证书管理方式及时续期;本次未接管或修改其续期流程。
## 远程 Windows 电脑
复制以下文件并保持目录结构,角色配置不要公开或提交 Git:
```text
<部署目录>/
bin/ads-agent.exe
scripts/start-agent.ps1
config/private/agent.env
```
在该部署目录执行:
```powershell
.\scripts\start-agent.ps1
```
脚本默认接入手机 `192.168.100.141:5555`,注册 ID 为 `home-phone`。该地址必须从远程电脑可达。也可覆盖 `-Target` 和 `-Device`。此直接 TCP 模式不需要对公网暴露远程 ADB Server。
## 本地 Windows 电脑
本地配置位于 `config/private/client.env`,已配置目录 ACL 并被 Git 忽略。该文件只包含客户端角色凭据和非敏感连接地址,不包含服务器 root 密码。
```powershell
.\scripts\start-client.ps1
# adb 不在 PATH 时:
.\scripts\start-client.ps1 -Adb 'F:\AndroidSDK\platform-tools\adb.exe'
```
默认端口 `127.0.0.1:15555`。另开终端:
```powershell
adb devices -l
adb -s 127.0.0.1:15555 shell
scrcpy -s 127.0.0.1:15555
```
启动脚本读取角色令牌,不把令牌放到程序命令行。直接运行二进制时,需自行加载对应环境变量;`--server` 可省略,但若当前 DNS 链路仍不可达,需设置 `ADS_CONNECT_ADDRESS` 或显式传入源站地址。
## 域名如果以后改为独立子域名
当前根域名路径已经可用。若改成 `ads.ttstd.com`,需要额外完成以下三步,不能只添加 DNS 就直接使用:
1. DNS 添加 A 记录:主机名 `ads`,值 `175.178.213.60`,先用“仅 DNS”(关闭 Cloudflare 橙云),TTL 自动或 300 秒。不要修改现有根域名或其他子域名记录。
2. 服务器新增该域名的 Nginx 虚拟主机,取得覆盖 `ads.ttstd.com` 的公有 TLS 证书,并配置 WebSocket 反向代理。现有主站证书不覆盖此子域名。
3. 两端改用 `--server wss://ads.ttstd.com`。DNS 直连稳定后可去掉 `--connect-address` / `ADS_CONNECT_ADDRESS`。
## 本次验证
已使用正式 Rust 二进制经公网 Linux 中继完成真实手机测试:普通本地 `adb devices` 显示为 `device`,读取型号 `AOSP on crosshatch`,Shell 回显正确。临时网关为本地启动并借助已有 VPN 访问远程 ADB;因此该测试证明公网中继的数据路径,尚未证明远程 Windows 上开机自启或完全关闭 VPN 后的现场部署。
可复现命令(角色令牌只从私有文件读取):
```powershell
python tests/real_device.py --relay-url wss://ttstd.com/ads --connect-address 175.178.213.60:443 --credentials-dir config/private --adb-server 192.168.5.222:5037 --serial 192.168.100.141:5555
```
+2
View File
@@ -4,6 +4,8 @@ All requests use `Authorization: Bearer <token>`. Agent and client roles have se
## Endpoints
Paths below are relative to the relay base URL. A reverse proxy can strip a prefix such as `/ads/`; the deployed default base is `wss://ttstd.com/ads`. An optional TCP origin override preserves the URL hostname for HTTP Host, TLS SNI and certificate validation.
| Endpoint | Role | Purpose |
|---|---|---|
| `GET /healthz` | Public | Liveness only |
+8 -1
View File
@@ -20,4 +20,11 @@ Read-only real-device smoke test:
- App installation, Android Studio and scrcpy have not yet been exercised through the new path.
- Temporary processes and local ADB endpoint were disconnected after the test; unrelated local ADB devices were preserved.
No public server was deployed. Production WSS certificates, real Internet latency, and Linux/macOS runtime behavior still need deployment-environment validation. The Linux Go server is cross-built separately; cross-building is not a Linux runtime test.
Public deployment follow-up:
- Linux amd64 server is now running on Debian 12 at `175.178.213.60`, as an enabled systemd service under a dedicated user.
- Existing Nginx proxies `https://ttstd.com/ads/` to loopback `127.0.0.1:18081`, stripping the prefix. Its existing root-domain certificate was verified without disabling certificate checks.
- A real public WSS smoke test passed: both Rust daemons connected to the public origin while keeping TLS SNI/hostname `ttstd.com`; ordinary local ADB listed `127.0.0.1:59671` as `device`, and both read-only shell commands passed.
- The test gateway still used the existing VPN-reachable remote ADB Server to reach the phone. Installing the gateway on the remote Windows PC and verifying with VPN disabled remain separate deployment steps.
- Public Cloudflare DNS connectivity timed out from the current PC; the explicit origin-address option was used. No DNS records were changed.
- macOS runtime and Linux Rust daemon hosting remain untested. See `deployment-ttstd.md` for deployed configuration and certificate expiry.