我第一次尝试在远程/云VPS上设置应用程序(我使用的是Digital Ocean)。我试图从我的客户端创建一个SSH隧道到远程数据库。由于我以前没有尝试过这种操作,因此我参考了这篇文章,这篇文章和这篇文章。
阅读完文章后,我在自己的客户端/本地机器上运行了以下命令:
然而,我收到了以下错误信息:
据我所知,我远程服务器上的pg_hba.conf是默认的:
我把postgresql.conf文件中的"listen_addresses"改成了*。
它停在那里,不响应任何命令。
感谢您的任何指导。
阅读完文章后,我在自己的客户端/本地机器上运行了以下命令:
ssh -L 5433:localhost:5432 user@REMOTE_IP
然后我尝试连接:
psql -h localhost -p 5433 postgres;
然而,我收到了以下错误信息:
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5433?
据我所知,我远程服务器上的pg_hba.conf是默认的:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
我把postgresql.conf文件中的"listen_addresses"改成了*。
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
我曾试过将127.0.0.1替换为localhost,但没有成功。
欢迎提出任何建议。我不熟悉SSH隧道等技术。
谢谢。 编辑:
根据@drdaeman的建议,我运行了以下命令:
sudo ssh -N -vvv -L 5433:localhost:5432 user@host
最后几条调试信息如下:
debug1: Local forwarding listening on 127.0.0.1 port 5433.
debug2: fd 5 setting O_NONBLOCK
debug3: fd 5 is O_NONBLOCK
debug1: channel 1: new [port listener]
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IP_TOS 0x10
debug1: Requesting no-more-sessions@openssh.com
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: receive packet: type 80
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
请输出以下命令sudo netstat -ltpn | grep 5432
的结果:
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 5835/postgres
它停在那里,不响应任何命令。
感谢您的任何指导。