klt-site-112-rootless-部署维护手册.md 29 KB

klt-site(112.12.24.92)Rootless 部署维护手册

实例:恪澜通运营支撑(SEOH klt-site + klt-bos)
主机:112.12.24.92,SSH 22047,用户 sxtadmin(rootless Podman)
公网入口:https://bos.sxtwork.cn:20443
更新:2026-11-29(补充登录端到端障碍、令牌续签、前端构建与重建连带)


1. 拓扑与路径

角色 路径 / 名称
SEOH 现场包 /home/sxtadmin/seoh/klt-site
Compose 项目名 klt-site(容器名前缀 klt-site-,网络 klt-site-net)
BOS 后端 / 前端静态 /home/sxtadmin/klt-bos(容器 klt-bos、klt-bos-web)
持久化数据(bind) /home/sxtadmin/klt-data/{postgres,minio,kafka,gitea}
备份产物 /home/sxtadmin/klt-data/backups/{postgres,oss}
备份脚本 /home/sxtadmin/klt-data/bin/klt-backup-*.sh
安装介质(可选保留) /home/sxtadmin/delivery/(含 .bin / images-offline,约 4G)
运行时凭证与证书 /home/sxtadmin/seoh/klt-site/deploy-data/(部署后不可整体删除,见 §6)

公网端口(DNAT → 本机)

公网 本机 用途
20443 443(klt-bos-web nginx) BOS HTTPS(bos.sxtwork.cn)
23000 3000(api-gateway) SEOH API(直连调试)
28080 8080(portal) SEOH Portal

证书:/opt/certs/bos.sxtwork.cn.{pem,key},挂入 klt-bos-web。


2. Rootless 要点(必读)

  1. 一律用 sxtadmin + podman,不要 sudo podman。
  2. Linger 已开(loginctl show-user sxtadmin -p Linger → yes),用户 systemd / 备份 timer 在登出后仍运行。
  3. UID 映射:/etc/subuid 为 sxtadmin:100000:65536。
    • 容器内 uid=0 → 宿主机 sxtadmin
    • 容器内 uid=N → 宿主机 100000+(N-1)(例如 999→100998,1001→101000)
  4. 禁止在宿主机直接 chown 999 / chown 1001(全局无此 uid,会失败)。需要时:

    podman unshare chown -R 999:999 /home/sxtadmin/klt-data/postgres
    podman unshare chown -R 1001:0  /home/sxtadmin/klt-data/kafka
    
  5. SELinux:共享目录用 container_file_t:s0(不要用带 cXX,cYY 的私有 MCS,否则其它容器读 CA 会 Permission denied)。修正示例:

    chcon -R -t container_file_t -l s0 ~/seoh/klt-site/deploy-data/certs
    chcon -R -t container_file_t -l s0 ~/klt-data
    
  6. 操作前确保会话总线可用:

    export XDG_RUNTIME_DIR=/run/user/$(id -u)
    export DBUS_SESSION_BUS_ADDRESS=unix:path=${XDG_RUNTIME_DIR}/bus
    export PATH="$HOME/.local/bin:$PATH"
    

3. 日常启停

现场目录:

cd ~/seoh/klt-site
set -a; source .env; set +a

scripts/container-cli.sh 已自动追加(若存在):

  • docker-compose.ports.yml
  • docker-compose.bind-data.yml

推荐入口:

./seoh-start.sh          # 或 scripts/seoh-ctl.sh start
./seoh-stop.sh           # stop(不删卷)
# 慎用:./scripts/seoh-ctl.sh purge   # down -v,会删 named volume;bind 目录本身仍在

等价手动:

podman-compose \
  -f docker-compose.release.yml \
  -f docker-compose.instances.yml \
  -f docker-compose.network-name.yml \
  -f docker-compose.ports.yml \
  -f docker-compose.bind-data.yml \
  up -d

BOS:

podman start klt-bos klt-bos-web   # 或按既有 run 命令重建
podman logs -f klt-bos

健康抽查:

podman ps --format '{{.Names}} {{.Status}}' | sort
podman exec klt-site-postgres pg_isready -U postgres
curl -skf https://127.0.0.1:443/ >/dev/null && echo bos-web-ok

4. 数据持久化(bind mount)

覆盖文件:~/seoh/klt-site/docker-compose.bind-data.yml
仓库参考副本:temp/remote-deploy/docker-compose.bind-data.yml

服务 宿主机 容器内 属主策略
postgres ~/klt-data/postgres /var/lib/postgresql/data unshare chown 999:999
minio ~/klt-data/minio /data sxtadmin
kafka ~/klt-data/kafka /bitnami/kafka unshare chown 1001:0
gitea ~/klt-data/gitea /data cp -a(子目录常为 1000)

校验是否为 bind(勿只看 volume 名):

podman inspect klt-site-postgres --format '{{range .Mounts}}{{if eq .Destination "/var/lib/postgresql/data"}}{{.Type}} {{.Source}}{{end}}{{end}}'
podman inspect klt-site-kafka    --format '{{range .Mounts}}{{if eq .Destination "/bitnami/kafka"}}{{.Type}} {{.Source}}{{end}}{{end}}'
podman inspect klt-site-minio    --format '{{range .Mounts}}{{if eq .Destination "/data"}}{{.Type}} {{.Source}}{{end}}{{end}}'
podman inspect klt-site-gitea    --format '{{range .Mounts}}{{if eq .Destination "/data"}}{{.Type}} {{.Source}}{{end}}{{end}}'

期望均为 bind /home/sxtadmin/klt-data/...。


5. 备份(systemd --user timer)

Unit 时间 动作
klt-backup-pg.timer 每天 ≈02:30 pg_dumpall → ~/klt-data/backups/postgres/<UTC>/
klt-backup-oss.timer 每天 ≈03:00 MinIO mc mirror 打包 → ~/klt-data/backups/oss/

保留约 7 天(脚本内 KLT_BACKUP_KEEP_DAYS)。

systemctl --user list-timers 'klt-backup-*'
systemctl --user start klt-backup-pg.service    # 立即试跑
systemctl --user start klt-backup-oss.service
tail -20 ~/klt-data/backups/postgres/backup.log
tail -20 ~/klt-data/backups/oss/backup.log

单元文件:~/.config/systemd/user/klt-backup-*.{service,timer}
模板:temp/remote-deploy/backup/


6. deploy-data:保留、权限收紧与可删项

6.1 不要整体清理

deploy-data/ 是 运行时依赖,不是安装临时目录。容器持续 bind:

子路径 用途
secrets/ postgres/minio/kafka 等密码(/run/secrets/*)
certs/、keys/ mTLS、JWT 签名、root-ca、master.key
bootstrap-token-*.env 服务启动换票(重建容器仍要读;仅 start 不重载)

删掉会导致无法重启/重建。

6.2 Rootless 下的权限模型(已对本实例执行)

微服务多以容器内 uid=999 运行。Rootless 映射下,宿主机文件若 chmod 600 且属主为 sxtadmin(对应容器 root),则 uid=999 读不了,下次重启会报 Permission denied。

因此采用:

对象 模式 说明
deploy-data/、secrets/、keys/ 目录 700 同机其它用户无法进入目录列出/打开文件
secrets/*、私钥、master.key、private.pem 644 供容器内非 root 读取;靠父目录 700 兜底,勿把目录放开
*.crt / public.pem 644 公钥/证书
bootstrap-token-*.env 600 仅宿主机注入用;已写入容器 env 后运行时不依赖打开该文件
SELinux container_file_t:s0 避免 :Z 打上私有 MCS 导致其它容器读 CA 失败

收紧命令(可重复执行):

DD=~/seoh/klt-site/deploy-data
chmod 700 "$DD" "$DD/secrets" "$DD/keys"
chmod 644 "$DD"/secrets/*
chmod 644 "$DD"/keys/private.pem "$DD"/keys/master.key "$DD"/keys/public.pem
chmod 600 "$DD"/bootstrap-token-*.env
find "$DD/certs" -type f -name '*.key' -exec chmod 644 {} +
find "$DD/certs" -type f \( -name '*.crt' -o -name 'public.crt' \) -exec chmod 644 {} +
find "$DD/certs" -type d -exec chmod 755 {} +
chcon -R -t container_file_t -l s0 "$DD/secrets" "$DD/keys" "$DD/certs"

冒烟:

podman exec klt-site-token-issuer sh -c 'id; cat /etc/seoh/keys/private.pem >/dev/null && echo PRIV_OK'
podman exec klt-site-keybox sh -c 'cat /etc/seoh/keys/master.key >/dev/null && echo MASTER_OK'
podman exec klt-site-postgres sh -c 'cat /run/secrets/postgres_password >/dev/null && echo PG_OK'
podman restart klt-site-token-issuer klt-site-keybox   # 确认重启后仍能读

禁止在未验证的情况下对私钥统一 chmod 600 后直接重启全栈。

6.3 部署后可删的体积项

路径 约大小 条件
deploy-data/docker-images/*.tar(如 rust-*-slim-bookworm.tar) ~866M 仅 wasm 编译基座缓存;podman images 里已有对应 rust 基座后可删,缺了再跑 scripts/ensure-wasm-compiler-base-image.sh

本实例曾保留该 tar(当时本地无 rust 镜像标签);磁盘紧时再评估删除。


7. Bootstrap Token 过期(部署/重建必做)

微服务启动依赖短时 Bootstrap JWT。停机或重建过久后会出现:

Bootstrap … Token 已过期 (code=11009)

连带现象(本实例已踩过):

  • 网关回 50000 未找到匹配路由(注册中心/网关换票失败,路由表未刷新)
  • identity-provider/otp-service 等日志里 bootstrap 换运行期 JWT 失败
  • 登录页验证码偶发成功、但后续业务 API 全挂

处理(在 compose up / force-recreate 之前):

cd ~/seoh/klt-site
./bin/seoh-bootstrap-resign \
  --private-key deploy-data/keys/private.pem \
  --profile deploy-profile.json \
  --output bootstrap-tokens.csv \
  --ttl 86400 \
  --key-id key-2025-01
BOOTSTRAP_CSV="$PWD/bootstrap-tokens.csv" bash scripts/replicas.sh inject
# 再 up / 重建需要新 env 的容器

要点:

  1. --ttl:默认现场常按 3600 秒;运维窗口长时用 86400(24h),避免「签完还没 recreate 完又过期」。
  2. env_file 只在创建时写入容器;只 podman start / restart 不会加载新 bootstrap,必须 recreate。
  3. 校验容器内票是否新鲜:

    podman inspect klt-site-identity-provider \
    --format '{{range .Config.Env}}{{println .}}{{end}}' | grep '^BOOTSTRAP_TOKEN=' \
    | python3 -c "import sys,base64,json,time; t=sys.stdin.read().split('=',1)[1].strip();
    p=json.loads(base64.urlsafe_b64decode(t.split('.')[1]+'==')); print('left',p['exp']-int(time.time()))"
    
  4. 重建连带:podman-compose up --force-recreate 即使带 --no-deps,仍可能因依赖图停掉大量下游容器(本实例 recreate service-registry 时级联 SIGKILL 过 wasm/flow/nfsd 等)。重建鉴权链路后应用 seoh-start.sh 或逐个 podman start 把停掉的服务拉齐,再查 podman ps。

  5. 网络名必须先 source .env:seoh_set_compose_files 会按 SEOH_SITE_NETWORK(本实例=klt-site-net)重写 docker-compose.network-name.yml。若未加载 .env,会默认写成 seoh-network 并新建第二张网,部分容器挂到错误网络后出现 dns error: failed to lookup … seoh-token-issuer(本实例 recreate 时已踩)。操作前:

    cd ~/seoh/klt-site
    set -a; source .env; set +a   # 确保 SEOH_SITE_NETWORK=klt-site-net
    # 确认 override:
    # networks.seoh-network.name 必须是 klt-site-net(可 external: true)
    cat docker-compose.network-name.yml
    

若已分裂:把误挂在 seoh-network 的容器 network disconnect 后 network connect --alias seoh-<svc> klt-site-net,再 podman start;必要时删掉空的 seoh-network。


8. 登录端到端(本实例实测口径)

公网登录页:https://bos.sxtwork.cn:20443/login
通路:浏览器 → klt-bos-web nginx(同源 /api/)→ klt-site-api-gateway → identity-provider/otp-service。

8.1 平台三步登录(与前端同形)

请求体一律包在 { "data": { … } };缺 data 会 HTTP 422(missing field data)。

  1. POST /api/system/seoh-identity-provider/otp/captcha/create@v1
  2. POST /api/system/seoh-identity-provider/auth/challenge/verify@v1(拿一次性 challenge_token)
  3. POST /api/system/seoh-identity-provider/auth/password@v1,头 X-Login-Challenge-Token

本实例 OTP_SERVICE_BYPASS_CAPTCHA_VERIFY=true ⇒ 验证码可填 0000(生产若关闭 bypass,必须看图输入)。

challenge/verify 与 auth/password 必须同一份 scope 上下文,否则 12006。业务前端固定走 end_user(⛔ 用 platform 登业务账号会读成「密码错误」)。

本实例前端已烘焙的空间上下文:

字段 值
tenant_id/project_id/scope_id 383023670995484672
env/stage prod/prod

8.2 登录名陷阱(极易踩)

IAM 中业务账号登录名无 klt_ 前缀:

角色 正确登录名 错误示例
总运营 admin klt_bos_admin
运营主账号 bos_ops_main klt_bos_ops_main
其它种子 bos_ops_sub/bos_team_lead/bos_ops/bos_ent/bos_sub/bos_partner/bos_operator 加 klt_ 前缀

若线上静态资源仍是旧包,登录页「本机联调账号」按钮可能填入 klt_bos_admin → 一律 12002。以 IAM 为准:

PGPW=$(tr -d '\r\n' < ~/seoh/klt-site/deploy-data/secrets/postgres_password)
podman exec -e PGPASSWORD="$PGPW" klt-site-postgres \
  psql -U postgres -d seoh_iam -c \
  "SELECT username, scope_type, scope_id, env, stage FROM iam_user.t_iam_user ORDER BY created_at;"

源码侧 IllustratedLoginPage 的 LOCAL_ACCOUNTS 已改为去掉前缀;部署后须确认 klt-bos-web 用的是新 dist(见 §11)。

8.3 种子口令(本实例)

与联调/测试手册一致(⛔ 勿与 deploy-data/secrets/root_user_password 混淆——那是平台 root 口令):

登录名 口令
admin/bos_partner/bos_operator/bos_sub KltBos#2026-Svc!
bos_ops_main KltOps#a890e3fav2
bos_ops_sub KltOps#75a0ab5ev2
bos_team_lead KltOps#fcff633bv2
bos_ops KltOps#44919bdav2
bos_ent KltOps#57f04896
平台 root(scope_type=platform,业务登录页不用) deploy-data/secrets/root_user_password

8.4 前端构建参数(公网页)

web-scaffold 构建时:

变量 公网部署期望 说明
ENV_KLT_API_BASE_URL 空串 同源;由 nginx location /api/ 反代到网关。若打成 https://api-gateway.*.seoh.local:3000,公网浏览器解析不到
OSS_SEOH_TENANT_ID/OSS_SEOH_PROJECT_ID 上表 ID 缺则登录页直接提示「缺少项目空间标识」
OSS_SEOH_ENV/OSS_SEOH_STAGE prod/prod 须与 IAM end_user 行一致

校验已部署包:

podman exec klt-bos-web sh -c \
  'grep -oE ".{40}api-gateway[^\"]{0,40}" /usr/share/nginx/html/static/js/index.*.js | head'
# 正常:出现 X="".trim() … 回退字面量可存在,但运行时 GATEWAY_BASE 必须是空串
podman exec klt-bos-web sh -c \
  'grep -oE "tenant_id:\"[0-9]+\".{0,80}env:\"[a-z]+\"" /usr/share/nginx/html/static/js/index.*.js | head'

8.5 nginx/DNS 陈旧

重建 api-gateway 后容器 IP 可能变;klt-bos-web 若仍解析旧 IP,/api/ 会失败。处理:

podman restart klt-bos-web
# 必要时确认 nginx 上游名是 seoh-api-gateway(compose 网络别名),不是写死 IP

8.6 identity-provider 迁移 schema

本实例曾出现 identity_provider 业务表在 schema identity_provider,而 _sqlx_migrations 落在 public,导致启动以为未迁移、缺列(如 subject_key)。处理口径:把迁移历史同步进业务 schema(或按现场包脚本重跑 ensure),确认:

curl -sk https://127.0.0.1:443/api/system/seoh-identity-provider/health@v1
# 期望 code=10000 且 database healthy

9. klt-bos 业务令牌过期(登录后 UDS 11000/KLT-S20006)

现象:平台三步登录成功,但页面报 UDS 11000: Token 验证失败: Token 已过期(已退避重试)(KLT-S20006)。
原因:klt-bos 调 UDS 用的是服务账号票(KLT_BOS_SERVICE_TOKEN + ~/klt-bos/app/keys/account_token.json),与用户登录票无关;短时 JWT 过期后业务全挂。

9.1 检查

podman inspect klt-bos --format '{{range .Config.Env}}{{println .}}{{end}}' \
  | grep '^KLT_BOS_SERVICE_TOKEN=' \
  | python3 -c "import sys,base64,json,time; t=sys.stdin.read().split('=',1)[1].strip();
p=json.loads(base64.urlsafe_b64decode(t.split('.')[1]+'==')); print('env left',p['exp']-int(time.time()))"
python3 - <<'PY'
import json,base64,time
d=json.load(open('/home/sxtadmin/klt-bos/app/keys/account_token.json'))
for k in ('access','access_token','refresh','refresh_token'):
  if k in d and d[k]:
    p=json.loads(base64.urlsafe_b64decode(d[k].split('.')[1]+'=='))
    print(k, 'left', p['exp']-int(time.time()))
PY

9.2 续签(推荐:用 admin 重新登录写票)

AccountTokenManager 持久文件字段名是 access/refresh/access_exp/refresh_exp。若只有 access_token/refresh_token/obtained_at,载入失败 ⇒ 只用环境变量裸票且无 refresh ⇒ 过期后无法自动续。

# 1) 三步登录拿 admin 新票(口令见 §8.3)后写入:
#    ~/klt-bos/app/keys/account_token.json  (须含 access+refresh+*_exp)
#    ~/klt-bos/app/keys/service_token.txt  (access 一行)
# 2) ~/klt-bos/app/.env 中 KLT_BOS_SERVICE_TOKEN=<access>
# 3) 清 SELinux 私有 MCS 后再 recreate(见 §9.3)
cd ~/klt-bos/app
set -a; source .env; set +a
podman-compose -f docker-compose.yml up -d --force-recreate
# 日志应有:账号票已从持久文件载入…
curl -sk -H "Authorization: Bearer $KLT_BOS_SERVICE_TOKEN" \
  https://127.0.0.1:443/api/klt/klt-bos/auth/context@v1   # 期望 code=10000

进程内可调 POST …/token/refresh@v1(Authorization: Bearer <refresh>)自动续;refresh 会旋转,须落盘成功。keys 若 :ro 挂载,续期只留内存,重启仍依赖文件/env。

9.3 SELinux:config/keys 挂载 Permission denied

podman run -v …:Z 会给目录打上私有 MCS(如 s0:c186,c460),下次 recreate 读不到配置 ⇒ Error: missing field 'server'(其实是 /app/config 空/拒读)。与 §6.2 相同口径:

chcon -R -t container_file_t -l s0 ~/klt-bos/app/config ~/klt-bos/app/keys \
  ~/klt-bos/app/openapi.yaml ~/klt-bos/certs
# 挂载用 :ro 即可,⛔ 不要再用 :Z;必要时 :z 或 --security-opt label=disable

9.4 uds-gateway 起不来(迁移表 schema)

与 IDP 同类:业务表在 uds_gateway,_sqlx_migrations 只在 public ⇒ 重启报 relation "t_uds_datasource" already exists。处理:

PGPW=$(tr -d '\r\n' < ~/seoh/klt-site/deploy-data/secrets/postgres_password)
podman exec -i -e PGPASSWORD="$PGPW" klt-site-postgres \
  psql -U postgres -d seoh_uds_gateway -v ON_ERROR_STOP=1 <<'SQL'
INSERT INTO uds_gateway._sqlx_migrations
  SELECT * FROM public._sqlx_migrations
ON CONFLICT (version) DO UPDATE SET
  description=EXCLUDED.description, success=EXCLUDED.success,
  checksum=EXCLUDED.checksum, execution_time=EXCLUDED.execution_time,
  installed_on=EXCLUDED.installed_on;
SQL
podman start klt-site-uds-gateway

9.5 组织档案/区域树打到 *.seoh.local(KLT-S20006)

现象:登录后进「组织与区域 → 区域管理」报
区域树结构取数失败(node/get_subtree):platform call failed: error sending request for url (https://api-gateway.dev.seoh.local:3000/…)(KLT-S20006)。

原因:klt-bos 的 PlatformClient 默认把平台口打到开发态网关主机名;容器内解析不到 *.seoh.local。与 §8.4「前端同源」是两条线——浏览器走 nginx 同源,业务容器调平台走 gateway.url。

本实例已落地:

# ~/klt-bos/app/config/prod.toml
gateway.enabled = false
gateway.url = "https://seoh-api-gateway:3000"

并在 compose/.env 注入(挂载同一份根 CA):

GATEWAY_CA_CERT_PATH=/etc/seoh/certs/root-ca.crt
CONFIG_CENTER_CA_CERT_PATH=/etc/seoh/certs/root-ca.crt

改完后须对 klt-bos recreate(仅 restart 不重读 env_file/挂载变更时同理),再验:

# 期望 code=10000,root.name=全网(或至少不再出现 seoh.local)
curl -sk -X POST 'https://127.0.0.1:443/api/klt/klt-bos/region/tree@v1' \
  -H "Authorization: Bearer <admin_access>" -H 'Content-Type: application/json' \
  -d '{"data":{}}'

9.6 区域树首次播种(RM hierarchy 空/作用域不匹配)

gateway.url 通了之后,还可能卡在 RM 数据本身:

RM/BOS 返回 含义 处理
13001 hierarchy not found 库里没有 {project_id}:klt.region 建逻辑树+虚根
13060 该逻辑树不属于当前调用方作用域 t_rt_hierarchy.scope_type/scope_id 与用户票不一致 业务票是 end_user/<project_id> ⇒ 树也必须是这对,不能写成 project
region/tree 有节点但 level 全 null 本地投影 bos.bos_region_meta 未写 补省级(及下级)层级行;虚根「全网」不入该表

本实例 project_id=383023670995484672。运维例外路径(end_user 调 hierarchy/create 会被 AC 11001 拒)可直写 RM 库后补投影:

PGPW=$(tr -d '\r\n' < ~/seoh/klt-site/deploy-data/secrets/postgres_password)
TENANT=383023670995484672
# 任选未占用的 snowflake 风格 bigint;下列为本实例已落地值
HID=383023670995484701
RID=383023670995484702   # 虚根「全网」
SH=383023670995484710; JS=383023670995484711; GD=383023670995484712

podman exec -i -e PGPASSWORD="$PGPW" klt-site-postgres \
  psql -U postgres -d seoh_resource_metadata -v ON_ERROR_STOP=1 <<SQL
SET search_path TO resource_metadata, public;
INSERT INTO t_rt_hierarchy (
  id, hierarchy_key, scope_type, scope_id, code, name, tree_kind, resource_type, status
) VALUES (
  $HID, '${TENANT}:klt.region', 'end_user', '${TENANT}',
  'klt.region', '区域树', 'region', 'klt.region', 'active'
) ON CONFLICT (hierarchy_key) DO UPDATE
  SET scope_type='end_user', scope_id='${TENANT}';
INSERT INTO t_rt_node (id, hierarchy_id, parent_id, materialized_path, depth, name, sort_order, status)
VALUES ($RID, $HID, NULL, '/${RID}/', 0, '全网', 0, 'active')
ON CONFLICT (id) DO NOTHING;
INSERT INTO t_rt_node (id, hierarchy_id, parent_id, materialized_path, depth, name, sort_order, status) VALUES
  ($SH, $HID, $RID, '/${RID}/${SH}/', 1, '上海市', 10, 'active'),
  ($JS, $HID, $RID, '/${RID}/${JS}/', 1, '江苏省', 20, 'active'),
  ($GD, $HID, $RID, '/${RID}/${GD}/', 1, '广东省', 30, 'active')
ON CONFLICT (id) DO NOTHING;
SQL

# 本地层级/闭包投影(表在 schema bos,⛔ public)
podman exec -i -e PGPASSWORD="$PGPW" klt-site-postgres \
  psql -U postgres -d "project_${TENANT}_prod" -v ON_ERROR_STOP=1 <<SQL
SET search_path TO bos, public;
INSERT INTO bos_region_meta (node_id, level, path_name, synced_at) VALUES
  ('$SH', '省', '上海市', NOW()),
  ('$JS', '省', '江苏省', NOW()),
  ('$GD', '省', '广东省', NOW())
ON CONFLICT (node_id) DO UPDATE SET
  level=EXCLUDED.level, path_name=EXCLUDED.path_name, synced_at=NOW();
INSERT INTO dim_node_ancestor (node_id, ancestor_id, depth) VALUES
  ('$RID','$RID',0),
  ('$SH','$SH',0),('$SH','$RID',1),
  ('$JS','$JS',0),('$JS','$RID',1),
  ('$GD','$GD',0),('$GD','$RID',1)
ON CONFLICT DO NOTHING;
SQL

端到端验收(本实例已过):公网登录 admin → 组织与区域 → 区域管理,左侧「区域树」见 全网/上海市/江苏省/广东省(4 节点),概况可点选省级;运营商页可打开(空表「暂无数据」属正常,非树故障)。

9.7 主导航页面端到端(2026-11-29 复测)

身份:公网 admin(end_user/本项目)。多数列表空表属正常(无业务种子)。

结果 页面
✅ 可进入、取数成功 概览;区域管理/运营商/合伙人/运营团队/运维团队;套餐配置/合同管理/客户管理/批量导入/全部订阅;分成管理/成本管理/对账清单/账单明细/出账更正记录/出账配置;工单总览/我的待办/全部工单/待分派/交付与回执/工单配置;定时任务;审计日志
❌ 仍失败 (无)

本轮为页面可进做过的库侧补齐(项目库 project_<id>_prod,schema bos;并在 uds_gateway.t_uds_virtual_table 登记 physical+抬升 t_uds_catalog_revision;ALTER/新建后须 restart klt-site-uds-gateway,否则易出现 cached plan must not change result type 或列名仍按旧 schema):

  1. 列对齐:catalog_plan.use_category→plan_family+plan_desc/created_team_id;subscription/contract_service_item 同类改名/补列(item_family、item_mode、serves_item_id、ref_subscription_id、parent_subscription_id 等)。
  2. 缺表补建并发布:ticket/ticket_open_stop/ticket_backfill/ticket_message/ticket_config;reconcile_batch/bill_detail/billing_config/billing_correction/billing_receivable*/billing_snapshot_share 等(空表即可让列表回 10000)。
  3. CREATE OR REPLACE VIEW public.<表> AS SELECT * FROM bos.<表>(全 bos 表):绕过 DML 写死 public.bos_* 的路径(否则定时任务写 bos_job_run 会报 relation does not exist)。

批量导入曾红 → 已修(应用侧):UDS/DataFusion 不支持 jsonb ->/->>(Arrow),相关 string_agg 子查询也会触发 scalar_subquery_to_join 失败。import_batch/get_list 改为列表只查批次头,客户名整列拉回后在 Rust 汇总;空表回 10000/「没有匹配的记录」属正常。


10. 常见故障

现象 处理
chown 999: Permission denied / 无此用户 改用 podman unshare chown …
读 /etc/seoh/certs/root-ca.crt Permission denied 清 MCS:chcon -R -t container_file_t -l s0 deploy-data/certs
私钥 chmod 600 后服务重启失败 容器内 uid=999 读不了;按 §6.2 用目录 700 + 文件 644
podman rm 报 dependent containers 从叶子服务起迭代 podman rm -f,或整栈 stop 后再删;勿对 postgres 乱 --depend
kafka 起不来、secrets Permission denied 检查 deploy-data/secrets 权限与 SELinux 标签(§6.2)
compose up 卡住在少数容器 查 health / bootstrap;可 pkill -f podman-compose 后按依赖 podman start
备份 timer 不跑 确认 Linger、XDG_RUNTIME_DIR、systemctl --user status
登录 12002/点「总运营」仍失败 确认登录名为 admin 非 klt_bos_admin;口令用 §8.3,勿用 root_user_password
登录 422 missing field data 请求体缺 {data:…} 包裹
登录 12006 challenge 与 password 两步 scope 不一致,或重复使用已消费的 challenge_token
网关 50000 未找到匹配路由 bootstrap/注册中心过期或未 recreate;按 §7 续签后拉齐服务并重启 klt-bos-web
公网登录请求打到 *.seoh.local 前端未按 §8.4 以空串构建;重打 dist 并更新 klt-bos-web
组织档案 get_subtree 打到 *.seoh.local(KLT-S20006) klt-bos 的 gateway.url/CA;见 §9.5
region/tree:13001 hierarchy not found/13060 跨作用域 播种 {project}:klt.region,scope_type=end_user;见 §9.6
多页 UDS 13003 物理表尚未发布/No field named … 项目库缺表/缺列或未登记 UDS 虚拟表;见 §9.7
批量导入 KLT-S20006(日志含 Arrow/scalar_subquery_to_join) 旧二进制仍走 jsonb/相关子查询;换已修 klt-bos(见 §9.7)后应回 10000
recreate 一个服务后大量容器 Exited 级联停止;./seoh-start.sh 或逐个 podman start,再 resign 若 bootstrap 已在窗口内过期
dns error: … seoh-token-issuer/配置中心不可达 容器挂到了错误的 seoh-network;按 §7 先 source .env 钉死 klt-site-net 并迁回

11. 升级 / 重建注意

  1. 改 bind 或端口:只改 docker-compose.bind-data.yml / ports.yml,保证 container-cli.sh 仍会加载它们。
  2. 全量 up -d 前先 resign bootstrap(见 §7);运维窗口建议 --ttl 86400。
  3. 不要对 bind 目录做 rm -rf ~/klt-data/postgres 之类操作。
  4. purge / down -v 只影响 named volume;确认不再误删后仍要检查 ~/klt-data 是否完整。
  5. 不要删除整个 deploy-data/(见 §6);磁盘紧时仅评估 §6.3 与 ~/delivery 大包。
  6. 磁盘紧张时可删 ~/delivery/images-offline 与大型 .bin(需保留重装能力则先拷走)。
  7. 更新前端:按 §8.4 构建 → 同步到 ~/klt-bos/web/dist(或既有镜像)→ 重启 klt-bos-web;用 §8.2/§8.4 命令核对登录名与 GATEWAY_BASE。
  8. 重建网关/注册中心后:重启 klt-bos-web,并检查 klt-bos 业务令牌(§9)。

12. 本地运维参考副本

仓库 temp/remote-deploy/(部署一次性脚本已清理)保留:

  • docker-compose.bind-data.yml / docker-compose.ports.yml
  • nginx-bos-rootless.conf
  • backup/(备份脚本 + systemd unit)
  • ssh_cmd.sh、id_ed25519_deploy(仅运维机使用,勿提交到公开仓)

SSH 示例:

ssh -i temp/remote-deploy/id_ed25519_deploy -o IdentitiesOnly=yes -p 22047 sxtadmin@112.12.24.92