如何在 Ubuntu 22.04 LTS 上安装 pgAdmin

在本教程中,我们将向您展示如何在 Ubuntu 22.04 LTS 上安装 pgAdmin。 对于那些不知道的人,pgAdmin 是一个最受欢迎、功能丰富的开源 PostgreSQL 管理和开发平台,可在 Linux、Unix、macOS 和 Windows 上运行。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 Ubuntu 22.04 (Jammy Jellyfish) 上逐步安装 pgAdmin4。 对于 Ubuntu 22.04 和任何其他基于 Debian 的发行版,如 Linux Mint、Elementary OS、Pop!_OS 等,您可以按照相同的说明进行操作。

先决条件

  • 运行以下操作系统之一的服务器:Ubuntu 22.04、20.04 和任何其他基于 Debian 的发行版,如 Linux Mint。
  • 建议您使用全新的操作系统安装来防止任何潜在问题。
  • 对服务器的 SSH 访问(或者如果您在桌面上,则只需打开终端)。
  • 一个 non-root sudo user或访问 root user. 我们建议充当 non-root sudo user,但是,如果您在充当 root 时不小心,可能会损害您的系统。

在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 pgAdmin

步骤 1. 首先,通过运行以下命令确保所有系统包都是最新的 apt 终端中的命令。

sudo apt update sudo apt upgrade sudo apt install software-properties-common apt-transport-https wget ca-certificates libpq5 gnupg2

步骤 2. 在 Ubuntu 22.04 上安装 pgAdmin。

默认情况下,pgAdmin 在 Ubuntu 22.04 基础存储库中不可用。 现在运行以下命令将 pgAdmin 存储库添加到您的 Ubuntu 系统:

sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list'

接下来,使用以下命令导入 GPG 密钥:

curl  -fsSL https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/pgadmin.gpg

启用存储库后,现在使用以下命令安装最新版本的 pgAdmin:

sudo apt update sudo apt install pgadmin4

步骤 3. 配置 Apache pgAdmin 的 Web 服务器。

现在我们发起 Apache 使用以下命令配置 Web 服务器:

sudo /usr/pgadmin4/bin/setup-web.sh

输出:

Setting up pgAdmin 4 in web mode on a Debian based platform... Creating configuration database... NOTE: Configuring authentication for SERVER mode.  Enter the email address and password to use for the initial pgAdmin user account:  Email address: [email protected] Password:  Retype password: pgAdmin 4 - Application Initialisation ======================================  Creating storage and log directories... We can now configure the Apache Web server for you. This involves enabling the wsgi module and configuring the pgAdmin 4 application to mount at /pgadmin4. Do you wish to continue (y/n)? y The Apache web server is running and must be restarted for the pgAdmin 4 installation to complete. Continue (y/n)? y Apache successfully restarted. You can now start using pgAdmin 4 in web mode at https://127.0.0.1/pgadmin4

当上述脚本运行时,输入您将用于登录仪表板的电子邮件和密码。

步骤 4. 配置防火墙。

现在我们设置一个简单的防火墙(UFW) Apache 允许对 HTTP 和 HTTPS 的默认 Web 端口进行公共访问:

sudo ufw allow OpenSSH sudo ufw allow 'Apache Full' sudo ufw enable

步骤 5. 访问 pgAdmin Web 界面。

成功安装后,打开您的 Web 浏览器并使用 URL 访问 pgAdmin Web UI https://your-IP-addresss/pgadmin4. 您将被重定向到以下页面:

恭喜! 您已成功安装 pgAdmin。 感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装 pgAdmin4。 如需更多帮助或有用信息,我们建议您查看 pgAdmin 官方网站.