连接到Amazon EC2上远程PostgreSQL服务器 [英] Connect to remote postgresql server on amazon ec2
问题描述
我开始一个Amazon EC2实例,并安装PostgreSQL的9.1在它。然后我去了
安全组:快速启动-1 (有一个更
default`,我并没有改变),并开通了5432 TCP端口,表看起来是这样的:
I started an amazon ec2 instance, and installed postgresql 9.1 over it. I then went to the
Security Group: quicklaunch-1(there was one more
default` which i did not change) and opened the 5432 TCP Port, the table looks like this:
(Service) Source Action
22 0.0.0.0/0 Delete
5432 0.0.0.0/32 Delete
5433 0.0.0.0/32 Delete
6432 0.0.0.0/32 Delete
我创建了一个数据库和用户。
我的 /etc/postgresql/9.1/main/pg_hba.conf
是这样的:
I have created a database and user .
My /etc/postgresql/9.1/main/pg_hba.conf
looks like this:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
host db_name user_name 0.0.0.0/0 md5
# "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
# 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
和 /etc/postgresql/9.1/main/postgresql.conf 是这样的:
# - Connection Settings -
listen_addresses = '*'
#listen_addresses = 'localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
port = 5432 # (change requires restart)
然后我尝试在连接到远程计算机,如下所示:
I then try to connect on to the remote machine as follows:
psql -h ec2-xxx-xx-xxx-xxx.compute-1.amazonaws.com -d <database_name> -U <username>
其中 ec2-xxx-xx-xxx-xxx.compute-1.amazonaws.com 我公开DNS
上面的命令不会导致任何连接,我该怎么连接?
The above command does not result in any connection, how can i connect?
推荐答案
在此表中:
5432 0.0.0.0/32 Delete
5433 0.0.0.0/32 Delete
6432 0.0.0.0/32 Delete
在CIDRs看起来像你没有让任何IP地址。难道他们不应该是 0.0.0.0/0
代替,就像你所拥有的端口22(SSH )?
the CIDRs look like you're not allowing any IP in. Shouldn't they be 0.0.0.0/0
instead, like what you have for port 22 (ssh)?
这篇关于连接到Amazon EC2上远程PostgreSQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!