Files
danyang-match/infrastructure/scripts/health-check.sh
T
WorkBuddy 797b1c46cf refactor(storage): 对象存储从 MinIO 换成 SeaweedFS(钉 4.47)
动机:MinIO 的 GitHub 仓库已于 2026-02 归档,不再产出安全补丁,已累积多个
CVE 且不修;本项目存身份证 / 实名材料 / 用户照片,无人修 CVE 才是真正驱动因素
(Docker Hub 下架只是表象,quay.io 仍在提供)。

变更:
- 三套 compose(dev / staging / prod)的 minio 服务替换为 seaweedfs 4.47:
  覆盖 entrypoint 渲染 -s3.config 注入 identity(S3 网关默认不鉴权,必须显式开启),
  -volume.max=100 解除第二个 bucket 写入时的 InternalError。
- 新增一次性 storage-init 容器,经 filer 接口预建 public / private 桶
  (SeaweedFS PutObject 到不存在的 bucket 直接失败;全仓库原无任何 createBucket)。
- S3Config 显式开启 path-style:AWS SDK v1 默认 virtual-host 会把 bucket 拼进
  主机名,容器名在 DNS 中不存在必然失败(本机有 http_proxy 时易误判为 502 拒绝)。
- ci.yml:镜像校验与起栈步骤改为 seaweedfs + storage-init。
- 运维脚本 health-check.sh / run-uat.sh 的 MinIO 探针改为 SeaweedFS
  (S3 网关开启鉴权后匿名根请求返回 403,200/403 均算存活)。

注:path-style 与建桶属换存储的必要项;presigned URL 的 host 须对外可达这一
既有缺陷(原 minio:9000 直发客户端不可达)留待下一轮「改缺陷」处理。
2026-09-22 14:26:48 +08:00

78 lines
2.3 KiB
Bash

#!/bin/bash
# ============================================
# 丹阳公益婚恋服务平台 — 健康检查与监控脚本
# ============================================
# 用法:
# ./scripts/health-check.sh # 检查所有服务
# ./scripts/health-check.sh --detail # 详细输出
# ============================================
set -euo pipefail
COMPOSE_FILE="${COMPOSE_FILE:-../infrastructure/docker-compose.prod.yml}"
DETAIL="${2:-}"
EXIT_CODE=0
check_service() {
local name="$1"
local check="$2"
local result
result=$(eval "$check" 2>/dev/null || echo "FAIL")
if [ "${result}" = "OK" ]; then
echo " ✅ ${name}: ${result}"
else
echo " ❌ ${name}: ${result}"
EXIT_CODE=1
fi
}
echo "============================================"
echo " 丹阳公益婚恋服务平台 — 健康检查"
echo " $(date '+%Y-%m-%d %H:%M:%S')"
echo "============================================"
# 容器状态
echo ""
echo "【容器状态】"
docker compose -f "${COMPOSE_FILE}" ps --format "table {{.Name}}\t{{.Status}}\t{{.Ports}}" 2>/dev/null | head -10
# 服务检查
echo ""
echo "【服务检查】"
check_service "PostgreSQL" \
"pg_isready -h postgres -U ${DB_USER:-danyang} -d ${DB_NAME:-danyang_match} 2>/dev/null && echo OK || echo FAIL"
check_service "Redis" \
"redis-cli -h redis${REDIS_PASSWORD:+ -a ${REDIS_PASSWORD}} ping 2>/dev/null | grep -q PONG && echo OK || echo FAIL"
check_service "SeaweedFS" \
"curl -s -o /dev/null -w '%{http_code}' http://seaweedfs:8333/ 2>/dev/null | grep -qE '^(200|403)$' && echo OK || echo FAIL"
check_service "Backend API" \
"curl -sf http://localhost:8080/api/v1/health/live 2>/dev/null | grep -q success && echo OK || echo FAIL"
check_service "Backend Ready" \
"curl -sf http://localhost:8080/api/v1/health/ready 2>/dev/null | grep -q success && echo OK || echo FAIL"
check_service "Nginx" \
"curl -sf http://localhost/nginx-health 2>/dev/null && echo OK || echo FAIL"
# 详细输出
if [ "${DETAIL}" = "--detail" ]; then
echo ""
echo "【磁盘使用】"
docker system df 2>/dev/null || true
echo ""
echo "【内存使用】"
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" 2>/dev/null || true
fi
echo ""
if [ ${EXIT_CODE} -eq 0 ]; then
echo "✅ 所有服务正常"
else
echo "❌ 存在异常服务,请检查上方输出"
fi
exit ${EXIT_CODE}