快速部署

如果你只想尽快看到第一台节点在线,先按下面的最短路径走;生产环境的细化配置放在下一节。

一键安装(推荐)

交互式安装器,适合快速上手

服务端一条命令安装。脚本会自动检测架构、校验二进制哈希、生成配置和 systemd unit。

服务端安装
# 一条命令安装,同样命令也可用于升级
curl -fsSL https://github.com/XiNian-dada/NodeLite/releases/latest/download/install-server.sh | sudo sh
升级服务端
curl -fsSL https://github.com/XiNian-dada/NodeLite/releases/latest/download/install-server.sh | \
  sudo NODELITE_SERVER_MODE=upgrade sh
安装脚本会自动引导你输入安装目录、监听端口、对外域名和面板账号密码。

开始前确认

  • 一台可 SSH 的 Linux 主机,用来部署 nodelite-server
  • 一台或多台 Linux 子机,用来部署 nodelite-agent
  • 服务端建议预留一个域名,后面用于 HTTPS / WSS 和安装脚本分发
  • 生产环境建议提前放行 80/443,并让服务端只监听回环地址

如果只是本地验证,先用内网 IP 或临时域名也可以,跑通后再补反向代理。

跑通后检查

  • 服务端 systemctl status nodelite-serveractive (running)
  • Agent 日志中出现成功连接到 /ws 的记录
  • 浏览器打开面板后能看到至少一台节点处于在线状态
  • /metrics 可以被抓取,或至少本地 curl 返回 Prometheus 文本

进阶配置

当第一台节点已经跑起来后,再看这一节会更容易理解,也更适合生产环境使用。

手工部署 适合需要精细控制配置的进阶用户
  1. GitHub Releases 下载对应架构的 nodelite-server 二进制
  2. 复制 config/server.example.toml 并修改关键配置(监听地址、域名、认证凭据、GeoIP 模式等)
  3. 将二进制安装到 /usr/local/bin/nodelite-server,配置文件放到 /opt/nodelite/config/server.toml
  4. 创建 systemd unit 并启动
  5. 执行 install-agent 签发节点命令
查看服务状态
sudo systemctl status nodelite-server.service
sudo journalctl -u nodelite-server.service -f
如果服务端起不来,第一时间检查 sudo journalctl -u nodelite-server.service -n 100 --no-pager
节点定位 & GeoIP 默认用 ipwhois 在线查询,dbip 只在需要本地数据库时启用
默认行为

NodeLite 默认使用 provider = "ipwhois" 在线查询 GeoIP,不需要下载 DB-IP Lite 数据库。

如果切到 provider = "dbip",才会启用数据库下载,右下角的 DB-IP attribution 也只在这个模式下显示。

GeoIP 配置示例
[geoip]
enabled = true
provider = "ipwhois"
edition = "country-lite"
database_path = "./data/geoip/dbip.mmdb"
手动位置优先

如果你在节点设置页手动指定了位置,手动结果会覆盖自动 GeoIP;需要离线使用本地数据库时再改成 provider = "custom" 并指定自己的 database_path

节点签发 & Agent 部署 在服务端生成含一次性 token 的安装命令,粘贴到目标子机执行
服务端签发节点
# 在服务端执行,生成一条可直接粘贴到子机执行的安装命令
/usr/local/bin/nodelite-server \
  --config /opt/nodelite/config/server.toml \
  install-agent \
  --node-id hk-01 \
  --node-label "Hong Kong 01"
子机执行(复制上一步的输出)
curl -fsSL https://monitor.example.com/install/install-agent.sh | \
  NODELITE_AGENT_INSTALL_TOKEN='one-time-token' sh -s -- \
  --bootstrap-url https://monitor.example.com/install/bootstrap \
  --base-url https://github.com/XiNian-dada/NodeLite/releases/latest/download
Agent 升级
# 不需要重新 bootstrap,保留现有 agent.toml
curl -fsSL https://monitor.example.com/install/install-agent.sh | \
  NODELITE_AGENT_MODE=upgrade sh -s -- \
  --base-url https://github.com/XiNian-dada/NodeLite/releases/latest/download
token 提示

一次性 install token 有效期 15 分钟。过期后重新执行 install-agent 生成新的 token 即可。

长期 node token 只在 bootstrap 响应体中下发,不会出现在 URL 或命令参数中。

反向代理配置 Nginx 终结 HTTPS/WSS,服务端监听回环地址

生产环境推荐:nodelite-server 监听 127.0.0.1:<port>,Nginx 对外暴露 443 端口。

Nginx 配置参考
server {
    listen 443 ssl http2;
    server_name monitor.example.com;

    ssl_certificate     /path/to/fullchain.pem;
    ssl_certificate_key /path/to/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:<port>;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /ws {
        proxy_pass http://127.0.0.1:<port>/ws;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 120s;
        proxy_send_timeout 120s;
    }

    location /install/ {
        proxy_pass http://127.0.0.1:<port>;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
Caddy 也可用 — 自动 TLS、无需手动配置证书。同机反代不需要额外配 trusted_proxies
Prometheus 集成 NodeLite 提供 /metrics 端点,输出 Prometheus exposition 文本

/metrics 与仪表盘共用只读认证,抓取端需带上同样的 Basic Auth 凭据。

验证
curl -u '<readonly-username>:<generated-strong-password>' https://monitor.example.com/metrics
Prometheus 配置
scrape_configs:
  - job_name: nodelite
    scheme: https
    metrics_path: /metrics
    basic_auth:
      username: <readonly-username>
      password: <generated-strong-password>
    static_configs:
      - targets:
          - monitor.example.com
交叉编译 在开发机上构建 Linux 静态二进制

仓库内置 musl 目标的 lld 链接配置,可直接交叉编译静态二进制。

构建
cargo build --release --target x86_64-unknown-linux-musl \
  -p nodelite-server \
  -p nodelite-agent

cargo build --release --target aarch64-unknown-linux-musl \
  -p nodelite-server \
  -p nodelite-agent

常见问题

部署和使用中可能遇到的问题及解决方法。

先检查 Agent 日志:

sudo journalctl -u nodelite-agent.service -n 50 --no-pager

常见原因:

  • Agent 配置中的 server 不是 wss:// 或证书有问题
  • 反向代理未正确转发 WebSocket(检查 UpgradeConnection 头)
  • Agent 的 node token 与服务端 server.json 不匹配
  • 防火墙未放行 443 端口或 WebSocket 路径

系统架构

按当前源码绘制:Agent 采集并通过 WebSocket 上报,Server 认证、清洗、聚合、持久化,再向 Web UI、JSON API 和 Prometheus 暴露视图。

整体运行架构

从部署入口到 Agent 上报、Server 内存状态、历史写入和前端读取的主路径。

Linux Agent 节点 runtime::run 加载 agent.toml 配置 HostCollector 读取 /proc/stat、meminfo、loadavg 读取 net/dev、mounts、statvfs 生成节点身份与监控快照 session::run_forever hello / metrics / pong / logs 消息 nodelite-server 进程 /ws handler 接入控制与 Hello 握手 NodeRegistry 认证节点并维护 token 代次 Authenticated Session 清洗上报快照 记录 ping/pong 延迟 SharedState 节点状态 总览视图 / 缓存 HistoryStore 有界队列 + 批量写入 AgentLogStore / AuditLog 运行日志 + 安全事件 外部访问 Nginx / Caddy HTTPS / WSS 终结 Web 面板 / API / · /api/* · /metrics 本地持久化 server.json history/audit.sqlite3 wss / WireMessage 认证 认证通过 更新 日志 / 审计 历史点 读取缓存视图 代理 /ws 代次

Server 内部组件图

AppState 是 Axum handler 和 WebSocket 会话拿到的共享上下文,后台任务围绕注册表、快照和离线状态运行。

startup::run_server 加载配置 / 构建路由 / 启动后台任务 AppState handlers::* 页面 / API / 设置 安装 / 认证路由 ws::session Hello 握手 -> 认证 指标 / 心跳 / 刷新 token SharedState 内存中的注册表 视图版本 + 缓存 auth / admission Basic Auth + TOTP IP 封禁 / WS 准入 NodeRegistry server.json Argon2id token 哈希 HistoryStore mpsc 队列 SQLite 批量写入 AgentLogStore / AuditLog 近期 Agent 日志 audit.sqlite3 background tasks 重载注册表 / 清理陈旧节点 持久化快照 受保护路由 读 / 写 清洗后状态 记录状态 日志 / 事件 清理缺失 节点

WebSocket 协议时序

握手、认证、实时上报、心跳 RTT、token 刷新和断开处理都在一条已认证会话里完成。

Agent Server /ws Registry / State connect wss://domain/ws hello(protocol_version, token, identity) authorize_identity + token_generation AuthorizedNode server_notice(info, authenticated) metrics(snapshot) sanitize + update_snapshot + history enqueue ping(nonce) pong(nonce) update_latency refresh_token_response(new_token, expires_at)

存储、安全与部署边界

敏感凭证不直接暴露给前端;Registry、History、Audit 与 Snapshot 分别承担授权、趋势、安全事件和恢复。

访问入口 Web UI / JSON API / Metrics Basic Auth 保护 ReadonlyRouteAuth + TOTP pending/auth cookie 仅存随机 token TOTP step 防重放 Admission Controllers /ws 连接配额 install / 2FA / sensitive auth 失败封禁 Server 数据边界 server.json Argon2id token_hash / generation history.sqlite3 history_points + WAL + indexes audit.sqlite3 login / TOTP / token / rate limit snapshot.json 15s restore point 部署与恢复 Nginx / Caddy TLS / WSS / real client IP nodelite-server 127.0.0.1:8080 graceful shutdown + final flush nodelite-agent agent.toml token 原子替换 指数退避重连 auth events install bootstrap read/write state /ws snapshot