连接到Google计算引擎上的Postgres服务器 [英] connecting to postgres server on google compute engine

查看:98
本文介绍了连接到Google计算引擎上的Postgres服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在google cloud上安装了PostgreSQL,并且希望能够使用pg-admin从我的PC远程访问它。



当我尝试连接到实例时,确实收到以下错误:


无法连接到服务器:



无法连接到服务器:连接被拒绝(0x0000274D / 10061)
服务器是否在主机 [外部IP我的虚拟机实例]和
在端口5432上接受TCP / IP连接?


我认为这可能是因为Google云防火墙阻止了我(也许!),我为我的实例指定了以下防火墙,我使用我的IP地址定义了源过滤器:



am我缺少了一些东西,因为我仍然无法访问它,有人可以帮我吗,我不知道了,我检查了许多教程,做了很多事情,但我应该解决这个问题。任何人有任何想法吗?

解决方案

我按照



您可以在 VM实例部分上编辑Compute Engine实例。



在这种情况下,使用标记可以为特定计算机在同一网络中设置防火墙规则。



这是我的防火墙规则的定义入口流量。这是我运行Postgresql服务器的Compute Engine实例在网络标签部分配置的标签:





在源IP范围内,您需要将要连接的计算机的PUBLIC IP地址放置到运行postgresql服务器的计算机上,因为这是入口防火墙规则。
以该IP作为源IP,您应该不会遇到任何标签问题。我鼓励您使用标签,因为所有内容都会更加安全。



您可以在以下地址检查本地连接的公共IP:



希望这会有所帮助!



1 https://cloud.google.com/community/tutorials/setting -up-postgres#creating-a-compute-engine-instance



2 https://askubuntu.com/questions/831262/how-to-install-pgadmin-4-in-desktop-mode-on-ubuntu



3 https://www.postgresql.org/message-id/001f01c018c2 $ 830133 b0 $ 64898cd5%40northlink.gr





I have installed a PostgreSQL on google cloud and I want to be able to access it remotely from my PC using preferably pg-admin.

I do get the following error when I try to connect to my instance:

Unable to connect to server:

could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "[external IP of my VM instance]" and accepting TCP/IP connections on port 5432?

I think this could because google cloud firewall is blocking me (maybe!), I specified the following firewall for my instance, I use my ip address to define Source filters:

am I missing something because I cant still access this, can someone please help me I have no idea anymore, I have check many tutorials and I have done many things that I though should fix this. anyone any idea?

解决方案

I followed the tutorial on 1 and I could connect remotely from one machine to another. I could reproduce your case by miss configuring the firewall rules. You have set the firewall rule with a tag. That tag needs to be on the VM too. If you create a firewall rule with a tag, that tag needs to be on(in my case the tag name for the tag is postgre-5432) Network Tags:

You can Edit your Compute Engine instance on the VM instance section.

In this case tags are used to be able to set firewall rules in the same network for a specific machine.

Here is the definition of my firewall rule for ingress traffic. This is the tag that my Compute Engine Instance running postgresql server has configured on the Network Tags section:

In source Ip ranges you need to place the PUBLIC IP address of the computer that you want to connect from, to the computer running the postgresql server as this is an ingress firewall rule. And with that ip as source ip you shouldn’t have any tag problem. I encourage you to use tags as everything will be more secure.

You can check the PUBLIC IP of your local connection in this address: http://ip4.me/

Then on the configuration files you mentioned you need to place the Public IP of your connection . This IP needs to be the same that you are using on your ingress firewall rule.

sudo nano /etc/postgresql/9.5/main/pg_hba.conf: host all all PUBLIC_IP/32 md5

And here you need to set * for the listen_addresses as * means any address. Anyway you are controlling the ips able to connect to your instance in pg_hba.conf:

sudo nano /etc/postgresql/9.5/main/postgresql.conf listen_addresses = '*' # what IP address(es) to listen on;

pgAdmin:

Here you can see how to install pgAdmin4 on ubuntu 2 Here you can see how to connect to postgres from the command line. [3

To be able to connect to your postgres remote instance from pgAdmin4 you need to set the host-name/address to your Compute Engine Instance Ip running your postgresql server. If you followed the tutorial here 1 you should have a default database named postgres too.

Hope this helps!

1 https://cloud.google.com/community/tutorials/setting-up-postgres#creating-a-compute-engine-instance

2 https://askubuntu.com/questions/831262/how-to-install-pgadmin-4-in-desktop-mode-on-ubuntu

3 https://www.postgresql.org/message-id/001f01c018c2$830133b0$64898cd5%40northlink.gr


这篇关于连接到Google计算引擎上的Postgres服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆