如何在 CentOS 7/RHEL 7 上以服务器模式将PgAdmin 4安装为Web应用程序

PgAdmin 4 是对流行的 PostgreSQL 数据库 pgAdmin3 管理工具的重写。

PgAdmin 是 PostgreSQL 领先的图形开源管理、开发和管理工具。

在本教程中,我们将演示如何在CentOS 7/RHEL 7上使用mod_WSGI在服务器模式下作为Apache HTTP下的WSGI应用程序运行和安装PgAdmin 4 v2。

为 PGAdmin 4 创建 Apache 虚拟主机

创建一个新的 apache 虚拟主机文件并添加以下几行

# vi /etc/httpd/conf.d/pgadmin4.conf
<VirtualHost *>
    ServerName pgadmin.onitroad.local
    WSGIDaemonProcess pgadmin processes=1 threads=25
    WSGIScriptAlias//usr/lib/python2.7/site-packages/pgadmin4-web/pgAdmin4.wsgi

    <Directory "/usr/lib/python2.7/site-packages/pgadmin4-web/">
        WSGIProcessGroup pgadmin
        WSGIApplicationGroup %{GLOBAL}
        Require all granted
    </Directory>
</VirtualHost>

使用以下命令检查apache配置:

# apachectl configtest
Syntax OK

通过运行以下命令重新启动 Apache

# systemctl restart httpd

为了确保 PgAdmin 可以访问 PostgreSQL 服务器,我们需要使用以下命令调整 Selinux 以允许 Apache 通过网络连接

# setsebool -P httpd_can_network_connect 1

安装 PGAdmin 4

要安装 PgAdmin4 v2 ,我们将使用 PostgreSQL RPM ,使用以下命令安装 PostgreSQL 存储库:

# yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
# yum install epel-release

使用以下命令安装 PgAdmin 4 v2

# yum install pgadmin4-v2

配置 PGAdmin 4

为了将 pgAdmin 配置为作为 Web 应用程序在服务器模式下正确运行,可能需要指定 PgAdmin 数据库、会话和日志文件的路径。
打开 config_distro.py 文件并添加以下设置:

# vi /usr/lib/python2.7/site-packages/pgadmin4-web/config_distro.py
LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage'

运行以下命令以创建配置数据库。

# python /usr/lib/python2.7/site-packages/pgadmin4-web/setup.py
NOTE: Configuring authentication for SERVER mode.
Enter the email address and password to use for the initial pgAdmin user account:
Email address: jack@onitroad
Password:Type the Password
Retype password:Retype the Password
pgAdmin 4 - Application Initialisation
======================================

将配置数据库目录的所有权更改为用户 Apache :

# chown -R apache:apache /var/lib/pgadmin4
# chown -R apache:apache /var/log/pgadmin4

如果启用了 SeLinux,请使用以下命令调整 SELinux 策略:

# chcon -R -t httpd_sys_content_rw_t "/var/log/pgadmin4/"
# chcon -R -t httpd_sys_content_rw_t "/var/lib/pgadmin4/"

访问 PGAdmin 4

如果启用了防火墙,请执行以下命令启用 http 服务:

# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload
success

打开 http://pgadmin.onitroad.local 并使用凭据登录到 PgAdmin。

日期:2020-06-02 22:18:16 来源:oir作者:oir