【问题标题】:Postgresql Centos IssuePostgresql Centos 问题
【发布时间】: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


【解决方案1】:

更改listen_addresses 后,您还没有重新启动 PostgreSQL。它仍在收听127.0.0.1,即仅环回。或者您为不同的 PostgreSQL 安装编辑了配置文件。

如果您连接到主机127.0.0.1 端口5432,它将起作用。或者确保您编辑了正确的配置并重新启动(不仅仅是重新加载)PostgreSQL。

【讨论】:

  • 我重启了 3-4 次。另外,我可以在 127.0.0.1 连接,但不能在外部连接,所以我的问题似乎出在一些我不知道的防火墙或类似的东西上。我编辑了 iptables,所以它似乎不是那样的。重启服务失败时,我什至重启了整个系统。
  • SHOW config_file; - 确保您编辑了正确的。还有SHOW listen_addresses。它与防火墙无关-您的问题清楚地表明 Pg 仅在环回接口上侦听,请查看您的 netstat 输出。
  • 谢谢克雷格。我已经更新了 postgres tp 9.1 但忘记了。我只是继续并重新配置服务器,因为它正在转换为没有数据的数据库服务器。
猜你喜欢
  • 2014-09-08
  • 2017-08-28
  • 1970-01-01
  • 1970-01-01
  • 2014-03-28
  • 1970-01-01
  • 2011-10-04
  • 2021-02-19
  • 2018-09-02
相关资源
最近更新 更多