执行firewalld后无法访问pgAdmin4服务器模式

问题描述

我在服务器模式下安装了Postgresql 12,PostGIS和pgAdmin4。我可以通过域名访问pgAdmin4。但是,当我尝试通过QGIS或RStudio访问Postgresql数据库时,出现以下错误

Is the server running on host <ServerName> and accepting TCP/IP connections on port 5432?

我将postgresql.conf文件设置为 local_address = '0.0.0.0'pg_hba.conf

host    all             all             0.0.0.0/0               md5
host    all             all             ::/0                    md5

即使进行了此更改,我也无法通过QGIS访问数据库,因此我引用了此http://www.project-open.com/en/howto-postgresql-port-secure-remote-access。按照此过程,我执行了:

firewall-cmd --zone=public --add-port=5432/tcp --permanent
firewall-cmd --reload 

现在,我可以通过QGIS访问数据库,但不能访问pgAdmin4,它现在显示错误

The connection has timed out

The server at <ServerName> is taking too long to respond

执行$ netstat -na 结果:

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN
tcp        0    320 45.56.73.78:22          47.185.238.169:50439    ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::80                   :::*                    LISTEN
udp        0      0 127.0.0.53:53           0.0.0.0:*
udp6       0      0 ::1:53481               ::1:53481               ESTABLISHED
raw6       0      0 :::58                   :::*                    7

我认为这是由于防火墙的更改引起的,但是我没有足够的经验来解决此问题。任何帮助都会很棒,谢谢!

服务器:Ubuntu 20.04

解决方法

我通过使用以下命令在防火墙中添加端口80/tcp来解决此问题:

附加之前的状态:

$ firewall-cmd --list-all 
public
  target: default
  icmp-block-inversion: no
  interfaces:
  sources:
  services: dhcpv6-client ssh
  ports: 5432/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

添加80 / tcp:

$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ firewall-cmd --reload
$ firewall-cmd --list-all
public
  target: default
  icmp-block-inversion: no
  interfaces:
  sources:
  services: dhcpv6-client ssh
  ports: 5432/tcp 80/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules: