Files
ssw-mvp/docs/scard/VM_DEPLOY.md
T
admin 3247e9fd15 init: ssw-mvp initial commit
- boot/ (Java/Maven, JNPF 7.0) — 移除旧的 boot/.git,源码直接纳入仓库
- web/ (Vue 3 + Vite + Ant Design Vue, pnpm)
- docs/, scard/, nax/
- refs/INDEX.md + refs/国标/(其余 refs/* 开源子仓库不纳入)
- 已忽略: connector_data/, jweb/, log/, web/{dist,node_modules,.pnpm}, boot/*/target/, .DS_Store, .idea, .vscode
2026-08-05 18:29:12 +08:00

8.5 KiB
Raw Blame History

SSWFlow 跨节点部署:VM j7node + 本机

本文件记录 SSWFlow 在 OrbStack 虚机上以"k3s + Pod"模式部署的完整步骤与已知坑, 用于跨节点数据流通演示(VM connector → 本机 scard server → 本机 tds 安全平面镜像)。

1. 部署架构

┌──────────────────────────────────────────┐    ┌────────────────────────────────────┐
│  本机 (macOS 192.168.97.x)               │    │  OrbStack VM j7node (resolute)    │
│                                          │    │  192.168.139.196  4G 内存  15G盘  │
│  ┌────────────────────────────────────┐  │    │                                    │
│  │  scard server :8443 (Go)          │◀─┼────┼── connector (Go) 192.168.139.67   │
│  │  ├─ 软 PKI  ca-cert.pem           │  │    │  ├─ device_id=J7NODE-001          │
│  │  └─ attestation strict / TOFU      │  │    │  └─ 连 https://192.168.139.3:8443  │
│  └────────────────────────────────────┘  │    │                                    │
│  ┌────────────────────────────────────┐  │    │  ┌─── k3s v1.30.5 (systemd) ──────┐ │
│  │  ssw-admin :30000 (Java/Spring)   │◀─┼────┼──┤  NodePort 31000                │ │
│  │  ├─ DB=j7+j7flow_node1+tdc_node1  │  │    │  │   ├─ j7-postgres-0 (Pod)       │ │
│  │  │  连 PG 192.168.1.18:15432      │  │    │  │   ├─ j7-redis (Pod)            │ │
│  │  └─ 前端 web/ 5173                │  │    │  │   └─ j7-admin (Pod, 1.5G JVM)  │ │
│  └────────────────────────────────────┘  │    │  └───────────────────────────────┘ │
└──────────────────────────────────────────┘    └────────────────────────────────────┘

2. 准备步骤

2.1 建 VM(OrbStack 4G 内存起步)

orbctl create --memory 4G --cpus 2 --disk 32G ubuntu j7node

VM 启动后安装 Java 21 + Redis:

orb -m j7node bash -c '
  sudo DEBIAN_FRONTEND=noninteractive apt-get update -qq
  sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq openjdk-21-jdk-headless redis-server curl iptables nftables
  sudo sed -i "s/^bind .*/bind 127.0.0.1/" /etc/redis/redis.conf
  sudo systemctl restart redis
'

2.2 装 k3s(systemd 方式,绕过 OrbStack session 回收)

VM 内 github release 受限,用 gh-proxy 加速:

orb -m j7node bash -c '
  curl -sfL --max-time 180 -o /tmp/k3s \
    "https://gh-proxy.com/https://github.com/k3s-io/k3s/releases/download/v1.30.5+k3s1/k3s"
  sudo install -m 0755 /tmp/k3s /usr/local/bin/k3s
'

写 systemd unit(必须用 systemd,nohup/disown/setsid 在 OrbStack session 下都会被回收):

/etc/systemd/system/k3s.service:

[Unit]
Description=Lightweight Kubernetes (k3s)
Wants=network-online.target
After=network-online.target

[Install]
WantedBy=multi-user.target

[Service]
Type=notify
ExecStart=/usr/local/bin/k3s server --disable=traefik --disable=servicelb --write-kubeconfig-mode=644
KillMode=mixed
Restart=always
RestartSec=5s
LimitNOFILE=65536
StandardOutput=journal
StandardError=journal
sudo systemctl daemon-reload
sudo systemctl enable k3s
sudo systemctl start k3s
# 等 ~30s
sudo /usr/local/bin/k3s kubectl get nodes

2.3 配置 containerd registry mirror

/etc/rancher/k3s/registries.yaml:

mirrors:
  "docker.io":
    endpoint:
      - "https://docker.m.daocloud.io"
  "crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com":
    endpoint:
      - "https://crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com"

关键:docker.io 在 OrbStack VM 内被墙(registry-1.docker.io:443 timeout), 必须用 daocloud 镜像源;pause 镜像默认从 docker.io 拉,不配 mirror 永远 ContainerCreating。

sudo systemctl restart k3s

3. 部署清单

5 个 yaml 在 scard/code/bin/k8s/:

文件 内容
00-namespace.yaml ns=j7 + PV/PVC(hostPath /var/lib/j7node/pg-data)
05-pg-init.yaml ConfigMap 00-create-dbs.sql:建 j7 / j7flow_node1 / tdc_node1 库(j7_node1 由 POSTGRES_DB 自动建)
10-postgres.yaml StatefulSet + Service(postgres:16-alpine, 5Gi hostPath)
20-redis.yaml Deployment + Service(redis:latest,--requirepass 123456)
30-admin.yaml Deployment + Service NodePort 31000(liberica-openjre-rocky:21 + hostPath jar)

apply:

sudo /usr/local/bin/k3s kubectl apply -f /Users/xs/Desktop/ssw/scard/code/bin/k8s/
sudo /usr/local/bin/k3s kubectl -n j7 get pods

预期:

j7-admin-f48cdcd6-...   1/1   Running
j7-postgres-0           1/1   Running
j7-redis-...            1/1   Running

admin 完整启动需要 ~90s(Spring Boot + 4 数据源 init + Quartz + Redisson 24 连接)。

外部访问:admin NodePort http://192.168.139.196:31000/api/oauth/Login

4. Connector 部署(Go 二进制裸跑,不放 Pod)

connector 是 Go 静态二进制,没有对应阿里云镜像,直接放 VM 内裸跑:

orb -m j7node bash -c '
  /Users/xs/Desktop/ssw/scard/code/bin/connector-linux-amd64 \
    --server https://192.168.139.3:8443 \
    --device-id J7NODE-001 \
    --tpm-type software \
    --register \
    --tls-ca /Users/xs/Desktop/ssw/scard/code/bin/tls/ca-cert.pem \
    --data-dir /var/lib/j7node/connector-data \
    > /opt/ssw/logs/connector.log 2>&1
'

预期 host server log:

[POST] /api/v1/device/enroll-nonce 192.168.139.3
[POST] /api/v1/device/register   192.168.139.3
[REGISTER] admitted device=J7NODE-001 attestation=tofu-recorded pcr_digest=...

5. 已知坑(项目级)

  1. JNPF 平台主库硬编码 db-name: j7 —— admin pod 必须连 j7 库,否则报 database "j7" does not exist。init script 多建 CREATE DATABASE j7。
  2. redis 默认无密码但 admin 要求 123456 —— redis 容器必须 --requirepass 123456。
  3. JNPF 7 多租户登录(singleLogin=2):账号必须带 @tenantId 后缀(如 admin@0),且对应独立 DB——VM 端 j7_node1 是空 schema 无法登录,业务查询报 relation "base_sys_config" does not exist。
  4. JNPF 密码算法:md5(md5(plain) + secretkey),不是单纯的 md5(plain)。
  5. OrbStack session 退出 SIGHUP 所有子进程 —— 必须用 systemd / run_in_background 长任务,nohup + setsid + disown 都无效。
  6. k3s binary 下载(VM 内):github release 受限,用 gh-proxy.com;本机下载后可用 install -m 0755 推到 /usr/local/bin/。
  7. NodePort 范围 30000-32767 —— admin 用 31000 而非 33000。
  8. OrbStack VM 内存:默认 866MB 跑 SSWFlow 会 OOM(exit 137),必须 --memory 4G 起新 VM。
  9. docker.io 在 OrbStack VM 内被墙:必须配 containerd mirror,否则 pause 镜像拉不下来 pod 卡 ContainerCreating。
  10. PVC 重建:删 StatefulSet 时 PVC 不会自动删,需手动 kubectl delete pvc j7-pg-data + kubectl delete pv j7-pg-data-pv + rm -rf /var/lib/j7node/pg-data/* 才能重 init。

6. 待办

  • 把本机 j7 库的 331 张表 schema dump → VM j7 库,让 admin pod 跑完整业务(耗时)
  • 把 VM pod 切到 hostNetwork / HostPort 暴露给 VM 外的访问
  • JVM heap 调优(当前 Xmx1500m,pod ready 后 GC 频繁)

7. 端到端验证清单

步骤 命令 期望
k3s ready sudo /usr/local/bin/k3s kubectl get nodes j7node Ready control-plane,master
pod ready sudo /usr/local/bin/k3s kubectl -n j7 get pods 3 个 pod 都 1/1 Running
admin NodePort curl -sk http://192.168.139.196:31000/api/oauth/Login HTTP 200(登录返回 400 是空 schema 预期)
connector 注册 VM 上 connector log [RUNNING] Registered device: J7NODE-001 (status: active)
host scard curl -sk https://127.0.0.1:8443/api/v1/device/status | jq '.[].device_id' 包含 J7NODE-001