From 181b338780a8be31e03f34128014aaddf7589c2c Mon Sep 17 00:00:00 2001
From: Zhou Weidong <502333560@qq.com>
Date: Wed, 28 Oct 2026 18:23:48 +0800
Subject: [PATCH] =?UTF-8?q?fix(ops):=20=E4=BF=AE=E5=A4=8D=E7=AE=A1?=
=?UTF-8?q?=E7=90=86=E7=AB=AF=20Redis=20=E6=9C=AA=E9=85=8D=E7=BD=AE?=
=?UTF-8?q?=E4=B8=8E=E7=9C=8B=E9=97=A8=E7=8B=97=E6=9C=AA=E7=9C=9F=E6=AD=A3?=
=?UTF-8?q?=E5=91=A8=E6=9C=9F=E5=B7=A1=E6=A3=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- admin-api 的 application.yml 缺少 spring.data.redis 配置,容器内默认连
127.0.0.1 导致 /actuator/health 返回 DOWN(redis 组件不可用);
补齐后与 app-api 共用 REDIS_HOST/REDIS_PORT,健康检查恢复 UP
- 计划任务原先用 BootTrigger 挂 Repetition,Windows 不生效(Next Run Time
为 N/A,9 小时只跑过一次),看门狗形同虚设;改为 TimeTrigger + PT2M
无限重复 + StartWhenAvailable,实测每 2 分钟稳定巡检
- watchdog.ps1 的连续失败计数改为落盘 watchdog-state.json,避免每轮进程
重启后清零导致「连续 3 次失败告警」永不触发
---
deploy/backend-watchdog-task.xml | 10 ++++++++--
deploy/watchdog.ps1 | 19 ++++++++++++++++++-
.../src/main/resources/application.yml | 6 ++++++
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/deploy/backend-watchdog-task.xml b/deploy/backend-watchdog-task.xml
index b58a9cf..88f59d2 100644
--- a/deploy/backend-watchdog-task.xml
+++ b/deploy/backend-watchdog-task.xml
@@ -17,11 +17,17 @@
PT10M
-
+
+
+ 2026-01-01T00:00:00
PT2M
+ P3650D
+ false
-
+
diff --git a/deploy/watchdog.ps1 b/deploy/watchdog.ps1
index 404211f..3dde3d8 100644
--- a/deploy/watchdog.ps1
+++ b/deploy/watchdog.ps1
@@ -91,8 +91,18 @@ $checks = @(
@{ Name = "Prometheus"; Type = "http"; Url = "http://127.0.0.1:9090/-/healthy"; Service = "prometheus"; Container = "fruitshorts-prometheus" }
)
-# 跟踪每个服务的连续失败次数
+# 跟踪每个服务的连续失败次数。脚本由计划任务每 2 分钟拉起一次,
+# 进程内变量会跨轮丢失,因此计数持久化到状态文件,否则「连续 3 次告警」永远不触发。
+$StateFile = Join-Path $LogDir "watchdog-state.json"
$failCounts = @{}
+if (Test-Path $StateFile) {
+ try {
+ (Get-Content $StateFile -Raw | ConvertFrom-Json).PSObject.Properties |
+ ForEach-Object { $failCounts[$_.Name] = [int]$_.Value }
+ } catch {
+ Write-Log "状态文件损坏,重置连续失败计数"
+ }
+}
foreach ($check in $checks) {
$name = $check.Name
@@ -168,3 +178,10 @@ if ($drive) {
Send-Alert "磁盘告警" "C 盘使用率 ${pct}%,请清理日志或扩容"
}
}
+
+# 落盘本轮结束时的连续失败计数,供下一轮接着累计
+try {
+ $failCounts | ConvertTo-Json | Set-Content -Path $StateFile -Encoding UTF8
+} catch {
+ Write-Log "状态文件写入失败: $_"
+}
diff --git a/fruitshorts-admin-api/src/main/resources/application.yml b/fruitshorts-admin-api/src/main/resources/application.yml
index 41372e4..2930a0c 100644
--- a/fruitshorts-admin-api/src/main/resources/application.yml
+++ b/fruitshorts-admin-api/src/main/resources/application.yml
@@ -14,6 +14,12 @@ spring:
url: ${DB_URL:jdbc:postgresql://127.0.0.1:5432/fruitshorts}
username: ${DB_USER:fruitshorts}
password: ${DB_PASSWORD:fruitshorts}
+ data:
+ redis:
+ # 与 app-api 共用同一个 Redis 实例;容器内必须显式指定 host,
+ # 否则 Spring Boot 默认连 127.0.0.1(容器内即自身)导致健康检查报 DOWN。
+ host: ${REDIS_HOST:127.0.0.1}
+ port: ${REDIS_PORT:6379}
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: Asia/Shanghai