[英]How can I access remotely a postgres database hosted on a raspberry pi (docker) using cloudflare tunnel?
I am trying to access my postgres database remotely, which is hosted on a docker container on my raspberry pi 4. I would like to be able to connect to it through python using something like:我正在尝试远程访问我的 postgres 数据库,该数据库托管在我的 raspberry pi 4 上的 docker 容器中。我希望能够通过 python 连接到它,例如:
import psycopg2
connection = psycopg2.connect('postgres://user:password@db.mydomain.com:5432/mydbname')
The database is actually timescaledb, but should work in the same way as postgres.该数据库实际上是 timescaledb,但应该以与 postgres 相同的方式工作。
I am currently able to access when on my network just by pointing the connection to the internal ip of my raspberry:我目前可以通过将连接指向我的树莓派的内部 ip 来访问我的网络:
connection = psycopg2.connect('postgres://user:password@192.168.1.***:5432/mydbname')
I have installed cloudflared via docker on the raspberry and configured a tunnel by pointing db.mydomain.com to the internal ip address 192.168.1.***:5432 using TCP.我已经通过 docker 在树莓派上安装了 cloudflared,并通过使用 TCP 将 db.mydomain.com 指向内部 IP 地址 192.168.1.***:5432 配置了一个隧道。 Following this guide , I have also installed cloudflared on the client machine (windows) and run in cmd:
按照本指南,我还在客户端计算机 (windows) 上安装了 cloudflared 并在 cmd 中运行:
cloudflared access tcp --hostname db.mydomain.com --url localhost:5432
I tried using HTTP or HTTPS as Service type in cloudflare but nothing seems to work, although I am able to access other containers like portainer on the raspberry through the same tunnel with no problems.我尝试在 cloudflare 中使用 HTTP 或 HTTPS 作为服务类型,但似乎没有任何效果,尽管我能够通过同一个隧道毫无问题地访问树莓上的其他容器,如 portainer。
The error I get in python is:我在 python 中得到的错误是:
psycopg2.OperationalError: connection to server at "db.mydomain.com" (104.2*.**.***), port 5432 failed: Connection timed out (0x0000274C/10060)
Is the server running on that host and accepting TCP/IP connections?
104.21. 104.21。 .
. * seems to be a Cloudflare ip address.
* 似乎是 Cloudflare 的 IP 地址。
Would anybody be so kind to help me solve this issue?有人会这么好心帮我解决这个问题吗? Thank you.
谢谢你。
You need to install a cloudflare tunnel at the origin, so that the sql traffic is proxied.您需要在源站安装 cloudflare 隧道,以便代理 sql 流量。
Here is an example to ssh through terminal a Raspberry remotely: https://youtu.be/fNSf7D8CXgA这是一个远程通过终端 Raspberry ssh 的示例: https ://youtu.be/fNSf7D8CXgA
I hope it helps.我希望它有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.