简体   繁体   English

psql-Mac试图连接安装在远程服务器中虚拟机中的Ubuntu系统中的postgreSQL

[英]psql - Mac trying to connect postgreSQL in Ubuntu system installed in a virtual machine in remote server

Apologize in front, maybe the situation here is a bit complicated. 在前面道歉,也许这里的情况有点复杂。 I searched everywhere online but couldn't find a perfect solution, plus I have tried almost all the solutions mentioned in other posts. 我在网上到处搜索,但找不到完美的解决方案,而且我尝试了其他帖子中提到的几乎所有解决方案。

  • Situation: 情况:

So I have a postgreSQL database installed in a Ubuntu system. 所以我在Ubuntu系统中安装了一个postgreSQL数据库。 The system is actually a virtual machine on the VMware workstation 12, which is installed on Windows 7 professional. 该系统实际上是VMware工作站12上的虚拟机,该工作站安装在Windows 7 Professional上。 Now I am trying to remotely access the postgreSQL database through my MacBook pro 2013. 现在,我尝试通过MacBook Pro 2013远程访问postgreSQL数据库。

In the Mac terminal, the command line I tried is: 在Mac终端中,我尝试过的命令行为:

psql -U postgres -h xxx.xxx.xxx.xx psql -U postgres -h xxx.xxx.xxx.xx

"xxx.xxx.xxx.xx" represents the IP address of the Windows 7 machine. “ xxx.xxx.xxx.xx”代表Windows 7计算机的IP地址。 The result is a failure: 结果是失败:

psql: could not connect to server: Operation timed out Is the server running on host "169.254.121.2" and accepting TCP/IP connections on port 5432? psql:无法连接到服务器:操作超时服务器是否在主机“ 169.254.121.2”上运行并接受端口5432上的TCP / IP连接?

  • What I have done: 我做了什么:

    1. Edited the pg_hba.conf file to include 编辑了pg_hba.conf文件以包括

host all all 0.0.0.0/0 md5 托管所有0.0.0.0/0 md5

  1. Edited the postgresql.conf to include 编辑了postgresql.conf以包括

listen_addresses='*' listen_addresses ='*'

  1. Restarted postgres service. 重新启动postgres服务。
  2. Disabled firewall on the host. 主机上禁用了防火墙。
  3. I checked by running the psql command locally and it worked. 我通过在本地运行psql命令进行了检查,它是否有效。 Also, on the same VMware I have other Ubuntu systems. 另外,在同一VMware上,我还有其他Ubuntu系统。 They are all fine to connect and access the data in this Ubuntu system. 它们都可以很好地连接和访问此Ubuntu系统中的数据。
  4. Running Nmap, the output is 运行Nmap,输出为

PORT STATE SERVICE 港口国服务

5432/TCP open postgresql 5432 / TCP打开PostgreSQL

  • What's next? 下一步是什么? Anything else I can try? 我还能尝试什么吗? Any advice is highly appreciated and please let me know if anything above is ambiguous. 如有任何建议,我们将不胜感激,如果有任何歧义,请告诉我。 I will clarify for better diagnosis. 我将澄清以便更好地诊断。 Thank you all! 谢谢你们!

Somehow managed to get it working.. 不知何故设法使其正常工作。

So when I ran "Nmap" on the other Ubuntu system towards this one, it does shows 因此,当我在另一个Ubuntu系统上针对该系统运行“ Nmap”时,它确实显示

PORT STATE SERVICE 港口国服务

5432/TCP open postgresql 5432 / TCP打开PostgreSQL

However, when I ran "Nmap" on my Mac, it's a different port, 3389, which is mainly used for Windows remote desktop. 但是,当我在Mac上运行“ Nmap”时,它是另一个端口3389,主要用于Windows远程桌面。 So what I did was to check the network configuration of this Ubuntu virtual machine from " bridged " to " NAT " and did a port forwarding to 5432. It is working fine now.. 因此,我要做的就是检查此Ubuntu虚拟机从“ 桥接 ”到“ NAT ”的网络配置,并进行端口转发到5432。现在工作正常。

I read in some places saying that VMware favors bridged whereas VirtualBox favors NAT+port forwarding. 我在某些地方读到说VMware支持桥接,而VirtualBox支持NAT +端口转发。 I am quite confused as it is certain not the case in my situation. 我很困惑,因为可以肯定我的情况并非如此。 Maybe I am wrong. 也许我错了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VS Code 无法从 mac 连接到远程 Ubuntu 机器 - VS Code is not able to connect to Remote Ubuntu machine from mac 无法连接到运行在 windows 10 虚拟机中的 postgresql 服务器 - Cant connect to postgresql server running in windows 10 virtual machine 无法通过 ODBC 从 Ubuntu 连接远程 Postgresql 服务器 - Unable to connect remote Postgresql server from Ubuntu by ODBC 尝试将文件从本地 Mac 上传到远程 Ubuntu 服务器 - Trying to upload a file from local Mac to remote Ubuntu server 在 mac 上工作但不在机器上工作 - linux ubuntu - 节点服务器 - Working on mac but not on machine - linux ubuntu - node server 服务器未连接到远程计算机(Linux) - Server does not connect to remote machine (Linux) 从ubuntu连接到远程mysql服务器失败 - Connect to remote mysql server from ubuntu fails “没有连接的设备”,试图将我的LG连接到我的Ubuntu机器 - “No Connected Devices”, trying to connect my LG to my Ubuntu machine 如何在Azure中连接到在Linux虚拟机上运行的mysql服务器 - how to connect to a mysql server running on a linux virtual machine in azure 当我使用visual studio远程linux连接到一个linux虚拟机时,连接不稳定 - When I use visual studio remote linux to connect to connect to a linux virtual machine, the connection is instability
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM