我有一个只允许本地连接的PostgreSQL服务器。
我使用“Navicat for PostgreSQL Lite”来执行一些pipe理操作。 在这个客户端中,我configuration了一个SSH隧道到我的服务器。 一切工作正常。
今天,我想用另一个客户端,不让我configurationSSH隧道。 所以,我试图手动打开SSH隧道:
ssh -L 15021:myserver.com:5432 [email protected]
但是,当我试图用它与客户端,它说连接被拒绝。 在SSH提示符下,我收到了这个消息。
channel 3: open failed: connect failed: Connection refused
我试过了
psql -h localhost -p 15021 db_name
同样的错误…
我不明白Navicat是什么神奇的东西,我不会用我的手动SSH隧道。 我非常确定PostgreSQL监听端口5432。
感谢任何指针或答案。
编辑:
这是LogLevel DEBUG的尝试日志。 我匿名了主机名。
Sep 13 14:57:23 myserver sshd[27793]: debug1: server_input_channel_open: ctype direct-tcpip rchan 3 win 2097152 max 32768 Sep 13 14:57:23 myserver sshd[27793]: debug1: server_request_direct_tcpip: originator ::1 port 64027, target myserver.com port 5432 Sep 13 14:57:23 myserver sshd[27793]: debug1: connect_next: host myserver.com ([xxx.xx.xx.xxx]:5432) in progress, fd=9 Sep 13 14:57:23 myserver sshd[27793]: debug1: channel 1: new [direct-tcpip] Sep 13 14:57:23 myserver sshd[27793]: debug1: server_input_channel_open: confirm direct-tcpip Sep 13 14:57:23 myserver sshd[27793]: debug1: channel 1: connection failed: Connection refused Sep 13 14:57:23 myserver sshd[27793]: error: connect_to myserver.com port 5432: failed. Sep 13 14:57:23 myserver sshd[27793]: debug1: channel 1: free: direct-tcpip, nchannels 2
ssh -L 15021:myserver.com:5432 [email protected]
这不是build立隧道的典型方式,因为它要求远程SSH服务器通过公共IP地址( myserver.com )连接到PostgreSQL,
这导致Connection refused因为postgres不听其公共地址。 这是通常和默认的情况。
你可能打算这样做:
ssh -L 15021:localhost:5432 [email protected]
在这种情况下,SSH会将数据库连接从localhost:15021路由到远程主机的localhost:5432 ,这可能是数据库期望连接的地方。