feat: 优化代理准备并完善远端部署
- 增加严格代理、两分钟预取、白名单去重与分组状态展示\n- 增加远端注册令牌和安全地址校验\n- 增加 Docker Compose、Caddy 示例与控制中心部署文档
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# 发布到镜像仓库后改为固定版本镜像,例如 ghcr.io/owner/douyu-control:v1.0.0
|
||||
DOUYU_CONTROL_IMAGE=douyu-control:local
|
||||
|
||||
# 中国大陆服务器可使用 https://goproxy.cn,direct
|
||||
GOPROXY=https://proxy.golang.org,direct
|
||||
|
||||
# 宿主机只监听回环地址,由 Caddy 暴露 HTTPS。
|
||||
DOUYU_CONTROL_HOST_PORT=18080
|
||||
|
||||
# 管理网页令牌,与注册令牌必须不同。
|
||||
DOUYU_CONTROL_OPERATOR_TOKEN=replace-with-openssl-rand-hex-32
|
||||
|
||||
# 桌面端“注册令牌”填写同一个值。
|
||||
DOUYU_CONTROL_ENROLL_TOKEN=replace-with-another-openssl-rand-hex-32
|
||||
|
||||
# 仅在未设置注册令牌时启用自动注册窗口。
|
||||
DOUYU_CONTROL_ENROLL_WINDOW=10m
|
||||
@@ -0,0 +1,2 @@
|
||||
.env
|
||||
data/
|
||||
@@ -0,0 +1,14 @@
|
||||
control.example.com {
|
||||
encode zstd gzip
|
||||
|
||||
reverse_proxy 127.0.0.1:18080 {
|
||||
flush_interval -1
|
||||
}
|
||||
|
||||
header {
|
||||
Strict-Transport-Security "max-age=31536000"
|
||||
Referrer-Policy "no-referrer"
|
||||
X-Content-Type-Options "nosniff"
|
||||
X-Frame-Options "DENY"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
FROM golang:1.26-alpine AS build
|
||||
|
||||
ARG TARGETOS=linux
|
||||
ARG TARGETARCH=amd64
|
||||
ARG GOPROXY=https://proxy.golang.org,direct
|
||||
|
||||
ENV GOPROXY=${GOPROXY}
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download github.com/gorilla/websocket
|
||||
|
||||
COPY internal ./internal
|
||||
COPY cmd/douyu-control ./cmd/douyu-control
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
|
||||
go build -trimpath -ldflags="-s -w" -o /out/douyu-control ./cmd/douyu-control
|
||||
|
||||
FROM alpine:3.22
|
||||
|
||||
RUN apk add --no-cache ca-certificates tzdata \
|
||||
&& addgroup -S -g 10001 douyu \
|
||||
&& adduser -S -D -H -u 10001 -G douyu douyu \
|
||||
&& mkdir -p /data \
|
||||
&& chown douyu:douyu /data \
|
||||
&& chmod 0700 /data
|
||||
|
||||
ENV TZ=Asia/Shanghai \
|
||||
DOUYU_CONTROL_ADDR=:18080 \
|
||||
DOUYU_CONTROL_DATA=/data
|
||||
|
||||
COPY --from=build /out/douyu-control /usr/local/bin/douyu-control
|
||||
|
||||
USER 10001:10001
|
||||
|
||||
EXPOSE 18080
|
||||
VOLUME ["/data"]
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD wget -qO- http://127.0.0.1:18080/api/health >/dev/null || exit 1
|
||||
|
||||
ENTRYPOINT ["douyu-control"]
|
||||
@@ -0,0 +1,109 @@
|
||||
# 远端控制中心部署
|
||||
|
||||
该目录只包含控制中心的部署文件。Go 源码仍位于仓库的 `cmd/douyu-control` 和 `internal/remote`,避免桌面端 Agent 与控制中心协议分叉。
|
||||
|
||||
## 架构
|
||||
|
||||
```text
|
||||
Internet
|
||||
-> Caddy 443
|
||||
-> 127.0.0.1:18080
|
||||
-> douyu-control 容器
|
||||
-> ./data
|
||||
```
|
||||
|
||||
Caddy 不放入该 Compose。继续使用宿主机现有 Caddy,避免重复申请证书和占用 80/443。
|
||||
|
||||
## 首次部署
|
||||
|
||||
```bash
|
||||
cd deploy/control-center
|
||||
cp .env.example .env
|
||||
openssl rand -hex 32
|
||||
openssl rand -hex 32
|
||||
```
|
||||
|
||||
把两个随机值分别填入 `.env`:
|
||||
|
||||
```text
|
||||
DOUYU_CONTROL_OPERATOR_TOKEN=管理网页令牌
|
||||
DOUYU_CONTROL_ENROLL_TOKEN=桌面实例注册令牌
|
||||
```
|
||||
|
||||
创建数据目录并交给容器用户:
|
||||
|
||||
```bash
|
||||
sudo install -d -m 0700 -o 10001 -g 10001 data
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
如果服务器无法访问 `proxy.golang.org`,将 `.env` 中的 `GOPROXY` 改为可用的 Go 模块代理,例如 `https://goproxy.cn,direct`。
|
||||
|
||||
检查:
|
||||
|
||||
```bash
|
||||
curl http://127.0.0.1:18080/api/health
|
||||
docker compose ps
|
||||
docker compose logs -f --tail=100
|
||||
```
|
||||
|
||||
## Caddy
|
||||
|
||||
把 `Caddyfile.example` 中的配置改好域名后加入宿主机现有 Caddy 站点配置,然后验证并重载:
|
||||
|
||||
```bash
|
||||
sudo caddy validate --config /etc/caddy/Caddyfile
|
||||
sudo systemctl reload caddy
|
||||
```
|
||||
|
||||
公网防火墙只开放 `80/443`,不要开放 `18080`。Caddy 会自动处理 HTTPS 和 Agent WebSocket Upgrade。
|
||||
|
||||
## 桌面实例
|
||||
|
||||
每个实例填写:
|
||||
|
||||
```text
|
||||
控制中心地址: https://control.example.com
|
||||
注册令牌: 与 DOUYU_CONTROL_ENROLL_TOKEN 相同
|
||||
```
|
||||
|
||||
实例首次连接时使用注册令牌换取独立实例令牌,之后复用本机凭据。控制中心不需要保存桌面端的注册令牌。
|
||||
|
||||
## 管理网页
|
||||
|
||||
```text
|
||||
https://control.example.com/#admin=<DOUYU_CONTROL_OPERATOR_TOKEN>
|
||||
```
|
||||
|
||||
`#admin` 不会发送给服务器,页面读取后会从地址栏移除。
|
||||
|
||||
## 数据与备份
|
||||
|
||||
```text
|
||||
data/
|
||||
events.ndjson
|
||||
runs.ndjson
|
||||
agent_tokens.json
|
||||
```
|
||||
|
||||
`agent_tokens.json` 丢失后,已有实例需要重新注册。至少每天备份一次整个 `data` 目录。
|
||||
|
||||
当前 NDJSON 不会自动轮转。长期运行前需要增加应用层保留策略,不能只依赖 Docker 容器日志轮转。
|
||||
|
||||
## 升级
|
||||
|
||||
使用本地构建:
|
||||
|
||||
```bash
|
||||
docker compose build --pull
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
使用镜像仓库时,将 `.env` 中的 `DOUYU_CONTROL_IMAGE` 改为固定版本,然后:
|
||||
|
||||
```bash
|
||||
docker compose pull
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
升级不会删除 `data`。控制中心只能运行一个副本,不能直接水平扩容。
|
||||
@@ -0,0 +1,34 @@
|
||||
name: douyu-control
|
||||
|
||||
services:
|
||||
control-center:
|
||||
image: ${DOUYU_CONTROL_IMAGE:-douyu-control:local}
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: deploy/control-center/Dockerfile
|
||||
args:
|
||||
GOPROXY: ${GOPROXY:-https://proxy.golang.org,direct}
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
DOUYU_CONTROL_ADDR: ":18080"
|
||||
DOUYU_CONTROL_DATA: "/data"
|
||||
TZ: "Asia/Shanghai"
|
||||
ports:
|
||||
- "127.0.0.1:${DOUYU_CONTROL_HOST_PORT:-18080}:18080"
|
||||
volumes:
|
||||
- ./data:/data
|
||||
restart: unless-stopped
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop:
|
||||
- ALL
|
||||
stop_grace_period: 20s
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "20m"
|
||||
max-file: "3"
|
||||
Reference in New Issue
Block a user