零服务器成本:基于 Cloudflare 打造极简 Web 管理面板Zero Server Cost: Building a Minimalist Web Management Panel on Cloudflare


AI free token/AI免费积分

本文来源:https://mp.weixin.qq.com/s/7-GWTlxYeBmRFnxFWzuh6A
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

文章末尾附有代码,如需要更详细资料,请关注公众号并发送主机中继

图片图片图片

 

手里有几台散落各地的云服务器?或者家里有一台没有公网 IP 的 NAS 闲置着? 每次想要连上去看看运行状态、敲几行命令,不是要掏出终端软件找私钥,就是要折腾内网穿透软件,十分繁琐。

今天分享一个轻量级项目 —— host-relay。

这是一个纯靠 Cloudflare Workers 免费额度支撑的主机管理面板。只要你的机器能连上网,就能在浏览器里随时随地看到它的实时运行状态,并且一键唤出 Web SSH 终端。整个项目没有复杂的微服务,架构极简,非常适合各位 Homelab 玩家和独立开发者部署自用。


免费、轻量、自主可控

相比于市面上沉重的运维面板,host-relay 在设计思路上做了大量的“减法”,带来了以下几个直戳痛点的优势:

1. 完全白嫖,零服务端机器成本

不需要你自己准备一台公网服务器来做控制端。它的服务端是一个单文件 worker.js,跑在 Cloudflare Workers 上,并利用了免费版的 Durable Objects (SQLite-backed) 来保持长连接和存储数据。对于个人玩家那几台主机的体量,资源消耗极低,稳稳落在 CF 的免费额度内。

2. 天然无视 NAT,没有公网 IP 也能连

采用了类似 frp 的反向隧道模型。受控主机上的 Agent 会主动向 CF 边缘节点发起出站 WSS(WebSocket Secure)长连接。因为是主动出站,所以它完全不在乎你的机器是不是藏在深层局域网、有没有公网 IP,天然完成了内网穿透。

3. 极简的单文件架构

  • • 服务端:仅一个 worker.js 文件。
  • • 客户端 (Agent):用 Go 编写的单静态二进制文件,没有任何外部依赖,支持 Linux、macOS 和 Windows。不用装一堆环境,扔上去就能跑。

4. 丝滑的全功能 Web SSH

在面板点击“管理”,直接在浏览器里弹出一个基于 xterm.js 的终端窗口。支持多标签页同时开多个会话,终端大小也会跟随你的浏览器窗口自适应缩放(Resize)。

5. 状态实时推送,告别卡顿轮询

主机的 CPU、内存、磁盘容量和运行时长等指标,是由 Agent 定期上报,再通过 WebSocket 实时推送到你的浏览器上的。不需要依靠网页定时刷新去轮询获取,状态变化秒级响应。

6. 把安全放在第一位

  • • 一机一码防冒充:面板分配专属的 hostId 和一次性注册 token,杜绝任何未经授权的节点接入。
  • • 最高级别的私钥认证:除了支持常规的密码 SSH 登录外,它还支持本地私钥认证。你只需在 Agent 启动时指定机器上的私钥文件,私钥内容永远不会经过网络,网页上选“私钥登录”就能直接连,安全性拉满。
  • • 严格防范 SSRF:Agent 写死了只连接本地指定的端口(默认 127.0.0.1:22),绝不盲信服务端下发的连接目标,避免被当作肉鸡跳板。

部署方式

部署分为“服务端”和“客户端”两步。服务端部署在 Cloudflare,客户端跑在你的服务器上。

第一步:部署服务端 (Cloudflare Workers)

由于项目用到了 Durable Objects 的数据库迁移(migration)功能,首次部署必须通过命令行工具 wrangler 进行。

1. 拉取代码并登录进入目录,登录你的 Cloudflare 账号:

cd host-relaynpx wrangler login

2. 初始化部署创建 DO 命名空间:

npx wrangler deploy

3. 配置安全密钥配置四个必需的安全密钥(可以在命令行敲,也可以去 CF 网页后台的 Settings -> Variables & Secrets 里手动填):

npx wrangler secret put ADMIN_PASSWORD   # 面板的登录密码npx wrangler secret put SESSION_SECRET   # 用于签发会话的随机字符串npx wrangler secret put TICKET_KEY       # 用于签发 SSH ticket 的随机字符串npx wrangler secret put ENC_KEY          # 用于加密保存 SSH 密码的 AES-GCM 密钥

小贴士:强烈建议在 CF 后台给这个 Worker 绑定一个你自己的自定义域名。一来国内访问更稳定,二来后续配置也会方便很多。以后如果项目代码有更新,直接把新的 worker.js 源码复制粘贴到 CF 网页编辑器里保存就行了。

第二步:添加主机并运行客户端 Agent(默认有已编译好的客户端供下载)

1. 登录面板浏览器访问你刚才绑定的域名,用 ADMIN_PASSWORD 登录面板。

2. 生成配置点击**「添加主机」**,随便起个名字。面板会立刻给你弹出一行带有专属 ID 和 Token 的启动命令。

3. 下载客户端把 Agent 的二进制文件下载到你的目标服务器上(项目源码 src/agent 目录下提供了跨平台的 build.sh 编译脚本,一键就能编出各个平台的程序)。

4. 启动 Agent在你的目标服务器上执行刚才面板给出的命令:

./agent --server wss://你的域名 --id h_xxxx --token tk_xxxx --ssh-target 127.0.0.1:22

私钥模式:如果你对安全有极高要求,不想在网页输密码,可以在上面这行命令末尾加上 --ssh-key /root/.ssh/id_rsa,开启纯私钥模式。

只要敲下回车,你的管理面板上就会“叮”地一声,跳出这台机器的实时状态卡片了。点击卡片上的「管理」按钮,尽情在浏览器里享受 SSH 的乐趣吧!

进阶建议:如果你希望这个 Agent 在 Linux 机器上能一直常驻后台、开机自启,最稳妥的做法是写一个简单的 Systemd 服务,把 ExecStart 指向这行运行命令即可。


总结

这套方案极大地降低了个人多终端管理的门槛和成本。它摆脱了臃肿的商业化依赖,将轻量、免费与高度的自主可控完美结合。如果你也需要一个安全、省心、随时随地都能接入的主机控制台,不妨动手部署体验一下。

Source: https://mp.weixin.qq.com/s/7-GWTlxYeBmRFnxFWzuh6A If there is a copyright issue, please report at: 13951431913#139.com or submit a comment on the right.

Code is attached at the end of the article. For more detailed information, please follow the official account and send "host relay".

图片图片图片

Do you have several scattered cloud servers? Or a NAS at home without a public IP? Every time you want to connect to check the running status or run a few commands, you have to either pull out a terminal software and find the private key, or mess with NAT traversal software, which is very cumbersome.

Today, I am sharing a lightweight project — host-relay.

This is a host management panel that runs entirely on Cloudflare Workers' free quota. As long as your machine is connected to the internet, you can instantly see its real-time status in the browser and launch a web SSH terminal with one click. The entire project has no complex microservices and a minimalistic architecture, making it perfect for homelab enthusiasts and independent developers to deploy for personal use.

Free, Lightweight, and Self-hosted

Compared to bulky commercial monitoring panels, host-relay employs a "less is more" design philosophy, offering the following pain-point solutions:

1. Completely Free, Zero Server Cost

You don't need to provision a separate public server to act as the control hub. The server component is a single worker.js file running on Cloudflare Workers, utilizing the free Durable Objects (backed by SQLite) for persistent connections and data storage. For a handful of personal machines, the resource consumption is negligible and well within CF's free tier limits.

2. NAT-agnostic, No Public IP Required

It uses a reverse tunnel model similar to frp. The client agent on your machine actively establishes an outbound WSS (WebSocket Secure) connection to the CF edge node. Because it is an "outbound" connection initiated by the client, it bypasses all NAT and firewall issues, allowing you to connect to machines deep within private networks or without public IPs.

3. Minimalist Single-file Architecture

• Server: Only one worker.js file.

• Client (Agent): A single static binary written in Go, with no external dependencies. It supports Linux, macOS, and Windows, meaning you don't need to install a full suite of development libraries just to run it.

4. Smooth, Full-featured Web SSH

With a single click on "Manage," a browser-based terminal window opens using xterm.js. You can open multiple tabs for different sessions simultaneously, and the terminal size adapts automatically to your browser window.

5. Real-time Status Updates, No Polling Lag

The machine's CPU, memory, disk capacity, and uptime are collected by the agent and pushed to the dashboard in real-time via WebSocket. This eliminates the need for the web page to constantly poll the server, resulting in instant updates when the status changes.

6. Security First

• Unique ID per Machine: The panel assigns a distinct hostId and a one-time registration token to each device, preventing unauthorized nodes from joining the network.

• Highest Level of Key Authentication: In addition to standard password SSH login, it supports local private key authentication. You can specify the path to your private key file in the agent configuration on the remote machine. The private key itself is never transmitted over the network; the browser simply prompts you to select the "key" mode, and the connection is established locally, maximizing security.

• Strict SSRF Prevention: The agent is hard-coded to only connect to a local, pre-defined port (default 127.0.0.1:22). It does not accept arbitrary connection targets dictated by the server, protecting against exploitation as a relay for malicious traffic.

Deployment Guide

The deployment process is divided into two parts: setting up the server (Cloudflare) and installing the client agent on your target machines.

Step 1: Deploy the Server (Cloudflare Workers)

Since the project requires a database migration for the Durable Object, the initial deployment must be performed via the command line using the wrangler tool.

1. Clone the Repository and Log In Navigate to the project folder and authenticate with Cloudflare:

2. Initialize the Deployment Create the necessary Durable Object namespace:

3. Configure Security Keys You must define four required environment secrets (either directly in the command line as shown or manually through the CF Dashboard under Settings > Variables & Secrets):

Pro tip: It is highly recommended to bind a custom domain to this worker in the CF dashboard. This not only ensures more stable access from your region but also simplifies the configuration of subsequent hosts. If you need to update the code in the future, simply copy the new worker.js source into the CF editor.

Step 2: Add Hosts and Run the Client Agent

1. Log into the Dashboard Open your browser and navigate to the domain you just bound. Log in with the ADMIN_PASSWORD you set earlier.

2. Generate the Agent Configuration Click **"Add Host"** and give your machine a descriptive name. The system will instantly generate a line of code containing a unique ID and a transient token specific to this machine.

3. Download the Client Binary Ensure you have the agent binary for your specific operating system (Linux, macOS, or Windows). The project provides a build script (build.sh) in the src/agent directory to compile the Go code into these binaries.

4. Start the Agent On your target server, execute the command line provided by the dashboard:

Private Key Mode: For enhanced security, if you wish to use SSH keys instead of logging in with a password on the web interface, append the following flag to the start command: --ssh-key /path/to/your/private/key.

Once the agent is running, the dashboard will display a real-time status card for that machine. Simply click the "Manage" button on the card to open the web-based SSH terminal.

For Linux users, if you want the agent to start automatically at boot, it is best practice to create a simple Systemd service definition, pointing the ExecStart directive to this run command.

总结

This solution significantly lowers the threshold and cost of managing personal multi-terminal devices. It breaks free from the reliance on bulky commercial services, combining lightweight, free, and highly self-controlled features. If you also need a secure, worry-free, and always-accessible host control console, it's worth trying out by setting it up.

暂无评论,快来发表第一条评论吧!No comments yet. Be the first!

📮 需求咨询📮 Inquiry