PostgreSQL在Ubuntu重启后拒绝TCP / IP连接


0

这让我感到困惑。

我重新启动了ubuntu服务器,现在尝试与pgadmin连接,并得到以下信息:

could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "<ip.address>" and accepting
TCP/IP connections on port 5432?

在我的postgresql.conf文件中

listen_addresses = '*'

在我的pg_hba.conf中

# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# 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
# 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    all     all     129.125.179.201/32      trust
host    all     all     86.81.139.21/24         trust

我将以下行添加到末尾

host    all     all     0.0.0.0/0       md5

仍然无法连接

每次更改后,我都重新启动了postgresql。

我可以通过shh通过命令行登录到postgresql。

我没主意了!

编辑

iptables

sudo iptables -S
-P INPUT ACCEPT
-P FORWARD DROP
-P OUTPUT ACCEPT
-N DOCKER
-N DOCKER-ISOLATION
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT --reject-with icmp-port-unreachable
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
-A INPUT -j DROP
-A FORWARD -j DOCKER-ISOLATION
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -j DROP
-A OUTPUT -j ACCEPT
-A DOCKER-ISOLATION -j RETURN

Netstat结果

netstat -lt4
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:mysql         *:*                     LISTEN
tcp        0      0 *:8787                  *:*                     LISTEN
tcp        0      0 *:ssh                   *:*                     LISTEN
tcp        0      0 *:postgresql            *:*                     LISTEN

iptables保存

sudo iptables-save
# Generated by iptables-save v1.6.0 on Sat Sep 23 18:23:36 2017
*nat
:PREROUTING ACCEPT [48958:12725477]
:INPUT ACCEPT [2847:159736]
:OUTPUT ACCEPT [70:6309]
:POSTROUTING ACCEPT [70:6309]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A DOCKER -i docker0 -j RETURN
COMMIT
# Completed on Sat Sep 23 18:23:36 2017
# Generated by iptables-save v1.6.0 on Sat Sep 23 18:23:36 2017
*filter
:INPUT ACCEPT [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
:DOCKER - [0:0]
:DOCKER-ISOLATION - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT --reject-with icmp-port-unreachable
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
-A INPUT -j DROP
-A FORWARD -j DOCKER-ISOLATION
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -j DROP
-A OUTPUT -j ACCEPT
-A DOCKER-ISOLATION -j RETURN
COMMIT
# Completed on Sat Sep 23 18:23:36 2017

1
您没有偶然运行的防火墙,对吗?
Vanessa Deagan

不是我设置的,但是您如何检查?正如我所说的,它在重新启动之前运行正常。尽管我确实做了apt-get install postgis *来安装脚本,但是我还是试图进行pg_pointclouds的安装。
Spatial Digger

sudo iptables -S。如果要从同一台计算机进行连接,则可能还需要尝试host all all 127.0.0.1/32 md5
Vanessa Deagan

我已经添加了iptables的输出,机器正在工作,我正在使用腻子ssh进行连接。感谢您的协助。
Spatial Digger

主机所有127.0.0.1/32 md5已在本地连接下设置。
Spatial Digger

Answers:


0

我认为问题与授权(例如pg_hba.conf)无关,因为您的错误提示端口不可达。尝试指向尽可能多的连接参数。也尝试使用一些简单的工具(例如psql)进行连接(给出所有连接参数,例如-h localhost -U用户-W -p 5432等)。这应该为您提供一些提示,说明发生了什么以及在哪里可以找到。

特别要给他-h localhost,否则它将使用TCP的本地unix套接字指示

编辑:您确定,这是一个很好的iptable规则:-A INPUT -d 127.0.0.0/8 -j REJECT --reject-with icmp-port-unreachable我不是这里的专家,但是尝试临时删除此条目并重新连接。同样的关注点:-A INPUT -j DROP

EDIT2:如果没有任何效果,请通过“ iptables -S”的“ iptables-save”转储所有iptables。“ iptables-save”转储所有可用的表(例如filter,nat等)。手册中的更多信息


psql -U <用户名> -h <ip。地址> -W -p 5432在shell上运行良好,它说:psql(9.5.8)SSL连接(协议:TLSv1.2,密码:ECDHE-RSA-AES256- GCM-SHA384,位:256,压缩:关闭)
Spatial Digger

至于iptables,上一次我尝试更改它们时,我最终进行了全新安装
Spatial Digger

我应该如何使用命令行将其删除-更重要的是,应该如何将它们放回原处?抱歉,我仍在学习linux的复杂性。
Spatial Digger

仔细阅读iptable手册,您需要了解的所有内容。但是,如果您能够与psql连接,则相同的连接参数应与pgadmin3一起使用。检查是否有任何连接参数
差异

嘿,您发布了,您能够通过psql成功连接-您是否首先使用ssh连接到服务器?如果为真,则不要!在与尝试运行pgadmin3相同的系统上运行psql
Astinus Eberhard
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.