<# .SYNOPSIS 检查阿里云开发环境服务状态 .DESCRIPTION 检查Nacos、数据库、Redis、镜像仓库、Nginx、API Gateway等服务状态 #> $ErrorActionPreference = "SilentlyContinue" $RED = "Red" $GREEN = "Green" $YELLOW = "Yellow" function Write-Status($service, $status, $message) { if ($status -eq "OK") { Write-Host "$service : " -NoNewline Write-Host "✅ $message" -ForegroundColor $GREEN } elseif ($status -eq "WARN") { Write-Host "$service : " -NoNewline Write-Host "⚠️ $message" -ForegroundColor $YELLOW } else { Write-Host "$service : " -NoNewline Write-Host "❌ $message" -ForegroundColor $RED } } function Test-Url($url, $timeout = 10) { try { $response = Invoke-WebRequest -Uri $url -TimeoutSec $timeout -UseBasicParsing return $response.StatusCode -eq 200 } catch { return $false } } function Test-TcpPort($hostName, $port, $timeout = 5) { try { $tcpClient = New-Object System.Net.Sockets.TCPClient $connect = $tcpClient.BeginConnect($hostName, $port, $null, $null) $wait = $connect.AsyncWaitHandle.WaitOne($timeout * 1000, $false) if ($wait) { $tcpClient.EndConnect($connect) | Out-Null $tcpClient.Close() return $true } return $false } catch { return $false } } Write-Host "==========================================" Write-Host " 阿里云开发环境服务状态检查" Write-Host "==========================================" Write-Host "" $services = @( @{ Name = "Nacos"; Host = "8.140.221.49"; Port = 8848; Url = "http://8.140.221.49:8848/nacos/v1/console/health" }, @{ Name = "MariaDB"; Host = "8.140.221.49"; Port = 3306; Url = $null }, @{ Name = "Redis"; Host = "8.140.221.49"; Port = 6379; Url = $null }, @{ Name = "镜像仓库(Harbor)"; Host = "8.140.221.49"; Port = 5000; Url = "http://8.140.221.49:5000/v2/_catalog" }, @{ Name = "Nginx"; Host = "8.140.221.49"; Port = 80; Url = "http://8.140.221.49" }, @{ Name = "API Gateway"; Host = "8.140.221.49"; Port = 8080; Url = "http://8.140.221.49:8080/actuator/health" }, @{ Name = "Jenkins"; Host = "localhost"; Port = 8080; Url = "http://localhost:8080/login" }, @{ Name = "SonarQube"; Host = "localhost"; Port = 9000; Url = "http://localhost:9000/api/system/health" }, @{ Name = "Nexus"; Host = "localhost"; Port = 8091; Url = "http://localhost:8091/service/rest/v1/status" } ) $successCount = 0 $failedCount = 0 foreach ($service in $services) { Write-Host "🔍 检查 $($service.Name)..." if ($service.Url) { if (Test-Url $service.Url) { Write-Status $service.Name "OK" "$($service.Name)服务正常" $successCount++ } else { Write-Status $service.Name "FAIL" "$($service.Name)服务异常" $failedCount++ } } else { if (Test-TcpPort $service.Host $service.Port) { Write-Status $service.Name "OK" "$($service.Name)端口正常" $successCount++ } else { Write-Status $service.Name "FAIL" "$($service.Name)端口未开放" $failedCount++ } } } Write-Host "" Write-Host "==========================================" Write-Host " 检查结果汇总" Write-Host "==========================================" Write-Host "服务总数: $($services.Count)" Write-Host "正常: " -NoNewline Write-Host "$successCount" -ForegroundColor $GREEN Write-Host " | 异常: " -NoNewline Write-Host "$failedCount" -ForegroundColor $RED if ($failedCount -eq 0) { Write-Host "" Write-Host "✅ 所有服务状态正常!" -ForegroundColor $GREEN } else { Write-Host "" Write-Host "⚠️ 发现 $failedCount 个服务异常,请检查" -ForegroundColor $YELLOW } Write-Host "" Write-Host "建议:" Write-Host "1. 对于异常服务,登录服务器检查日志" Write-Host "2. 检查网络连通性和防火墙配置" Write-Host "3. 必要时重启相关服务"