35 lines
1.1 KiB
PowerShell
35 lines
1.1 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Starts the SSH tunnel required by the local DeerFlow backend's remote MySQL connection.
|
|
|
|
.DESCRIPTION
|
|
The local backend is configured to reach MySQL at 127.0.0.1:13307. This script forwards
|
|
that port over SSH to the MySQL listener on the remote server. It deliberately does not
|
|
store the SSH password; OpenSSH prompts for it when the tunnel starts.
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$RemoteHost = "119.254.86.251",
|
|
[int]$SshPort = 22322,
|
|
[string]$SshUser = "root",
|
|
[int]$LocalPort = 13307,
|
|
[int]$RemoteMySqlPort = 3307
|
|
)
|
|
|
|
$existing = Get-NetTCPConnection -State Listen -LocalPort $LocalPort -ErrorAction SilentlyContinue
|
|
if ($existing) {
|
|
Write-Host "本地端口 $LocalPort 已在监听;SSH 隧道应已启动。" -ForegroundColor Yellow
|
|
exit 0
|
|
}
|
|
|
|
Write-Host "正在建立 MySQL SSH 隧道:127.0.0.1:$LocalPort -> $RemoteHost`:$RemoteMySqlPort"
|
|
Write-Host "请保持此窗口运行;按 Ctrl+C 可关闭隧道。"
|
|
|
|
ssh -N `
|
|
-o ExitOnForwardFailure=yes `
|
|
-o ServerAliveInterval=30 `
|
|
-o ServerAliveCountMax=3 `
|
|
-L "${LocalPort}:127.0.0.1:${RemoteMySqlPort}" `
|
|
-p $SshPort `
|
|
"${SshUser}@${RemoteHost}"
|