在 CentOS 7 和 Fedora 38/37/36/35/34 上安装 pgAdmin 4
pgAdmin 是领先的开源、功能丰富的 PostgreSQL 管理和开发平台,可在 Linux、Unix、Mac OS X 和 Windows 上运行。 pgAdmin 可用于管理 PostgreSQL 9.2 及以上版本。随着 pgAdmin 4 的发布,从 Bootstrap 3 迁移到 Bootstrap 4。在本文中,我们将在 CentOS 7 和 Fedora 38/37/36/35/34/33/32 上安装 pgAdmin 4。
对于 CentOS 8:如何在 CentOS 8 Linux 上安装 pgAdmin 4
在 CentOS 7 和 Fedora 上安装 pgAdmin 4 之前考虑系统更新。
sudo yum -y update
在 CentOS 7/Fedora 38/37/36/35/34/33 上安装 pgAdmin4
您需要先在系统上安装 PostgreSQL,然后才能安装 pgAdmin 4。以下是帮助您安装 PostgreSQL 的指南:
- 如何在 CentOS 7 上安装 PostgreSQL 12
- 在 CentOS 7 上安装 PostgreSQL 13
- 如何在 Fedora 上安装 PostgreSQL
第1步:添加pgAdmin 4存储库
安装 PostgreSQL 后,您可以开始在 CentOS 7 上安装 pgAdmin 4。您需要添加 pgAdmin 4 RPM:
CentOS 7:
sudo yum install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm
软呢帽:
下载存储库文件。
source /etc/os-release
sudo tee /etc/yum.repos.d/pgadmin4.repo<<EOF
[pgAdmin4]
name=pgadmin4
baseurl=https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/fedora/fedora-$VERSION_ID-x86_64/
enabled=1
repo_gpgcheck=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGADMIN_PKG_KEY
EOF
您可以使用以下命令检查创建的存储库文件的内容:
$ cat /etc/yum.repos.d/pgadmin4.repo
[pgAdmin4]
name=pgadmin4
baseurl=https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/redhat/rhel-$releasever-$basearch
enabled=1
repo_gpgcheck=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/PGADMIN_PKG_KEY
步骤2:在CentOS 7/Fedora上安装pgAdmin4
然后安装pgAdmin4包
仅以网页模式安装,适用于服务器:
sudo yum install pgadmin4-web
安装桌面和网络模式。
sudo yum install pgadmin4
仅安装桌面模式,适用于桌面:
sudo yum install pgadmin4-desktop
检查安装依赖关系树,然后继续:
....
Transaction Summary
======================================================================================================================================================================================================
Install 3 Packages
Total download size: 77 M
Installed size: 289 M
Is this ok [y/N]: y
步骤 3:在 CentOS 7/Fedora 上配置 pgAdmin 4
现在我们已经安装了 pgAdmin 4,让我们对其进行配置。
1.
启动并启用httpd服务开机启动
sudo systemctl start httpd && sudo systemctl enable httpd
您可以通过运行以下命令来确认服务状态:
$ systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2021-10-24 22:34:22 UTC; 10s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 6377 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─6377 /usr/sbin/httpd -DFOREGROUND
├─6378 /usr/sbin/httpd -DFOREGROUND
├─6379 /usr/sbin/httpd -DFOREGROUND
├─6380 /usr/sbin/httpd -DFOREGROUND
├─6381 /usr/sbin/httpd -DFOREGROUND
├─6382 /usr/sbin/httpd -DFOREGROUND
└─6383 /usr/sbin/httpd -DFOREGROUND
Oct 24 22:34:22 centos.example.com systemd[1]: Starting The Apache HTTP Server...
Oct 24 22:34:22 centos.example.com httpd[6377]: [Sun Oct 24 22:34:22.727756 2021] [so:warn] [pid 6377] AH01574: module wsgi_module is already loaded, skipping
Oct 24 22:34:22 centos.example.com systemd[1]: Started The Apache HTTP Server.
最后,如果您已经安装了 pgadmin4 或 pgadmin4-web,请运行 Web 设置脚本以将系统配置为在 Web 模式下运行:
sudo /usr/pgadmin4/bin/setup-web.sh
这将要求您输入 pgadmin4 用户电子邮件地址并设置密码:
Setting up pgAdmin 4 in web mode on a Redhat 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: <input-email-address>
Password: <input-password>
Retype password: <Reenter-password>
pgAdmin 4 - Application Initialisation
======================================
Creating storage and log directories...
同意 Apache Web 服务器的配置。
Configuring SELinux...
The Apache web server is not running. We can enable and start the web server for you to finish pgAdmin 4 installation. Continue (y/n)? y
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Apache successfully enabled.
Apache successfully started.
You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4
步骤 4:访问 pgAdmin 4 Web 界面
如果您有活动的防火墙服务,请允许 http 端口
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
打开 http://[serverip_or_hostname]/pgadmin4
,使用上面步骤 6
创建的凭据登录 pgAdmin。
在 pgAdmin 的第一页上,通过点击“添加新服务器”添加要使用 pgAdmin 进行管理的 PostgreSQL 服务器。这可以是本地或远程 PostgreSQL 服务器。
在“常规”部分下,为服务器提供名称和说明。
在“连接”选项卡下,提供访问详细信息 - 数据库主机、数据库用户和密码。
完成后,点击保存按钮保存配置。如果您成功添加服务器,名称将显示在左侧边栏中。选择服务器以查看数据库摘要信息并进行更改。
我希望我们的文章对在 CentOS 7 和 Fedora 服务器/桌面上安装 pgAdmin 4 有所帮助。
学习 PostgreSQL 数据库的书籍:
- 学习 PostgreSQL 数据库的最佳书籍
有关安装 pgAdmin 4 的其他指南:
- 如何在 FreeBSD 12 上安装 pgAdmin4
- 在 Ubuntu 上安装 pgAdmin4
- 在 Debian 上安装 pgAdmin4