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

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

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

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

运行后:

ssh -L 16951:localhost:5432 server1 -nNT -f -g

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

当我跑步时:

psql -U jbarton -p 16951

我收到一条消息说没有监听端口 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"?

如有任何意见、答案或建议,我们将不胜感激。

更新

当我现在尝试使用 oracle, connect using: 时./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)
      )
    )

和 sqlnet.ora

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

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
NAMES.LOG_DIRECTORY = /var/oracle/network/log

答案1

如果不指定主机名,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.

尝试添加-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.

因此,您的连接字符串localhost将被 Oracle 拒绝。

更新

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

相关内容