无法通过 ssh 连接到转发端口

Jos*_*ton 5 ssh postgresql forwarding

我有两台服务器。服务器 1 可以访问我有权访问但不能通过 SSH 登录的服务器上的 Oracle 实例。我想使用 SSH 端口转发从服务器 2 连接到服务器 1,再从那里连接到 Oracle 实例。我已经设置了GatewayPorts=yesAllowTcpForwarding=yes但我仍然觉得有些不对劲。

出于这个问题的目的,我只想专注于从服务器 2 端口从 16951 向前连接到服务器 1(端口 5432)上的 postgres 实例。

运行后:

ssh -L 16951:localhost:5432 server1 -nNT -f -g
Run Code Online (Sandbox Code Playgroud)

从服务器 2,我可以"localhost.16951"在运行netstat检查打开的端口后看到,这使我相信该端口正在成功侦听。

当我运行时:

psql -U jbarton -p 16951
Run Code Online (Sandbox Code Playgroud)

我收到一条消息说没有监听端口 localhost:16951

    psql: could not connect to server: No such file or directory
     Is the server running locally and accepting
     connections on Unix domain socket "/tmp/.s.PGSQL.16951"?
Run Code Online (Sandbox Code Playgroud)

非常感谢任何意见、答案或建议。

更新

当我现在使用 oracle 尝试此操作时,使用连接:./sqlplus W_USER/password@//localhost:16951/dbname,出现此错误:ERROR: ORA-12537: TNS:connection closed

我的 oracle ora 文件如下所示:

`#tnsnames.ora
PROD2 =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 16951))
      (CONNECT_DATA =
         (SERVER = DEDICATED)
         (SERVICE_NAME = prod2)
      )
    )
Run Code Online (Sandbox Code Playgroud)

和 sqlnet.ora

'# sqlnet.ora Network Configuration File Generated by Oracle configuration tools.

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
NAMES.LOG_DIRECTORY = /var/oracle/network/log
Run Code Online (Sandbox Code Playgroud)

Dra*_*oan 5

如果你没有指定主机名,psql 假定域套接字连接。根据手册页:

If you omit the host name, psql will connect via a Unix-domain socket to a server on the local host, or via TCP/IP to localhost on machines that don't have Unix-domain sockets.
Run Code Online (Sandbox Code Playgroud)

尝试添加-h localhost到 psql 命令行。

至于 Oracle 错误,我猜是因为以下原因(oracle 更难诊断):

The ORA-12537 error sometimes relates configuration issues in the sqlnet.ora, protocol.ora and listener.ora files.  Verify that you service names match between your listener and remote client connect strings.
Run Code Online (Sandbox Code Playgroud)

所以你的连接字符串localhost被 oracle 拒绝了。

更新

如果那是本地的tnsnames.ora,你有没有尝试过sqlplus W_USER@PROD2?(如果需要,它会提示输入密码)。您可能必须将环境变量设置为所在TNS_ADMIN的位置tnsnames.ora