尝试通过端口转发连接到远程虚拟机数据库。 VM主机是远程服务器(Ubuntu x64),来宾VM是Ubuntu x64,并且为15432 =>设置端口转发。 5432(host => guest)。
当我尝试通过psql或pgAdmin3连接时,我收到连接拒绝错误。
来自本地机器的psql命令:
psql -h remote.server.address -p 15432 -U postgres database_name
响应:
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
postgresql.conf listen_addresses设置为all:
$ cat /etc/postgresql/9.4/main/postgresql.conf | grep listen
listen_addresses = '*' # what IP address(es) to listen on;
我的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
host all all 10.0.0.0/16 md5
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
host informatics nmr_user 192.168.20.223/32 md5
host all all 192.168.8.0/22 md5
host all all 192.168.50.0/24 md5
host all all 192.168.7.0/24 md5
host all all 192.168.4.0/24 md5
host all all 192.168.6.0/24 md5
SSL证书存在于pg_hba.conf中指定的路径中 重新启动postgres服务也无法解决问题
非常确定我的问题出在pg_hba中。我是网络业余爱好者。在vm:
$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:9a:8e:c6 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
inet6 fe80::a00:27ff:fe9a:8ec6/64 scope link
valid_lft forever preferred_lft forever
任何帮助都将不胜感激!!
修改:已解决
问题不在于postgres配置,而是远程主机上的Virtualbox VM配置。使用NAT设置端口转发,主机侦听127.0.0.1:15432。因为它只是监听环回接口,所以外部世界将端口15432视为关闭。在主机上将NAT更改为0.0.0.0:15432后,端口已打开并且连接已完成。
感谢您的建议