furniture-3d-system-Wu/scripts/check-ports-feiniu.ps1
WuYongJie 5821d73291 初始提交:3D家具安装展示系统
包含:
- furniture-3d-system:Next.js 16 全栈应用(资产中心、产品管理、3D装配动画)
- autocad-plugin:AutoCAD 家具导出插件源码
- 资产中心改造:编辑弹窗化、删除功能、Toast反馈、自定义Select组件

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 14:00:19 +08:00

91 lines
3.6 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 检查飞牛OS服务器端口占用情况
# 用途:检查服务器上哪些端口可用
# 使用:.\scripts\check-ports-feiniu.ps1
param(
[string]$ServerIP = "192.168.42.252",
[string]$ServerUser = "admin"
)
Write-Host "=== 检查服务器端口占用情况 ===" -ForegroundColor Cyan
Write-Host "服务器: $ServerIP`n" -ForegroundColor Yellow
# 检查常用端口
$portsToCheck = @(
@{Port=3000; Name="应用端口(默认)"},
@{Port=3001; Name="应用端口(备选1)"},
@{Port=3002; Name="应用端口(备选2)"},
@{Port=3003; Name="应用端口(备选3)"},
@{Port=8080; Name="应用端口(备选4)"},
@{Port=9000; Name="MinIO API"},
@{Port=9001; Name="MinIO Console"},
@{Port=5432; Name="PostgreSQL"},
@{Port=6379; Name="Redis"}
)
Write-Host "正在检查端口占用情况..." -ForegroundColor Yellow
Write-Host ""
$availablePorts = @()
$occupiedPorts = @()
foreach ($portInfo in $portsToCheck) {
$port = $portInfo.Port
$name = $portInfo.Name
Write-Host "检查端口 $port ($name)..." -ForegroundColor Gray -NoNewline
# 使用SSH检查端口(使用BatchMode避免交互)
$result = ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=3 "$ServerUser@$ServerIP" "netstat -tuln 2>/dev/null | grep ':$port ' || echo 'FREE'" 2>&1
if ($result -match "FREE" -or ($result -eq "" -and $LASTEXITCODE -eq 0)) {
Write-Host " ✅ 可用" -ForegroundColor Green
$availablePorts += $portInfo
} elseif ($result -match "LISTEN" -or $result -match ":$port") {
Write-Host " ❌ 被占用" -ForegroundColor Red
$occupiedPorts += $portInfo
# 尝试获取占用进程信息
$processInfo = ssh -o StrictHostKeyChecking=no -o BatchMode=yes "$ServerUser@$ServerIP" "netstat -tulnp 2>/dev/null | grep ':$port ' | head -1" 2>&1
if ($processInfo -and $processInfo -notmatch "FREE") {
Write-Host " 进程: $($processInfo.Trim())" -ForegroundColor DarkGray
}
} else {
Write-Host " ⚠️ 检查失败(可能需要密码认证)" -ForegroundColor Yellow
}
}
Write-Host "`n=== 检查结果汇总 ===" -ForegroundColor Cyan
if ($availablePorts.Count -gt 0) {
Write-Host "`n✅ 可用端口:" -ForegroundColor Green
foreach ($portInfo in $availablePorts) {
Write-Host " 端口 $($portInfo.Port) - $($portInfo.Name)" -ForegroundColor White
}
}
if ($occupiedPorts.Count -gt 0) {
Write-Host "`n❌ 被占用端口:" -ForegroundColor Red
foreach ($portInfo in $occupiedPorts) {
Write-Host " 端口 $($portInfo.Port) - $($portInfo.Name)" -ForegroundColor White
}
}
Write-Host "`n=== 推荐配置 ===" -ForegroundColor Cyan
# 推荐第一个可用的应用端口
$recommendedPort = $availablePorts | Where-Object { $_.Port -in @(3000, 3001, 3002, 3003, 8080) } | Select-Object -First 1
if ($recommendedPort) {
Write-Host "推荐使用端口: $($recommendedPort.Port)" -ForegroundColor Green
Write-Host "`n在部署时设置环境变量:" -ForegroundColor Yellow
Write-Host " WEB_PORT=$($recommendedPort.Port)" -ForegroundColor White
Write-Host "`n或在.env文件中设置:" -ForegroundColor Yellow
Write-Host " WEB_PORT=$($recommendedPort.Port)" -ForegroundColor White
Write-Host "`n访问地址将是: http://$ServerIP`:$($recommendedPort.Port)" -ForegroundColor Cyan
} else {
Write-Host "⚠️ 没有找到可用的应用端口,请手动检查" -ForegroundColor Yellow
}
Write-Host "`n提示: 如果SSH需要密码,请先运行: .\scripts\setup-ssh-key.ps1" -ForegroundColor Gray