0

我在服务器模式下安装了 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

4

1 回答 1

0

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:

于 2020-08-24T23:23:16.033 回答