RedHat/CentOS8【PGAdmin4】服务器模式安装、

2020-03-20  本文已影响0人  张毅SOHO

PGAdmin4是一款PostgreSQL数据库的官方客户端(PostgreSQL数据库专用图形化管理工具)。采用B/S架构设计,服务器端模式可以实现集中部署,用户通过浏览器即可实现管理个人建立的数据库,即安全又便于使用;功能强大且支持中文、英文等多种语言。

本方案基于CentOS8系统设计,建议在RedHat/CentOS系统中使用。


1.PGAdmin4的安装

1、下载并安装Extra Packages for Enterprise Linux(EPEL)的yum源配置文件。可以从CentOS官方yum源安装,也可以使用国内/本地/私有yum源安装。本例使用了阿里云的yum源。

[centos@host ~]$ sudo dnf install https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

2、打开PostgreSQL官方网站下载页面【https://www.postgresql.org/download/linux/】,选择PostgreSQL适配的操作系统版本。

PostgreSQL适配操作系统

3、选择PostgreSQL版本,适配平台和架构。

PostgreSQL版本,适配平台和架构

4、下载并安装PostgreSQL官方yum源配置文件。

[centos@host ~]$ sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

技巧:PostgreSQL官方的yum源配置文件提供了PostgreSQL12/11/10/9.6/9.5/9.4共6个版本的配置信息,一般情况下我们只使用计划安装版本的配置信息,禁用不需要的配置信息可以提高下载速度。本例计划安装12版,可以禁用11/10/9.6/9.5/9.4版的配置信息。

[centos@host  ~]$ sudo dnf config-manager --disable pgdg11

[centos@host  ~]$ sudo dnf config-manager --disable pgdg10

[centos@host  ~]$ sudo dnf config-manager --disable pgdg96

[centos@host  ~]$ sudo dnf config-manager --disable pgdg96

[centos@host  ~]$ sudo dnf config-manager --disable pgdg94

注意:如果使用本地或私有yum源,可忽略第1-3步,直接获取本地/私有yum源的配置文件使用即可。有关如何进行yum源的本地化/私有化,请阅读文章《RedHat/CentOS8 【国内/本地/私有 YUM 源】制作和使用》,文章地址【https://www.jianshu.com/p/68db74388600】。

5、通过PostgreSQL官方yum源安装PGAdmin4客户端程序。

[centos@host  ~]$ sudo dnf install pgadmin4

注意:PGAdmin4客户端通过 Apache Httpd 程序发布,自动安装Httpd。Httpd程序安装目录是"/usr/sbin",Httpd程序配置目录是"/etc/httpd",PGAdmin4客户端配置目录是"/usr/lib/python3.6/site-packages/pgadmin4-web"。


2.PGAdmin4的配置

1、设置Httpd的用于启动PGAdmin4的虚拟目录配置文件。

位于程序配置目录"/etc/httpd/conf.d"下的"pgadmin4.conf.sample"文件是用于PGAdmin4虚拟目录的配置文件,在PGAdmin4安装时已经被创建。拷贝并重命名这个文件为"pgadmin4.conf"并设置。

1)拷贝并重命名配置文件。拷贝并重命名"/etc/httpd/conf.d/pgadmin4.conf.sample"到"/etc/httpd/conf.d/pgadmin4.conf":

[centos@host  ~]$ sudo cp /etc/httpd/conf.d/pgadmin4.conf.sample /etc/httpd/conf.d/pgadmin4.conf

2)使用文本编辑器打开"/etc/httpd/conf.d/pgadmin4.conf"文件:

[centos@host  ~]$ sudo gedit /etc/httpd/conf.d/pgadmin4.conf

设置文件内容如下(默认已设置完成,只需要验证即可):

配置文件内容样例

2、启动Httpd服务,并设置Httpd服务器为开机自启动状态。

[centos@host  ~]$ sudo systemctl enable httpd

[centos@host  ~]$ sudo systemctl start httpd

正常启动后,查询启动状态:

[centos@host  ~]$ sudo systemctl status httpd

查询结果如下图,表示服务正常:

正常启动服务状态

3、修改PGAdmin4初始化配置文件,指定PGAdmin4启动资源目录。

使用文本编辑器打开"/usr/lib/python3.6/site-packages/pgadmin4-web/config_distro.py"文件:

[centos@host  ~]$ sudo gedit /usr/lib/python3.6/site-packages/pgadmin4-web/config_distro.py

在文件中追加以下内容并保存:

HELP_PATH = '/usr/share/doc/pgadmin4-docs/en_US/html'

UPGRADE_CHECK_ENABLED = False

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'

SERVER_MODE = True

4、执行PGAdmin4初始化脚本,设置登录账户的用户名(邮箱格式)/口令,完成初始化。

[centos@host  ~]$ sudo python3  /usr/lib/python3.6/site-packages/pgadmin4-web/setup.py

初始化过程如下:

正常初始化完成状态

初始化工作会生成PGAdmin4启动所需资源的存储目录,登录账户用户名和口令。

5、修改PGAdmin4启动资源目录的所有者用户和组为Httpd服务的管理用户"apache"。

[centos@host  ~]$ sudo chown -R apache:apache /var/lib/pgadmin4

[centos@host  ~]$ sudo chown -R apache:apache /var/log/pgadmin4

6、在SELinux模式运行时,设置自定义启动资源目录的安全标记和安全策略。

[centos@host  ~]$ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/lib/pgadmin4(/.*)?"

[centos@host  ~]$ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/log/pgadmin4(/.*)?"

[centos@host  ~]$ sudo restorecon -Rv /var/lib/pgadmin4/

[centos@host  ~]$ sudo restorecon -Rv /var/log/pgadmin4/

[centos@host  ~]$ sudo setsebool -P httpd_can_network_connect 1

7、重新启动Httpd服务。

[centos@host  ~]$ sudo systemctl restart httpd

8、设置防火墙端口(CentOS8默认安装firewall防火墙),允许"80"端口(Httpd默认端口)访问服务器。

[centos@host  ~]$ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent

[centos@host  ~]$ sudo firewall-cmd --reload


3.PGAdmin4的使用

在浏览器中输入"http://ip/pgadmin4"或 "http://localhost/pgadmin4"来访问PGAdmin4客户端:

身份鉴别 主界面
上一篇下一篇

猜你喜欢

热点阅读