我正在尝试查询一个驻留在远程centos
(redhat 7
)虚拟机上的redhat 7
实例。
以下代码:
import pandas as pd, sqlalchemy
engine = sqlalchemy.create_engine('postgresql://postgres:projectpassword@ip_address_of_vm/project')
df = pd.read_sql_table('test_table', engine)
print(df)
ip_address_of_vm
是ens192 inet
地址。
在以下方面的成果:
psycopg2.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "ip_address_of_vm" and accepting
TCP/IP connections on port 5432?
如果我从我的主机( ping ip_address_of_vm
)计算机(Windows 10
),我收到答复,没有丢包。
在vm内部,我可以运行psql -U postgres
并输入projectpassword
,并且可以正确地登录到数据库中。
我的pg_hba.conf
看起来像:
| TYPE | DATABASE | USER | ADDRESS | METHOD |
|:-----:|:-----------:|:----:|:------------:|:------:|
| local | all | all | | md5 |
| host | all | all | 127.0.0.1/32 | md5 |
| host | all | all | ::1/128 | md5 |
| local | replication | all | | md5 |
| host | replication | all | 127.0.0.1/32 | md5 |
| host | replication | all | ::1/128 | md5 |
| host | all | all | 0.0.0.0/0 | md5 |
| host | all | all | ::/0 | md5 |
注意,在this question之后,我在listen_addresses = '*'
文件中取消了注释,但是发出:psql -h ip_address_of_vm -p 5432 project -U postgres -W
会产生:
psql: error: could not connect to server: Connection Timed out
如何连接远程vm上的postgres实例?
发布于 2021-06-25 16:51:25
您目前在hba.conf文件中没有任何允许的远程连接。
所有这些连接都是本地的(从同一虚拟机连接到数据库的IE)。为了允许连接,您需要添加如下内容:
主机,全,ip_of_remote_machine,md5,
我的看上去像:主机\均\x{e76f}\ md5
它允许我在.32 IP上的桌面计算机连接到驻留在不同IP地址上的虚拟机。
发布于 2021-06-25 16:52:02
这闻起来像防火墙,对我来说不是离题问题。应采取以下步骤:
netstat -lnp | grep postg
或类似的东西)。nmap ip_address_of_vm
-如果它是打开的,回到故障排除后的settings.)iptables -L INPUT
)traceroute ip_address_of_vm
)的路径,并在每个中间跳上查看是否启用了防火墙。https://stackoverflow.com/questions/68134068
复制相似问题