DataGrip通过跳板机连接数据库
失效链接处理
DataGrip通过跳板机连接数据库
环境:连接公司MySQL Server需要通过两层跳板机。第一层跳板机通过私钥验证,第二台跳板机和MySQL Server均使用用户名、密码验证。使用DataGrip + OpenSSH config可以实现双层跳板机登陆MySQL Server。
1、查看系统是否安装OpenSSH for Windows,以管理员权限运行Powershell
执行Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'

Installed表示已安装,如果没有安装则执行一下命令:
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
如果不需要作为SSH 服务器则只需要安装Client即可。
2、启动并配置 OpenSSH 服务(如果系统本身已经安装则跳过)
# Start the sshd service
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
3、在C:UserUserName文件夹下新增.ssh文件夹,并且新建 config 文件,如果有私钥则把私钥复制到该文件夹下

4、启动ssh-agent(建议改为自动启动,如果服务不是在运行状态是无法连接的)
Get-Service ssh-agent | Set-Service -StartupType 'Automatic'
Start-Service ssh-agent
# This should return a status of Running
Get-Service ssh-agent
# 把私钥添加到ssh-agent
ssh-add ~.sshid_ed25519(文件名替换成自己的)
5、配置config
Host 第二层跳板机IP
HostName 第二层跳板机IP
Port 第二层跳板机端口
User 第二层跳板机登陆用户
ProxyCommand ssh -W %h:%p 第一层跳板机别名
Host 第一层跳板机别名
HostName 第一层跳板机IP
Port 第一层跳板机端口
User 第一层跳板机登陆用户
IdentityFile C:UsersUserName.ssh私钥文件名
注意:第二层跳板机Host必须使用IP,不能取别名!
6、配置DataGrip


7、点Test Connection测试是否联通
提示输入密码则表示连接上第二层跳板机

连接成功

8、配置MySQL连接

最后Test Connection。
坑点1、DataGrip登陆跳板机使用的是ProxyCommand,暂时不支持ProxyJump命令
坑点2、在连接上第二层跳板机后,发现还是连不上MySQL,返回“Communications link failure.”,之后方通防火墙策略解决。
坑点3、SSH Configuration中的Host IP和config文件中的Host(注意不是HostName)必须对应,而且只能填IP,否则在输入密码后一直在等待服务器返回响应,只能强制结束程序。
Openssh for Windows使用文档:
https://docs.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_overview