在本指南中,我们将探讨在CentOS 8上PostgreSQL 13的安装。RHEL 8 Linux服务器。PostgreSQL是一个功能强大的开源对象关系数据库系统,可以安全地存储和扩展最复杂的数据工作负载。PostgreSQL数据库系统旨在确保用户的可靠性,数据完整性,强大的功能集和可扩展性。

在CentOS 8上安装PostgreSQL 13 | RHEL 8

从本文更新起,PostgreSQL 13已可以运行,所有软件包都可以在PostgreSQL团队正式支持的YUM存储库中找到,从而简化了安装过程。

在开始安装之前,请确保您正在运行最新版本的CentOS 8和RHEL 8 系统。您可以运行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/RHEL 8上安装PostgreSQL 

我们需要在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 2020 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/RHEL 8上安装PostgreSQL 13软件包—服务器和客户端。

 

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 <pgsqlrpms-hackers@pgfoundry.org>"
 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数据库初始化,然后才能使用数据库服务器。

数据库的主要配置文件是 /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 2020-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

Jul 09 23:35:30 centos-01.computingforgeeks.com systemd&#91;1]: Starting PostgreSQL 13 database server...
Jul 09 23:35:30 centos-01.computingforgeeks.com postmaster&#91;1865]: 2020-07-09 23:35:30.180 CEST &#91;1865] LOG:  redirecting log output to logging collector process
Jul 09 23:35:30 centos-01.computingforgeeks.com postmaster&#91;1865]: 2020-07-09 23:35:30.180 CEST &#91;1865] HINT:  Future log output will appear in directory "log".
Jul 09 23:35:30 centos-01.computingforgeeks.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 然后将“侦听地址”设置为服务器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 

最后建议安装pgAdmin 4来管理PostgreSQL 13数据库, pgAdmin是领先的开源功能丰富的PostgreSQL管理和开发平台,可在Linux,Unix,Mac OS X和Windows上运行。这是在CentOS上安装pgAdmin4的链接。

具体安装方法可以参考:www.cnblogs.com/idccoupon/p/13913384.html

以上文章来源惠主机www.idccoupon.com,安装过程仅供参考,有任何疑问欢迎交流讨论。

 

Logo

更多推荐