任务:添加监控及服务重启脚本
添加Prometheus/Grafana/Loki监控配置、Promtail配置、业务与监控服务器docker-compose文件以及Bash/PowerShell服务重启脚本
This commit is contained in:
parent
1f498d2396
commit
39a5d5d4ee
6
.trae/rules/git-commit-message.md
Normal file
6
.trae/rules/git-commit-message.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
alwaysApply: true
|
||||
scene: git_message
|
||||
---
|
||||
|
||||
在此处编写规则,自定义 AI 生成提交信息的风格。
|
||||
0
logs/TMDB服务-stderr.log
Normal file
0
logs/TMDB服务-stderr.log
Normal file
51
logs/TMDB服务-stdout.log
Normal file
51
logs/TMDB服务-stdout.log
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
. ____ _ __ _ _
|
||||
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
|
||||
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
|
||||
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
|
||||
' |____| .__|_| |_|_| |_\__, | / / / /
|
||||
=========|_|==============|___/=/_/_/_/
|
||||
:: Spring Boot :: (v3.2.5)
|
||||
|
||||
2026-06-25T17:43:17.176+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] com.wangpan.TmdbServiceApplication : Starting TmdbServiceApplication v1.0-SNAPSHOT using Java 17.0.8 with PID 46356 (D:\java2\wangpan\java\wangpan-tmdb-service\target\wangpan-tmdb-service-1.0-SNAPSHOT.jar started by ÀîÈÙÇ¿ in D:\java2\wangpan\java)
|
||||
2026-06-25T17:43:17.182+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] com.wangpan.TmdbServiceApplication : No active profile set, falling back to 1 default profile: "default"
|
||||
2026-06-25T17:43:18.983+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] ptablePropertiesBeanFactoryPostProcessor : Post-processing PropertySource instances
|
||||
2026-06-25T17:43:18.986+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource configurationProperties [class org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource
|
||||
2026-06-25T17:43:18.989+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletConfigInitParams [class org.springframework.core.env.PropertySource$StubPropertySource
|
||||
2026-06-25T17:43:18.990+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletContextInitParams [class org.springframework.core.env.PropertySource$StubPropertySource
|
||||
2026-06-25T17:43:18.991+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
|
||||
2026-06-25T17:43:18.991+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper
|
||||
2026-06-25T17:43:18.991+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper
|
||||
2026-06-25T17:43:18.993+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource Config resource 'class path resource [application.yml]' via location 'optional:classpath:/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper
|
||||
2026-06-25T17:43:19.812+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8083 (http)
|
||||
2026-06-25T17:43:19.833+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
|
||||
2026-06-25T17:43:19.833+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.20]
|
||||
2026-06-25T17:43:19.928+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
|
||||
2026-06-25T17:43:19.930+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2640 ms
|
||||
2026-06-25T17:43:20.018+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.filter.DefaultLazyPropertyFilter : Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter
|
||||
2026-06-25T17:43:20.033+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.r.DefaultLazyPropertyResolver : Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver
|
||||
2026-06-25T17:43:20.036+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.d.DefaultLazyPropertyDetector : Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector
|
||||
2026-06-25T17:43:20.212+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.encryptor.DefaultLazyEncryptor : String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor
|
||||
2026-06-25T17:43:20.227+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.c.StringEncryptorBuilder : Encryptor config not found for property jasypt.encryptor.provider-name, using default value: null
|
||||
2026-06-25T17:43:20.228+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] c.u.j.c.StringEncryptorBuilder : Encryptor config not found for property jasypt.encryptor.provider-class-name, using default value: null
|
||||
2026-06-25T17:43:20.325+08:00 WARN 46356 --- [wangpan-tmdb-service] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseInitializer': Injection of resource dependencies failed
|
||||
2026-06-25T17:43:20.330+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
|
||||
2026-06-25T17:43:20.365+08:00 INFO 46356 --- [wangpan-tmdb-service] [ main] .s.b.a.l.ConditionEvaluationReportLogger :
|
||||
|
||||
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
|
||||
2026-06-25T17:43:20.402+08:00 ERROR 46356 --- [wangpan-tmdb-service] [ main] o.s.b.d.LoggingFailureAnalysisReporter :
|
||||
|
||||
***************************
|
||||
APPLICATION FAILED TO START
|
||||
***************************
|
||||
|
||||
Description:
|
||||
|
||||
Failed to bind properties under 'spring.datasource.password' to java.lang.String:
|
||||
|
||||
Reason: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.password' to java.lang.String
|
||||
|
||||
Action:
|
||||
|
||||
Update your application's configuration
|
||||
|
||||
35
monitoring/docker-compose.business.yml
Normal file
35
monitoring/docker-compose.business.yml
Normal file
@ -0,0 +1,35 @@
|
||||
version: '3.8'
|
||||
|
||||
# 业务服务器专用配置(118.178.238.159)
|
||||
# 只部署 Node Exporter 和 Promtail,用于采集指标和日志
|
||||
|
||||
services:
|
||||
# Node Exporter - 采集业务服务器的硬件指标(CPU、内存、磁盘等)
|
||||
node-exporter:
|
||||
image: prom/node-exporter:latest
|
||||
container_name: node-exporter
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- /proc:/host/proc:ro
|
||||
- /sys:/host/sys:ro
|
||||
- /:/rootfs:ro
|
||||
command:
|
||||
- '--path.procfs=/host/proc'
|
||||
- '--path.rootfs=/rootfs'
|
||||
- '--path.sysfs=/host/sys'
|
||||
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
|
||||
ports:
|
||||
- "9100:9100"
|
||||
|
||||
# Promtail - 采集应用日志,发送给监控服务器的 Loki
|
||||
promtail:
|
||||
image: grafana/promtail:latest
|
||||
container_name: promtail
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./promtail.yml:/etc/promtail/config.yml
|
||||
- /var/log:/var/log
|
||||
- /opt/wangpan/logs:/opt/wangpan/logs
|
||||
command: -config.file=/etc/promtail/config.yml
|
||||
ports:
|
||||
- "9080:9080"
|
||||
76
monitoring/docker-compose.yml
Normal file
76
monitoring/docker-compose.yml
Normal file
@ -0,0 +1,76 @@
|
||||
version: '3.8'
|
||||
|
||||
# 监控服务器专用配置(ldfun.asia)
|
||||
# 只部署监控组件,不包含 Promtail(Promtail 部署在业务服务器上)
|
||||
|
||||
services:
|
||||
# Prometheus - 监控系统,采集所有指标数据
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
container_name: prometheus
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
- prometheus_data:/prometheus
|
||||
ports:
|
||||
- "9090:9090"
|
||||
networks:
|
||||
- monitoring
|
||||
|
||||
# Grafana - 可视化面板,查看监控图表和日志
|
||||
grafana:
|
||||
image: grafana/grafana:latest
|
||||
container_name: grafana
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- grafana_data:/var/lib/grafana
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin123
|
||||
- GF_USERS_ALLOW_SIGN_UP=false
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- prometheus
|
||||
- loki
|
||||
networks:
|
||||
- monitoring
|
||||
|
||||
# Loki - 日志聚合系统,存储日志数据
|
||||
loki:
|
||||
image: grafana/loki:latest
|
||||
container_name: loki
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- loki_data:/loki
|
||||
ports:
|
||||
- "3100:3100"
|
||||
networks:
|
||||
- monitoring
|
||||
|
||||
# Node Exporter - 采集监控服务器自身的硬件指标(CPU、内存、磁盘等)
|
||||
node-exporter:
|
||||
image: prom/node-exporter:latest
|
||||
container_name: node-exporter
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- /proc:/host/proc:ro
|
||||
- /sys:/host/sys:ro
|
||||
- /:/rootfs:ro
|
||||
command:
|
||||
- '--path.procfs=/host/proc'
|
||||
- '--path.rootfs=/rootfs'
|
||||
- '--path.sysfs=/host/sys'
|
||||
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
|
||||
ports:
|
||||
- "9100:9100"
|
||||
networks:
|
||||
- monitoring
|
||||
|
||||
volumes:
|
||||
prometheus_data:
|
||||
grafana_data:
|
||||
loki_data:
|
||||
|
||||
networks:
|
||||
monitoring:
|
||||
driver: bridge
|
||||
55
monitoring/prometheus.yml
Normal file
55
monitoring/prometheus.yml
Normal file
@ -0,0 +1,55 @@
|
||||
global:
|
||||
scrape_interval: 15s # 每15秒采集一次指标
|
||||
evaluation_interval: 15s # 每15秒评估一次告警规则
|
||||
|
||||
scrape_configs:
|
||||
# Prometheus 自身监控
|
||||
- job_name: 'prometheus'
|
||||
static_configs:
|
||||
- targets: ['localhost:9090']
|
||||
|
||||
# 监控服务器自身指标(通过 Node Exporter)
|
||||
- job_name: 'node-exporter-monitor'
|
||||
static_configs:
|
||||
- targets: ['node-exporter:9100']
|
||||
labels:
|
||||
server: 'monitor'
|
||||
|
||||
# 业务服务器指标(通过业务服务器上的 Node Exporter)
|
||||
- job_name: 'node-exporter-business'
|
||||
static_configs:
|
||||
- targets: ['118.178.238.159:9100']
|
||||
labels:
|
||||
server: 'business'
|
||||
|
||||
# 网关服务监控(端口8888)
|
||||
- job_name: 'wangpan-gateway'
|
||||
metrics_path: '/actuator/prometheus'
|
||||
static_configs:
|
||||
- targets: ['118.178.238.159:8888']
|
||||
labels:
|
||||
service: 'gateway'
|
||||
|
||||
# 用户服务监控
|
||||
- job_name: 'wangpan-user-service'
|
||||
metrics_path: '/actuator/prometheus'
|
||||
static_configs:
|
||||
- targets: ['118.178.238.159:8081']
|
||||
labels:
|
||||
service: 'user-service'
|
||||
|
||||
# 网盘服务监控
|
||||
- job_name: 'wangpan-drive-service'
|
||||
metrics_path: '/actuator/prometheus'
|
||||
static_configs:
|
||||
- targets: ['118.178.238.159:8082']
|
||||
labels:
|
||||
service: 'drive-service'
|
||||
|
||||
# TMDB服务监控
|
||||
- job_name: 'wangpan-tmdb-service'
|
||||
metrics_path: '/actuator/prometheus'
|
||||
static_configs:
|
||||
- targets: ['118.178.238.159:8083']
|
||||
labels:
|
||||
service: 'tmdb-service'
|
||||
29
monitoring/promtail.yml
Normal file
29
monitoring/promtail.yml
Normal file
@ -0,0 +1,29 @@
|
||||
server:
|
||||
http_listen_port: 9080 # Promtail HTTP 监听端口
|
||||
grpc_listen_port: 0 # 禁用 gRPC
|
||||
|
||||
positions:
|
||||
filename: /tmp/positions.yaml # 记录日志读取位置,防止重复采集
|
||||
|
||||
clients:
|
||||
# 指向监控服务器的 Loki,通过公网域名发送日志
|
||||
- url: http://ldfun.asia:3100/loki/api/v1/push
|
||||
|
||||
scrape_configs:
|
||||
# 收集系统日志
|
||||
- job_name: system
|
||||
static_configs:
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: varlogs
|
||||
__path__: /var/log/*.log
|
||||
|
||||
# 收集应用日志(各微服务输出到 /opt/wangpan/logs/)
|
||||
- job_name: wangpan-logs
|
||||
static_configs:
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: wangpan
|
||||
__path__: /opt/wangpan/logs/*.log
|
||||
99
restart-services.ps1
Normal file
99
restart-services.ps1
Normal file
@ -0,0 +1,99 @@
|
||||
# Restart script for wangpan microservices
|
||||
# Usage: .\restart-services.ps1
|
||||
|
||||
$JASYPT_PASSWORD = "wangpan-secret-key-2024"
|
||||
$BASE_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
|
||||
$services = @(
|
||||
@{ Name = "user-service"; Port = 8081; Jar = "wangpan-user-service\target\wangpan-user-service-1.0-SNAPSHOT.jar" },
|
||||
@{ Name = "drive-service"; Port = 8082; Jar = "wangpan-drive-service\target\wangpan-drive-service-1.0-SNAPSHOT.jar" },
|
||||
@{ Name = "tmdb-service"; Port = 8083; Jar = "wangpan-tmdb-service\target\wangpan-tmdb-service-1.0-SNAPSHOT.jar" },
|
||||
@{ Name = "gateway"; Port = 8888; Jar = "wangpan-gateway\target\wangpan-gateway-1.0-SNAPSHOT.jar" }
|
||||
)
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host " Wangpan Microservices Restart" -ForegroundColor Cyan
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
|
||||
$env:JASYPT_ENCRYPTOR_PASSWORD = $JASYPT_PASSWORD
|
||||
|
||||
Write-Host "[Step 1] Checking port usage..." -ForegroundColor Yellow
|
||||
foreach ($service in $services) {
|
||||
$port = $service.Port
|
||||
$name = $service.Name
|
||||
$connections = netstat -ano | Select-String ":$port\s" | Select-String "LISTENING"
|
||||
if ($connections) {
|
||||
$pids = $connections | ForEach-Object { ($_ -split '\s+')[-1] } | Select-Object -Unique
|
||||
foreach ($procId in $pids) {
|
||||
if ($procId -match '^\d+$' -and $procId -ne '0') {
|
||||
try {
|
||||
$process = Get-Process -Id $procId -ErrorAction SilentlyContinue
|
||||
if ($process) {
|
||||
Write-Host " Killing process on port $port (PID: $procId)..." -ForegroundColor Red
|
||||
Stop-Process -Id $procId -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
} catch {
|
||||
Write-Host " Failed to kill PID: $procId" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-Host " Port $port ($name) is free" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "[Step 2] Waiting for ports to release..." -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
Write-Host "[Step 3] Starting services..." -ForegroundColor Yellow
|
||||
foreach ($service in $services) {
|
||||
$name = $service.Name
|
||||
$port = $service.Port
|
||||
$jarPath = Join-Path $BASE_DIR $service.Jar
|
||||
Write-Host "Starting $name on port $port..." -ForegroundColor Cyan
|
||||
if (-not (Test-Path $jarPath)) {
|
||||
Write-Host " ERROR: Jar not found: $jarPath" -ForegroundColor Red
|
||||
continue
|
||||
}
|
||||
$process = Start-Process -FilePath "java" -ArgumentList "-jar", $jarPath -WindowStyle Hidden -PassThru
|
||||
if ($process) {
|
||||
Write-Host " Started $name (PID: $($process.Id))" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host " Failed to start $name" -ForegroundColor Red
|
||||
}
|
||||
if ($service -ne $services[-1]) {
|
||||
Start-Sleep -Seconds 5
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "[Step 4] Verifying services..." -ForegroundColor Yellow
|
||||
$allRunning = $true
|
||||
$maxRetries = 6
|
||||
foreach ($service in $services) {
|
||||
$port = $service.Port
|
||||
$name = $service.Name
|
||||
$started = $false
|
||||
for ($i = 1; $i -le $maxRetries; $i++) {
|
||||
$connections = netstat -ano | Select-String ":$port\s" | Select-String "LISTENING"
|
||||
if ($connections) {
|
||||
Write-Host " [OK] $name (port $port)" -ForegroundColor Green
|
||||
$started = $true
|
||||
break
|
||||
}
|
||||
Start-Sleep -Seconds 5
|
||||
}
|
||||
if (-not $started) {
|
||||
Write-Host " [FAIL] $name (port $port) - not started after $($maxRetries * 5)s" -ForegroundColor Red
|
||||
$allRunning = $false
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
if ($allRunning) {
|
||||
Write-Host "All services started successfully!" -ForegroundColor Green
|
||||
Write-Host "Access: http://localhost:8888" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Some services failed to start. Check logs." -ForegroundColor Red
|
||||
}
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
124
restart-services.sh
Normal file
124
restart-services.sh
Normal file
@ -0,0 +1,124 @@
|
||||
#!/bin/bash
|
||||
# 网盘微服务重启脚本 (Linux Bash)
|
||||
# 功能:检查端口占用 -> 杀死进程 -> 按顺序启动服务
|
||||
|
||||
# 配置
|
||||
JASYPT_PASSWORD="wangpan-secret-key-2024"
|
||||
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
LOG_DIR="$BASE_DIR/logs"
|
||||
|
||||
# 创建日志目录
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# 服务配置:名称、端口、jar路径
|
||||
declare -a SERVICE_NAMES=("用户服务" "网盘服务" "TMDB服务" "网关服务")
|
||||
declare -a SERVICE_PORTS=(8081 8082 8083 8888)
|
||||
declare -a SERVICE_JARS=(
|
||||
"wangpan-user-service/target/wangpan-user-service-1.0-SNAPSHOT.jar"
|
||||
"wangpan-drive-service/target/wangpan-drive-service-1.0-SNAPSHOT.jar"
|
||||
"wangpan-tmdb-service/target/wangpan-tmdb-service-1.0-SNAPSHOT.jar"
|
||||
"wangpan-gateway/target/wangpan-gateway-1.0-SNAPSHOT.jar"
|
||||
)
|
||||
|
||||
echo "========================================"
|
||||
echo " 网盘微服务重启脚本 (Linux)"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
|
||||
# 导出环境变量
|
||||
export JASYPT_ENCRYPTOR_PASSWORD="$JASYPT_PASSWORD"
|
||||
|
||||
# 第一步:检查并杀死占用端口的进程
|
||||
echo "[步骤1] 检查端口占用情况..."
|
||||
|
||||
for i in "${!SERVICE_PORTS[@]}"; do
|
||||
port=${SERVICE_PORTS[$i]}
|
||||
name=${SERVICE_NAMES[$i]}
|
||||
|
||||
# 查找占用端口的进程
|
||||
pid=$(lsof -ti :$port 2>/dev/null || ss -tlnp | grep ":$port " | awk '{print $NF}' | grep -oP 'pid=\K\d+' | head -1)
|
||||
|
||||
if [ -n "$pid" ]; then
|
||||
echo " 发现端口 $port 被进程 PID: $pid 占用,正在杀死..."
|
||||
kill -9 $pid 2>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " 已杀死进程 PID: $pid"
|
||||
else
|
||||
echo " 无法杀死进程 PID: $pid"
|
||||
fi
|
||||
sleep 1
|
||||
else
|
||||
echo " 端口 $port ($name) 未被占用"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "[步骤2] 等待端口释放..."
|
||||
sleep 3
|
||||
|
||||
# 第二步:按顺序启动服务
|
||||
echo ""
|
||||
echo "[步骤3] 按顺序启动服务..."
|
||||
echo ""
|
||||
|
||||
for i in "${!SERVICE_NAMES[@]}"; do
|
||||
name=${SERVICE_NAMES[$i]}
|
||||
port=${SERVICE_PORTS[$i]}
|
||||
jar_path="$BASE_DIR/${SERVICE_JARS[$i]}"
|
||||
|
||||
echo "----------------------------------------"
|
||||
echo "启动 $name (端口: $port)..."
|
||||
|
||||
if [ ! -f "$jar_path" ]; then
|
||||
echo " 错误: 找不到jar文件 $jar_path"
|
||||
echo " 请先执行 mvn clean install -DskipTests 编译项目"
|
||||
continue
|
||||
fi
|
||||
|
||||
# 启动服务(后台运行)
|
||||
nohup java -jar "$jar_path" > "$LOG_DIR/${name}-stdout.log" 2>&1 &
|
||||
pid=$!
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " 已启动 $name (PID: $pid)"
|
||||
else
|
||||
echo " 启动失败: $name"
|
||||
fi
|
||||
|
||||
# 等待5秒后启动下一个服务(最后一个服务不等待)
|
||||
if [ $i -lt $((${#SERVICE_NAMES[@]} - 1)) ]; then
|
||||
echo " 等待5秒后启动下一个服务..."
|
||||
sleep 5
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "----------------------------------------"
|
||||
echo "[步骤4] 验证服务启动状态..."
|
||||
sleep 5
|
||||
|
||||
# 检查服务状态
|
||||
all_running=true
|
||||
for i in "${!SERVICE_PORTS[@]}"; do
|
||||
port=${SERVICE_PORTS[$i]}
|
||||
name=${SERVICE_NAMES[$i]}
|
||||
|
||||
# 检查端口是否在监听
|
||||
if ss -tln | grep -q ":$port "; then
|
||||
echo " ✓ $name (端口 $port) - 运行中"
|
||||
else
|
||||
echo " ✗ $name (端口 $port) - 未启动"
|
||||
all_running=false
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "========================================"
|
||||
if [ "$all_running" = true ]; then
|
||||
echo " 所有服务启动成功!"
|
||||
echo " 访问地址: http://localhost:8888"
|
||||
else
|
||||
echo " 部分服务启动失败,请检查日志"
|
||||
echo " 日志目录: $LOG_DIR/"
|
||||
fi
|
||||
echo "========================================"
|
||||
@ -46,6 +46,11 @@ public interface TmdbScraperLogMapper extends BaseMapper<TmdbScraperLogDO> {
|
||||
*/
|
||||
int insertLog(@Param("log") Map<String, Object> log);
|
||||
|
||||
/**
|
||||
* 查询执行记录总数
|
||||
*/
|
||||
long countAll();
|
||||
|
||||
/**
|
||||
* 分页查询最近的执行记录
|
||||
* 复杂SQL,在XML中实现
|
||||
|
||||
@ -31,6 +31,13 @@ public class TmdbScraperLogRepository extends ServiceImpl<TmdbScraperLogMapper,
|
||||
|
||||
// ==================== 查询 ====================
|
||||
|
||||
/**
|
||||
* 查询执行记录总数
|
||||
*/
|
||||
public long countAll() {
|
||||
return baseMapper.countAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询最近的执行记录(分页)
|
||||
* 委托给 TmdbScraperLogMapper 中定义的 XML 查询
|
||||
|
||||
@ -18,6 +18,11 @@
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 查询执行记录总数 -->
|
||||
<select id="countAll" resultType="long">
|
||||
SELECT COUNT(*) FROM wp_tmdb_scraper_log
|
||||
</select>
|
||||
|
||||
<!-- 分页查询最近的执行记录 -->
|
||||
<select id="queryRecent" resultType="java.util.Map">
|
||||
SELECT * FROM wp_tmdb_scraper_log ORDER BY start_time DESC
|
||||
|
||||
Binary file not shown.
@ -18,6 +18,11 @@
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 查询执行记录总数 -->
|
||||
<select id="countAll" resultType="long">
|
||||
SELECT COUNT(*) FROM wp_tmdb_scraper_log
|
||||
</select>
|
||||
|
||||
<!-- 分页查询最近的执行记录 -->
|
||||
<select id="queryRecent" resultType="java.util.Map">
|
||||
SELECT * FROM wp_tmdb_scraper_log ORDER BY start_time DESC
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -36,6 +36,18 @@
|
||||
<version>3.0.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Actuator - 提供监控端点 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Micrometer Prometheus 注册器 - 暴露 Prometheus 指标 -->
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@ -33,9 +33,24 @@ jasypt:
|
||||
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
|
||||
string-output-type: base64
|
||||
|
||||
# Actuator 监控端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: prometheus,health,info
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
enabled: true
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.wangpan: INFO
|
||||
file:
|
||||
path: /opt/wangpan/logs
|
||||
|
||||
# MyBatis-Plus 配置
|
||||
mybatis-plus:
|
||||
|
||||
@ -33,9 +33,24 @@ jasypt:
|
||||
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
|
||||
string-output-type: base64
|
||||
|
||||
# Actuator 监控端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: prometheus,health,info
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
enabled: true
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.wangpan: INFO
|
||||
file:
|
||||
path: /opt/wangpan/logs
|
||||
|
||||
# MyBatis-Plus 配置
|
||||
mybatis-plus:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -31,6 +31,18 @@
|
||||
<version>3.0.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Actuator - 提供监控端点 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Micrometer Prometheus 注册器 - 暴露 Prometheus 指标 -->
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@ -43,7 +43,22 @@ jasypt:
|
||||
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
|
||||
string-output-type: base64
|
||||
|
||||
# Actuator 监控端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: prometheus,health,info
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
enabled: true
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.wangpan: INFO
|
||||
org.springframework.cloud.gateway: INFO
|
||||
file:
|
||||
path: /opt/wangpan/logs
|
||||
|
||||
@ -43,7 +43,22 @@ jasypt:
|
||||
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
|
||||
string-output-type: base64
|
||||
|
||||
# Actuator 监控端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: prometheus,health,info
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
enabled: true
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.wangpan: INFO
|
||||
org.springframework.cloud.gateway: INFO
|
||||
file:
|
||||
path: /opt/wangpan/logs
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -36,6 +36,18 @@
|
||||
<version>3.0.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Actuator - 提供监控端点 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Micrometer Prometheus 注册器 - 暴露 Prometheus 指标 -->
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@ -19,6 +19,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -145,8 +146,8 @@ public class MovieController {
|
||||
return Result.notFound("电影不存在");
|
||||
}
|
||||
|
||||
// 2. 校验用户权限
|
||||
if (!movieDO.getUserId().equals(user.getId())) {
|
||||
// 2. 校验用户权限(使用 Objects.equals 避免 user.getId() 或 movieDO.getUserId() 为 null 时 NPE)
|
||||
if (!Objects.equals(user.getId(), movieDO.getUserId())) {
|
||||
return Result.notFound("电影不存在或无权访问");
|
||||
}
|
||||
|
||||
|
||||
@ -214,13 +214,14 @@ public class TmdbScraperController {
|
||||
pageSize = Math.min(MAX_PAGE_SIZE, Math.max(1, pageSize));
|
||||
|
||||
List<Map<String, Object>> logs = scraperLogRepository.queryRecent(pageNo, pageSize);
|
||||
long total = scraperLogRepository.countAll();
|
||||
|
||||
// 构建分页响应
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("list", logs);
|
||||
result.put("pageNo", pageNo);
|
||||
result.put("pageSize", pageSize);
|
||||
result.put("total", logs.size());
|
||||
result.put("total", total);
|
||||
|
||||
return Result.success("查询成功", result);
|
||||
}
|
||||
|
||||
@ -29,9 +29,24 @@ jasypt:
|
||||
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
|
||||
string-output-type: base64
|
||||
|
||||
# Actuator 监控端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: prometheus,health,info
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
enabled: true
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.wangpan: INFO
|
||||
file:
|
||||
path: /opt/wangpan/logs
|
||||
|
||||
# MyBatis-Plus 配置
|
||||
mybatis-plus:
|
||||
|
||||
@ -29,9 +29,24 @@ jasypt:
|
||||
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
|
||||
string-output-type: base64
|
||||
|
||||
# Actuator 监控端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: prometheus,health,info
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
enabled: true
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.wangpan: INFO
|
||||
file:
|
||||
path: /opt/wangpan/logs
|
||||
|
||||
# MyBatis-Plus 配置
|
||||
mybatis-plus:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -36,6 +36,18 @@
|
||||
<version>3.0.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Actuator - 提供监控端点 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Micrometer Prometheus 注册器 - 暴露 Prometheus 指标 -->
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@ -22,9 +22,24 @@ jasypt:
|
||||
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
|
||||
string-output-type: base64
|
||||
|
||||
# Actuator 监控端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: prometheus,health,info
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
enabled: true
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.wangpan: INFO
|
||||
file:
|
||||
path: /opt/wangpan/logs
|
||||
|
||||
# MyBatis-Plus 配置
|
||||
mybatis-plus:
|
||||
|
||||
@ -22,9 +22,24 @@ jasypt:
|
||||
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
|
||||
string-output-type: base64
|
||||
|
||||
# Actuator 监控端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: prometheus,health,info
|
||||
metrics:
|
||||
export:
|
||||
prometheus:
|
||||
enabled: true
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.wangpan: INFO
|
||||
file:
|
||||
path: /opt/wangpan/logs
|
||||
|
||||
# MyBatis-Plus 配置
|
||||
mybatis-plus:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user