部署到 Google Cloud

在 Google Cloud Compute Engine 或 Cloud Run 上部署 nostrfy — 分步说明,含 systemd、TLS 和缩容到零的注意事项。

选项:Compute Engine(VM,推荐)或 Cloud Run (容器)。

选项 1:Compute Engine(推荐)

  1. 创建 VM:Ubuntu 24.04 LTS(或 Debian),e2-small(2 GB) 起步足够。选择离用户近的区域。
  2. 防火墙规则:允许入站 TCP 8080(以及 443 用于 TLS)。在 Network → Firewall 下,用你分配给 VM 的目标标签创建规则。
  3. SSH 登录(控制台的 SSH 按钮即可)并按照通用 VPS 指南操作:
sh
curl -fsSL https://raw.githubusercontent.com/iqbqioza/nostrfy/main/install.sh | sh
sudo mkdir -p /etc/nostrfy
sudo curl -fsSL -o /etc/nostrfy/nostrfy.toml \
  https://raw.githubusercontent.com/iqbqioza/nostrfy/main/deploy/nostrfy.toml
sudo nano /etc/nostrfy/nostrfy.toml                 # 设置 name、public_url、private_key
sudo curl -fsSL -o /etc/systemd/system/nostrfy.service \
  https://raw.githubusercontent.com/iqbqioza/nostrfy/main/deploy/nostrfy.service
sudo systemctl daemon-reload
sudo systemctl enable --now nostrfy
  1. 预留静态 IP(External IP → Reserve),使 public_url 在 重启后仍然有效。
  2. 验证:
sh
curl http://<external-ip>:8080/health
  1. 添加 TLS(wss://)用 certbot + nginx(如 VPS 指南)或带托管证书的 GCP 负载均衡器。

选项 2:Cloud Run(容器)

Cloud Run 从仓库的 Dockerfile 构建(它会下载预编译的发布 二进制):

  1. 从 GitHub 仓库创建服务(或将镜像推送到 Artifact Registry)。
  2. 端口:将容器端口设置为 8080。
  3. 分配内存:至少 512 MB(LMDB + 异步运行时)。
  4. 持久存储:在 /data 附加 Cloud Run 卷(filestore/gcsfuse) — LMDB 需要文件系统,因此在 /data 挂载 GCS FUSE 可实现持久化。
  5. TLS:Cloud Run 自动提供 https:// — 设置 relay.public_url = "wss://<service>.a.run.app"(或你的自定义域)。
Cloud Run 默认缩容到零
对于中继,设置 min instances = 1 使其永不变冷。烘焙到镜像中的 deploy/nostrfy.container.toml 可以通过在 /etc/nostrfy/nostrfy.toml 挂载你自己的 nostrfy.toml 来替换。