首页 > 解决方案 > 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

有谁知道如何处理这个?如何从本地机器获取连接?

标签: javaspringoraclespring-bootldap

解决方案


我可能会做这样的事情,我将创建文件调用~/.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 隧道。连同端口转发。


推荐阅读