gpt4 book ai didi

postgresql - 无法连接到 GCE 虚拟机上的 PostgreSQL 数据库

转载 作者:行者123 更新时间:2023-11-29 13:08:23 24 4
gpt4 key购买 nike

我有一个 PostgreSQL (9.6) 数据库,该数据库部署在带有 Google Compute Engine 的虚拟机上。不幸的是,我可以想出如何从我的本地机器访问它。我更改了 PostgreSQL 的配置文件如下:

/etc/postgresql/9.6/main/postgresql.conf 中,我添加了以下行:

listen_addresses = '*'                  # what IP address(es) to listen on;

/etc/postgresql/9.6/main/pg_hba.conf 我有:

# IPv4 local connections:
host all all 0.0.0.0/0 md5

我还在 GCP 上添加了入口和导出防火墙规则,如下所示(对于糟糕的艺术作品深表歉意): enter image description here

最后,我在我的虚拟机上启用了 IP 转发。

PostgreSQL 的日志看起来不错:

2019-10-04 09:57:20.244 UTC [10015] LOG:  received fast shutdown request
2019-10-04 09:57:20.244 UTC [10015] LOG: aborting any active transactions
2019-10-04 09:57:20.244 UTC [10020] LOG: autovacuum launcher shutting down
2019-10-04 09:57:20.247 UTC [10017] LOG: shutting down
2019-10-04 09:57:20.279 UTC [10015] LOG: database system is shut down
2019-10-04 09:57:21.346 UTC [10331] LOG: database system was shut down at 2019-10-04 09:57:20 UTC
2019-10-04 09:57:21.350 UTC [10331] LOG: MultiXact member wraparound protections are now enabled
2019-10-04 09:57:21.354 UTC [10335] LOG: autovacuum launcher started
2019-10-04 09:57:21.354 UTC [10330] LOG: database system is ready to accept connections
2019-10-04 09:57:21.814 UTC [10337] [unknown]@[unknown] LOG: incomplete startup packet

但是当我尝试从我的本地机器连接到它时,我遇到了超时:

silveris:~$ psql -U admin -h xxx.xxx.xxx.xxx -p 5432 -d ipp
psql: could not connect to server: Connection timed out
Is the server running on host "xxx.xxx.xxx.xxx" and accepting
TCP/IP connections on port 5432?

但是当我通过 SSH 连接到我的 VM 时一切正常:

root@ipf-bdd-test:~# psql -U admin -h localhost -p 5432 -d ipp
Password for user admin:
psql (9.6.15)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

ipp=#

你能指出我缺少的东西吗?

最佳答案

在您的防火墙规则中,您仅在此规则上授权计算默认服务帐户。顺便说一下,如果你从你的电脑上尝试,你没有使用良好的服务帐户,你被拒绝了。

当您从另一个 VM 尝试时,会使用计算默认服务帐户,并且您会被防火墙允许。

选择“apply to all”作为目标,它应该可以工作。

这样做只是为了开发。访问越安全越好(限制 IP、请求服务帐户、...)

关于postgresql - 无法连接到 GCE 虚拟机上的 PostgreSQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58236903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com