java - Spring Boot,通过本地机器上的 ssh 隧道使用 oracle-ldap url
问题描述
有3台机器:
local -> some remote server -> oracle db server (via ldap)
我想设置到 Oracle 数据库的数据源连接(在我的 Spring Boot 应用程序中)。
本地机器和带有 oracle db 的机器之间没有直接连接。所以,我通过远程服务器使用 ssh 隧道:
ssh -L 127.0.0.1:8081:some.ldap.host:389 user@remote.server.host
在 application.yml 文件中,我正在使用更多网址:
spring:
datasource:
url: jdbc:oracle:thin:@ldap://127.0.0.1:8081//srvcnm,cn=OracleContext,dc=yy,dc=xx,dc=com
当我的应用程序尝试获取数据库连接时,我收到以下错误:
Caused by: oracle.net.nt.TimeoutInterruptHandler$IOReadTimeoutException: Socket read timed out
at oracle.net.nt.TimeoutSocketChannel.handleInterrupt(TimeoutSocketChannel.java:254)
at oracle.net.nt.TimeoutSocketChannel.connect(TimeoutSocketChannel.java:103)
at oracle.net.nt.TimeoutSocketChannel.<init>(TimeoutSocketChannel.java:77)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:192)
... 126 common frames omitted
每当我在远程服务器上部署应用程序并在 application.yml 中输入“直接”url 时,都会在没有任何超时的情况下获得连接,并且应用程序运行良好。
jdbc:oracle:thin:@ldap://some.ldap.host:389//srvcnm,cn=OracleContext,dc=yy,dc=xx,dc=com
有谁知道如何处理这个?如何从本地机器获取连接?
解决方案
我可能会做这样的事情,我将创建文件调用~/.ssh/config
然后添加以下内容
Host remoteserver1
User usermane
Hostname ip or host name
ForwardAgent yes
Host oracleserver
User username
Hostname some.ldap.host
Port 22
# ForwardAgent yes if you need to forward one more instance
LocalForward 8081 some.ldap.host:389
ProxyCommand ssh -q -W %h:%p remoteserver1
这样做的目的是,当我尝试从 remoteserver1 连接到 ssh oracleserver 时,它会连接到 hopper,然后将 SSH 连接代理到那边的端口 22(即:oracleserver 上的 SSH)。
现在通过 ssh 进行连接,请执行以下操作ssh oracleserver
,因为它将通过 remoteserver1 在您的机器和 oracleserver 之间建立 ssh 隧道。连同端口转发。
推荐阅读
- ethereum - MyContractInstance.methods.MyMethod 不是函数(合同实例无法获取合同方法)web3
- sum - 特定时间段内的总天数 Power Bi
- html - 如何使图像高度适合父 div 的高度
- amazon-web-services - AWS CDK 将更改部署到 swagger 保留旧值
- python - (Python) 使用字典的单词替换程序,只应用第一个单词
- r - 将 .RData 保存在不同的目录中
- wordpress - 如何通过钩子编辑 WooCommerce 我的帐户页面
- regex - 仅当它包含某些查询参数 regex 时才匹配 url
- typescript - Type guards to convert interface X into Required
? - mysql - JSON 的 Laravel 连接关系