【发布时间】:2014-06-05 07:01:06
【问题描述】:
我正在尝试启用 Postgresql 9.3 以在 CentOS6 上接受远程连接。我在 iptables 中打开了端口,在 pgconf 文件中将端口设置为 5432,将 listen_addresses 设置为 '*'(接受所有连接),并允许 pg_hba 中的地址与主机全部 0.0.0.0/0 信任。 postmaster 在 5432 上运行。但是,我仍然收到以下错误。如何获得有效的连接?
错误:
could not connect to server: Connection refused
Is the server running on host "50.63.141.236" and accepting
TCP/IP connections on port 5432?
pg_hba.conf 文件的相关部分:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
#opens postgres to the internet
host all all 0.0.0.0/0 trust
iptables -L 的相关输出:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:postgres
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:postgres
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:postgres
最后,证明 postmaster 正在运行。
EN 1433/sshd
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LIST
【问题讨论】:
-
为什么信任 0.0.0.0/0 而不是 md5?
-
你确定 0.0.0.0 是你想要的 - 据我了解,这是一个未知的 IP 标头。在我们的 pg_hba.conf 文件(还有 pg9.3 和 centos)中,我们有我们的实际外部 IP 地址,后跟 32,例如 123.123.123.123/32
-
0.0.0.0/0匹配所有 IP 地址,因为子网掩码前缀/0不屏蔽任何内容。没关系,只要您不面向 Internet。 -
我现在只是想让它工作,所以我不担心 IP 地址。
标签: postgresql centos postgresql-9.3