【问题标题】:GCP firewall rule for tcp port are not workingtcp 端口的 GCP 防火墙规则不起作用
【发布时间】:2022-01-13 11:08:30
【问题描述】:

我有一个安装了 postgres 的虚拟机,现在我正在尝试从外部连接这个 PG,我创建了一个防火墙规则,将 5432 端口打开到任何源 IP,如下所示

我的实例有规则

但是当我尝试检查端口是否打开时,它对我来说失败了

$ nc -zv public-ip 5432
nc: connectx to public-ip port 5432 (tcp) failed: Connection refused
$ nc -zv public-ip 22  
Connection to public-ip port 22 [tcp/ssh] succeeded!
$ psql -h public-ip -p 5432 --username=myuser --dbname=mydb --password 
Password: 
psql: error: connection to server at "public-ip", port 5432 failed: Connection refused
    Is the server running on that host and accepting TCP/IP connections?

我尝试重新启动虚拟机,但没有帮助。我错过了什么?

【问题讨论】:

  • 如果您点击规则,它应该会告诉您它当前适用于哪些虚拟机。您看到那里列出了您的 PostgreSQL 虚拟机吗?如果没有,请检查以确保 VM 上有正确的标签。
  • 而且,除了@glen-yu 评论之外,您是否确信 VM 将端口暴露在 localhost/loopback 以外的网络接口上?您可以从 VM(或其他 VM)通过该端口上 VM 的内部 IP 连接到数据库吗?

标签: google-cloud-platform firewall google-cloud-networking google-cloud-instances


【解决方案1】:

连接被拒绝意味着您可以启动 TCP 连接,但没有进程正在侦听该端口,因此连接尝试被拒绝。这意味着防火墙可能不是问题。防火墙问题通常会导致超时错误。

编辑 postgresql.conf 配置文件:

listen_addresses = '*'

18.3.1. Connection Settings

【讨论】:

  • 我还必须将此host all all 0.0.0.0/0 md5 添加到pg_hba.conf
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-05
  • 2022-11-14
  • 2015-06-17
  • 1970-01-01
  • 2016-07-09
  • 2020-01-30
  • 1970-01-01
相关资源
最近更新 更多