在CentOS 8 rhel 8上安装PostgreSQL 13

时间:2020-02-23 14:32:19  来源:igfitidea点击:

在本教程中,我们将探讨在CentOS 8上的PostgreSQL 13的安装Rhel 8 Linux服务器。
PostgreSQL是一个强大的开源对象关系数据库系统,安全存储和缩放最复杂的数据工作负载。
PostgreSQL数据库系统旨在确保用户可靠性,数据完整性,强大功能集和可扩展性。
其发展背后有一个很大的社区,以确保创新和强大的声誉。

在CentOS 8 rhel 8上安装PostgreSQL 13

因为本文更新PostgreSQL 13可用运行生产工作负载。
所有软件包都在PostgreSQL Team正式支持的yum存储库中提供安装过程简化。

在开始安装之前,请确保我们正在运行CentOS 8的最新版本RHEL 8 Linux系统。
我们可以运行yum update命令来提取最新更新。

sudo yum -y update
sudo systemctl reboot

一旦系统重新启动,开始在CentOS 8 rhel 8上安装PostgreSQL 13 服务器。

第1步:添加PostgreSQL yum存储库

yum存储库支持CentOS和Rhel系列Linux发行版。
添加后,它将在PostgreSQL的支持生命周期内提供所有支持的PostgreSQL版本的自动更新。

运行以下命令以添加将PostgreSQL包提供给CentOS/RHEL 8服务器的存储库。

sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

通过按键盘中的y键在提示时接受安装。

ependencies resolved.
==================================================================================================================================================================
 Package                                     Architecture                      Version                              Repository                               Size
==================================================================================================================================================================
Installing:
 pgdg-redhat-repo                            noarch                            42.0-14                              @commandline                             11 k
Transaction Summary
==================================================================================================================================================================
Install  1 Package
Total size: 11 k
Installed size: 11 k
Is this ok [y/N]: y

第2步:在CentOS 8上安装PostgreSQL 13 | rhel 8.

我们需要在CentOS 8上禁用PostgreSQL AppStream存储库| Rhel 8 Linux包含其他一些版本的PostgreSQL。

sudo dnf -qy module disable postgresql

确认已启用的存储库列表。

$sudo dnf repolist
repo id                                                       repo name
AppStream                                                     CentOS-8 - AppStream
BaseOS                                                        CentOS-8 - Base
extras                                                        CentOS-8 - Extras
pgdg-common                                                   PostgreSQL common RPMs for RHEL/CentOS 8 - x86_64
pgdg10                                                        PostgreSQL 10 for RHEL/CentOS 8 - x86_64
pgdg11                                                        PostgreSQL 11 for RHEL/CentOS 8 - x86_64
pgdg12                                                        PostgreSQL 12 for RHEL/CentOS 8 - x86_64
pgdg13                                                        PostgreSQL 13 for RHEL/CentOS 8 - x86_64
pgdg95                                                        PostgreSQL 9.5 for RHEL/CentOS 8 - x86_64
pgdg96                                                        PostgreSQL 9.6 for RHEL/CentOS 8 - x86_64

检查存储库上是否可以查看postgreSQL 13包。

$sudo yum search postgresql13
Last metadata expiration check: 0:00:45 ago on Sat 31 Oct 2017 08:04:30 AM CET.
=============================================================== Name Exactly Matched: postgresql13 ===============================================================
postgresql13.x86_64 : PostgreSQL client programs and libraries
=================================================================== Name Matched: postgresql13 ===================================================================
postgresql13-docs.x86_64 : Extra documentation for PostgreSQL
postgresql13-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql13-test.x86_64 : The test suite distributed with PostgreSQL
postgresql13-devel.x86_64 : PostgreSQL development header files and libraries
postgresql13-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql13-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql13-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql13-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql13-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL

现在在CentOS 8上安装PostgreSQL 13软件包| Rhel 8服务器 - Server和Client。

sudo dnf install postgresql13 postgresql13-server

同意安装如果我们没事的话。

Dependencies resolved.
==================================================================================================================================================================
 Package                                       Architecture                     Version                                    Repository                        Size
==================================================================================================================================================================
Installing:
 postgresql13                                  x86_64                           13.0-1PGDG.rhel8                           pgdg13                           1.4 M
 postgresql13-server                           x86_64                           13.0-1PGDG.rhel8                           pgdg13                           5.5 M
Installing dependencies:
 libicu                                        x86_64                           60.3-2.el8_1                               BaseOS                           8.8 M
 postgresql13-libs                             x86_64                           13.0-1PGDG.rhel8                           pgdg13                           411 k
Transaction Summary
==================================================================================================================================================================
Install  4 Packages
Total download size: 16 M
Installed size: 63 M
Is this ok [y/N]: y

还需要GPG密钥存储库。

Total                                                                                                                              13 MB/s |  16 MB     00:01
warning: /var/cache/dnf/pgdg13-e81daebfc8b779ec/packages/postgresql13-13.0-1PGDG.rhel8.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
PostgreSQL 13 for RHEL/CentOS 8 - x86_64                                                                                          1.6 MB/s | 1.7 kB     00:00
Importing GPG key 0x442DF0F8:
 Userid     : "PostgreSQL RPM Building Project <Hyman@theitroad>"
 Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Is this ok [y/N]: y

第3步:初始化和启动数据库服务

在使用数据库服务器之前需要PostgreSQL数据库初始化。

$sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK

数据库主要配置文件是/var/lib/pgsql/13/data/postgresql.conf

$ls  /var/lib/pgsql/13/data/
base    pg_commit_ts  pg_ident.conf  pg_notify    pg_snapshots  pg_subtrans  PG_VERSION  postgresql.auto.conf
global  pg_dynshmem   pg_logical     pg_replslot  pg_stat       pg_tblspc    pg_wal      postgresql.conf
log     pg_hba.conf   pg_multixact   pg_serial    pg_stat_tmp   pg_twophase  pg_xact

启动PostgreSQL数据库服务器并将其设置为在启动时启动。

$sudo systemctl enable --now postgresql-13
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-13.service → /usr/lib/systemd/system/postgresql-13.service.

检查服务状态以确认运行。

$systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2017-07-09 23:35:30 CEST; 37s ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 1860 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 1865 (postmaster)
    Tasks: 8 (limit: 12210)
   Memory: 17.3M
   CGroup: /system.slice/postgresql-13.service
           ├─1865 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
           ├─1867 postgres: logger
           ├─1869 postgres: checkpointer
           ├─1870 postgres: background writer
           ├─1871 postgres: walwriter
           ├─1872 postgres: autovacuum launcher
           ├─1873 postgres: stats collector
           └─1874 postgres: logical replication launcher
May 09 23:35:30 centos-01.theitroad.com systemd&#91;1]: Starting PostgreSQL 13 database server...
May 09 23:35:30 centos-01.theitroad.com postmaster&#91;1865]: 2017-07-09 23:35:30.180 CEST &#91;1865] LOG:  redirecting log output to logging collector process
May 09 23:35:30 centos-01.theitroad.com postmaster&#91;1865]: 2017-07-09 23:35:30.180 CEST &#91;1865] HINT:  Future log output will appear in directory "log".
May 09 23:35:30 centos-01.theitroad.com systemd&#91;1]: Started PostgreSQL 13 database server.

第4步:设置PostgreSQL管理员用户的密码

更新PostgreSQL管理员用户密码。

$sudo su - postgres 
]$psql -c "alter user postgres with password 'StrongDBPassword'"
ALTER ROLE

步骤5:启用远程数据库连接(可选)

编辑文件 /var/lib/pgsql/13/data/postgresql.conf并将所有接口的Server IP地址或者"*"侦听收听地址。

$sudo vi /var/lib/pgsql/13/data/postgresql.conf
# line 59
listen_addresses = '192.168.10.10'

还将PostgreSQL设置为接受远程连接

$sudo vi /var/lib/pgsql/13/data/pg_hba.conf
# Accept from anywhere (not recommended)
host all all 0.0.0.0/0 md5
# Accept from trusted subnet (Recommended setting)
host all all 192.168.18.0/24 md5

保存更改后重新启动数据库服务。

sudo systemctl restart postgresql-13

使用psql命令的测试连接,同时提供用户名和可选的数据库名称。

$psql -U <dbuser> -h <serverip> -p 5432 <dbname>

第6步:安装PGADMIN 4 Web界面

PGAdmin是领先的开源功能丰富的PostgreSQL管理和开发平台,在Linux,UNIX,Mac OS X和Windows上运行。