From 10ea5e5eee29a4403f3ab62673a32abd085b1544 Mon Sep 17 00:00:00 2001 From: lzh Date: Thu, 23 Apr 2026 15:14:00 +0800 Subject: [PATCH] =?UTF-8?q?chore(video):=20ZLM=20=E5=87=AD=E8=AF=81?= =?UTF-8?q?=E6=8C=AA=E5=87=BA=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE=20+=20?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=B1=A0=20keep-alive=20+=20=E6=97=A5?= =?UTF-8?q?=E5=BF=97/=E9=98=9F=E5=88=97=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - application.yaml 里的 media.id/ip/http-port/secret/auto-config 改用 ${ZLM_*:占位} 形式,secret 默认值 please-override-in-env,防止 真实凭证写进默认 profile 被全环境继承;开发机实际值搬到 application-local.yaml,继续支持 env var 覆盖。已泄露到 git 历史 的 secret 需运维侧单独旋转。 - application-local.yaml druid 池:min-evictable-idle 从 10min 降到 5min + 打开 keep-alive,配合 eviction 扫描主动 ping,解决远程 MySQL 经 NAT/云防火墙 60~80s 静默断开导致 Communications link failure / last packet received X ms ago。 - application.yaml 补两个 video 模块运维开关: · viewsh.access-log.exclude-paths 屏蔽 /index/hook/on_server_keepalive 心跳刷屏,出错仍会 WARN; · video.sip-queue.enabled 管控上一笔 commit 引入的三个 SIP 消息 QueueScheduler,默认开启,关闭后队列会在内存堆积 需要运维兜底(注释已提醒慎用)。 --- .../src/main/resources/application-local.yaml | 17 +++++++++++- .../src/main/resources/application.yaml | 26 ++++++++++++++----- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/viewsh-module-video/viewsh-module-video-server/src/main/resources/application-local.yaml b/viewsh-module-video/viewsh-module-video-server/src/main/resources/application-local.yaml index b191dfeb..88b8746d 100644 --- a/viewsh-module-video/viewsh-module-video-server/src/main/resources/application-local.yaml +++ b/viewsh-module-video/viewsh-module-video-server/src/main/resources/application-local.yaml @@ -49,12 +49,18 @@ spring: max-active: 20 # 最大连接池数量 max-wait: 60000 # 配置获取连接等待超时的时间,单位:毫秒(1 分钟) time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位:毫秒(1 分钟) - min-evictable-idle-time-millis: 600000 # 配置一个连接在池中最小生存的时间,单位:毫秒(10 分钟) + # 远程 MySQL(124.222.218.x)经 NAT/云防火墙,空闲 60~80s 会被中间层静默断开。 + # 从 10 分钟改为 5 分钟:连接空闲达到这个阈值后开始走 keepAlive/回收逻辑。 + min-evictable-idle-time-millis: 300000 # 连接在池中最小生存时间(5 分钟) max-evictable-idle-time-millis: 1800000 # 配置一个连接在池中最大生存的时间,单位:毫秒(30 分钟) validation-query: SELECT 1 FROM DUAL # 配置检测连接是否有效 test-while-idle: true test-on-borrow: false test-on-return: false + # keep-alive: 每次 eviction 扫描(60s)时主动 ping 空闲超过 min-evictable-idle 的连接, + # 死连接直接剔除,避免 @Scheduled 任务低频借连接时踩上被中间层静默断开的死连接, + # 症状:RecoverableDataAccessException / Communications link failure / last packet received X ms ago + keep-alive: true pool-prepared-statements: true # 是否开启 PreparedStatement 缓存 max-pool-prepared-statement-per-connection-size: 20 # 每个连接缓存的 PreparedStatement 数量 primary: master @@ -115,6 +121,15 @@ spring: username: admin password: admin +--- #################### 本地开发专用:ZLM 媒体服务器配置 #################### +# 生产/测试环境请通过环境变量 ZLM_* 覆盖,不要直接把本地值改进 application.yaml +media: + id: ${ZLM_SERVER_ID:zlmediakit-local} + ip: ${ZLM_IP:192.168.0.104} + http-port: ${ZLM_HTTP_PORT:9092} + secret: ${ZLM_SECRET:u3UapOhmZa9er7S37Hc2k695NlZOBYdB} + auto-config: ${ZLM_AUTO_CONFIG:false} + # 日志文件配置 logging: level: diff --git a/viewsh-module-video/viewsh-module-video-server/src/main/resources/application.yaml b/viewsh-module-video/viewsh-module-video-server/src/main/resources/application.yaml index 876be774..5f9f6baa 100644 --- a/viewsh-module-video/viewsh-module-video-server/src/main/resources/application.yaml +++ b/viewsh-module-video/viewsh-module-video-server/src/main/resources/application.yaml @@ -108,6 +108,10 @@ viewsh: web: admin-ui: url: http://dashboard.viewsh.iocoder.cn # Admin 管理后台 UI 的地址 + # 访问日志:关掉 ZLM 每 10s 一次的心跳刷屏;出现异常或 4xx/5xx 时仍会打 WARN + access-log: + exclude-paths: + - /index/hook/on_server_keepalive xss: enable: false exclude-urls: @@ -149,17 +153,19 @@ sip: register-time-interval: 60 # ZLMediaKit 默认服务器配置 +# 真实连接参数(ip/http-port/secret)请通过环境变量或 application-{profile}.yaml 覆盖, +# 不要把具体环境的 secret 提交到默认 yaml。参考 application-local.yaml 里 MYSQL_* 的写法。 media: # ZLM 服务器唯一 ID(对应 ZLM general.mediaServerId) - id: your-zlm-server-id + id: ${ZLM_SERVER_ID:your-zlm-server-id} # ZLM 服务器内网 IP - ip: 127.0.0.1 + ip: ${ZLM_IP:127.0.0.1} # ZLM HTTP 端口 - http-port: 80 - # ZLM Hook 鉴权 secret(对应 ZLM hook.admin_params=secret) - secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc + http-port: ${ZLM_HTTP_PORT:80} + # ZLM Hook 鉴权 secret(对应 ZLM hook.admin_params=secret)——必须通过环境/profile 覆盖 + secret: ${ZLM_SECRET:please-override-in-env} # 是否自动配置 ZLM - auto-config: true + auto-config: ${ZLM_AUTO_CONFIG:true} # 录像路径 record-path: ./www/record # 录像保存天数 @@ -226,4 +232,12 @@ user-settings: # SIP 保持服务器连接(false 可防止 TCP DoS 攻击,但降低性能) sip-cache-server-connections: true +# Video 模块定时任务统一配置 +# 项目的业务级定时任务走 xxl-job(xxl.job.*),此处管控 video 模块内高频 SIP 消息队列轮询 +# 这类轮询频率(50ms/100ms/200ms)远低于 xxl-job 的秒级调度精度,仅靠 Spring @Scheduled 承载 +video: + sip-queue: + # 是否开启 SIP 消息队列消费调度器(目录同步/心跳/报警)。关闭后 SIP 消息将堆积在内存队列,不落库,慎用 + enabled: true + debug: false