如何在Windows中以访客身份访问Vagrant中托管的Postgresql?

时间:2015-02-16 16:15:21

标签: postgresql networking vagrant vagrantfile

我正在尝试使用Windows 8.1中的PGAdmin III客户端连接到Postgresql。 Postgresql安装在我的Windows机器上的Vagrant(Ubuntu 14.04)的本地副本中。它在Vagrant上运行起来:

侦听

tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      814/postgres

验证用户/通过/本地连接

我可以通过Windows中的SSH在Vagrant中本地访问Postgresql:

vagrant@precise32:/etc/postgresql/9.1/main$ psql -h localhost testdb myuser
Password for user myuser:
psql (9.1.15)
SSL connection (<removed)
Type "help" for help.

testdb=> \quit

的pg_hba.conf

我将此添加到我的pg_hba.conf文件中:

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             <my IP>                 md5

VAGRANT CONFIG

我的Vagrant配置设置为前进到5432:

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 5432, host: 15432

postgresql.conf中

我的postgresql.conf文件设置为侦听所有IP:

#listen_addresses = '*'    # what IP address(es) to listen on;

PGADMIN错误

所以,当我尝试通过PGAdmin作为访客连接到主机时,我在这里失踪了什么,我收到以下消息,表明它看到了但是有些东西不让我通过?:

An error has occurred:

Error connecting to the server: server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request.

PGADMIN连接信息

Host: localhost
Port: 15432
Service: <blank>
Maintenance DB: postgres
Username: Myuser (verified)
Password: ****** (verified)
Store password:
Colour: <blank>
Group: Servers

3 个答案:

答案 0 :(得分:0)

我不知道你在pg_hba.conf中的意思,但在流浪的环境中,你应该使用像10.0.2.2/24这样的ip而不是你的机器网络地址。

答案 1 :(得分:0)

在您的Vagrant配置中添加IP(如果未设置),例如:

config.vm.network :forwarded_port, host: 15432, guest: 5432
config.vm.network :private_network, ip: "192.168.111.222"

现在从Windows中的PGAdmin连接到主机192.168.111.222,端口5432。

为我工作,虽然我不知道为什么......:P

答案 2 :(得分:0)

我在linux中遇到了同样的问题,我认为在windows中也会发生这种情况。在我的postgresql.conf中,端口变量在两个地方定义。首先是5432值,第二个是5435值。

运行telnet vm_ip 5435,我能够连接到vm中运行的服务器。

在我的情况下,我的vm使用public_network选项运行,所以我有一个外部IP。在这种情况下,一旦您访问vm,您就不需要转发端口,例如,使用192.168.60.15:5435地址。

相关问题