[英]Setting up a Remotely Accessible Postgres Database with Linux and PGAdmin
I'm trying to set up a remotely accessible Postgres database .我正在尝试建立一个可远程访问的 Postgres 数据库。 I want to host this databse on one Linux based device (HOST), and to access it on another Linux based device (CLIENT).
我想在一个基于Linux的设备 (HOST) 上托管这个数据库,并在另一个基于 Linux 的设备 (CLIENT) 上访问它。
In my specific case, HOST is a desktop device running Ubuntu.在我的具体情况下,HOST 是运行 Ubuntu 的桌面设备。 CLIENT is a Chromebook with a Linux virtual system.
CLIENT 是带有 Linux 虚拟系统的 Chromebook。 (I know. But it's the closest thing to a Linux based device that I have to hand.
(我知道。但它是我手头最接近基于 Linux 的设备的东西。
PGP_KEY_URL="https://www.postgresql.org/media/keys/ACCC4CF8.asc"
POSTGRES_URL_STEM="http://apt.postgresql.org/pub/repos/apt/"
POSTGRES_URL="$POSTGRES_URL_STEM `lsb_release -cs`-pgdg main"
POSTGRES_VERSION="12"
PGADMIN_URL_SHORT="https://www.pgadmin.org/static/packages_pgadmin_org.pub"
PGADMIN_URL_STEM="https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt"
PGADMIN_TO_ECHO="deb $PGADMIN_URL_STEM/`lsb_release -cs` pgadmin4 main"
PGADMIN_PATH="/etc/apt/sources.list.d/pgadmin4.list"
sudo apt install curl --yes
sudo apt install gnupg2 --yes
wget --quiet -O - $PGP_KEY_URL | sudo apt-key add -
echo "deb $POSTGRES_URL" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt install postgresql-$POSTGRES_VERSION --yes
sudo apt install postgresql-client-$POSTGRES_VERSION --yes
sudo curl $PGADMIN_URL_SHORT | sudo apt-key add
sudo sh -c "echo \"$PGADMIN_TO_ECHO\" > $PGADMIN_PATH && apt update"
sudo apt update
sudo apt install pgadmin4 --yes
NU_USERNAME="my_user"
NU_PASSWORD="guest"
NU_QUERY="CREATE USER $NU_USERNAME WITH superuser password '$NU_PASSWORD';"
sudo -u postgres psql -c "$NU_QUERY"
Host IP Address: 192.168.1.255
主机IP地址:192.168.1.255
Port: 5432 (same as when I set up the database on HOST)端口:5432(和我在HOST上设置数据库时一样)
User: my_user用户:my_user
Password: guest密码:访客
However, when I try to save the connection, PGAdmin responds after a few seconds saying that the connection has timed out .但是,当我尝试保存连接时,PGAdmin 会在几秒钟后回复说连接已超时。
You have to configure listen_addresses
in /var/lib/pgsql/data/postgresql.conf
like this:您必须像这样在
/var/lib/pgsql/data/postgresql.conf
中配置listen_addresses
:
listen_addresses = '*'
Next make sure your firewall doesn't block the connection by checking if telnet can connect to your server:接下来通过检查 telnet 是否可以连接到您的服务器来确保您的防火墙不会阻止连接:
$ telnet 192.168.1.255 5432
Connected to 192.168.1.255.
Escape character is '^]'.
If you see Connected
network connectivity is ok.如果您看到
Connected
的网络连接正常。 Next you have to configure access rights for remote hosts.接下来,您必须配置远程主机的访问权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.