GNU/Linux >> Tutoriels Linux >  >> Cent OS

Comment installer PostgreSQL avec pgAdmin sur CentOS 8

Présentation

PostgreSQL est le SGBDR le plus avancé et pgAdmin est une interface utilisateur Web pour Postgres. Ici, vous verrez comment installer PostgreSQL avec pgAdmin sur CentOS / RHEL 8.

Qu'est-ce que PostgreSQL ?

PostgreSQL (également appelé Postgres ) est un système de gestion de base de données relationnelle (SGBDR) libre et open source mettant l'accent sur l'extensibilité et la conformité SQL. PostgreSQL s'appelait à l'origine POSTGRES, faisant référence à ses origines en tant que successeur de Ingres base de données. En 1996, le projet a été renommé PostgreSQL pour refléter sa prise en charge de SQL.

PostgreSQL propose des transactions avec des propriétés d'atomicité, de cohérence, d'isolation et de durabilité (ACID), des vues pouvant être mises à jour automatiquement, des vues matérialisées, des déclencheurs, des clés étrangères et des procédures stockées. Il est conçu pour gérer une gamme de charges de travail, des machines uniques aux entrepôts de données ou aux services Web avec de nombreux utilisateurs simultanés. Il s'agit de la base de données par défaut pour macOS Server, et est également disponible pour Linux, FreeBSD, OpenBSD et Windows.

Qu'est-ce que pgAdmin ?

pgAdmin est un outil d'administration d'interface utilisateur graphique (GUI) gratuit et open source pour les serveurs de base de données Postgres.

En plus de, pgAdmin est disponible dans les interfaces de bureau et Web. pgAdmin est le plus riche en fonctionnalités et le plus populaire parmi les autres outils d'administration pour PostgreSQL.

Mettre à jour les packages de serveur Linux

Alors mettez à jour les packages de serveur Linux en utilisant dnf commande.

# dnf update -y

Installer Postgres Officiel

Pour installer la dernière version, nous devons ajouter le référentiel yum officiel de PostgreSQL sur notre serveur Linux.

[root@unixcop ~]# dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 21:31:22 ago on Sun Aug  8 10:39:31 2021.
pgdg-redhat-repo-latest.noarch.rpm               18 kB/s |  12 kB     00:00    
Dependencies resolved.
================================================================================
 Package                 Architecture  Version        Repository           Size
================================================================================
Installing:
 pgdg-redhat-repo        noarch        42.0-19        @commandline         12 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 12 k
Installed size: 12 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : pgdg-redhat-repo-42.0-19.noarch                        1/1 
  Verifying        : pgdg-redhat-repo-42.0-19.noarch                        1/1 

Installed:
  pgdg-redhat-repo-42.0-19.noarch                                               

Complete!
[root@unixcop ~]# 

Désactivez le module PostgreSQL dans le référentiel yum standard en exécutant la commande suivante.

# dnf -qy module disable postgresql

Installation du serveur de base de données Postgres sur CentOS 8

Installez donc le serveur de base de données Postgres 13 (le plus récent au moment de la rédaction de cet article) sur votre serveur Linux en utilisant dnf commande.

[root@unixcop ~]# dnf install -y postgresql13-server
Last metadata expiration check: 0:01:38 ago on Mon Aug  9 10:31:26 2021.
Dependencies resolved.
======================================================================================================================================================
 Package                                    Architecture                  Version                                 Repository                     Size
======================================================================================================================================================
Installing:
 postgresql13-server                        x86_64                        13.3-2PGDG.rhel8                        pgdg13                        5.5 M
Installing dependencies:
 libicu                                     x86_64                        60.3-2.el8_1                            baseos                        8.8 M
 postgresql13                               x86_64                        13.3-2PGDG.rhel8                        pgdg13                        1.5 M
 postgresql13-libs                          x86_64                        13.3-2PGDG.rhel8                        pgdg13                        413 k

Transaction Summary
======================================================================================================================================================
Install  4 Packages

Total download size: 16 M
Installed size: 63 M
Downloading Packages:
(1/4): postgresql13-libs-13.3-2PGDG.rhel8.x86_64.rpm                                                                   69 kB/s | 413 kB     00:06    
(2/4): postgresql13-13.3-2PGDG.rhel8.x86_64.rpm                                                                        92 kB/s | 1.5 MB     00:16    
(3/4): postgresql13-server-13.3-2PGDG.rhel8.x86_64.rpm                                                                158 kB/s | 5.5 MB     00:35    
(4/4): libicu-60.3-2.el8_1.x86_64.rpm                                                                                 190 kB/s | 8.8 MB     00:47    
------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                 345 kB/s |  16 MB     00:48     
warning: /var/cache/dnf/pgdg13-e81daebfc8b779ec/packages/postgresql13-13.3-2PGDG.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 <[email protected]>"
 Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                              1/1 
  Installing       : postgresql13-libs-13.3-2PGDG.rhel8.x86_64                                                                                    1/4 
  Running scriptlet: postgresql13-libs-13.3-2PGDG.rhel8.x86_64                                                                                    1/4 
  Installing       : libicu-60.3-2.el8_1.x86_64                                                                                                   2/4 
  Running scriptlet: libicu-60.3-2.el8_1.x86_64                                                                                                   2/4 
  Installing       : postgresql13-13.3-2PGDG.rhel8.x86_64                                                                                         3/4 
  Running scriptlet: postgresql13-13.3-2PGDG.rhel8.x86_64                                                                                         3/4 
  Running scriptlet: postgresql13-server-13.3-2PGDG.rhel8.x86_64                                                                                  4/4 
  Installing       : postgresql13-server-13.3-2PGDG.rhel8.x86_64                                                                                  4/4 
  Running scriptlet: postgresql13-server-13.3-2PGDG.rhel8.x86_64                                                                                  4/4 
  Verifying        : libicu-60.3-2.el8_1.x86_64                                                                                                   1/4 
  Verifying        : postgresql13-13.3-2PGDG.rhel8.x86_64                                                                                         2/4 
  Verifying        : postgresql13-libs-13.3-2PGDG.rhel8.x86_64                                                                                    3/4 
  Verifying        : postgresql13-server-13.3-2PGDG.rhel8.x86_64                                                                                  4/4 

Installed:
  libicu-60.3-2.el8_1.x86_64                          postgresql13-13.3-2PGDG.rhel8.x86_64         postgresql13-libs-13.3-2PGDG.rhel8.x86_64        
  postgresql13-server-13.3-2PGDG.rhel8.x86_64        

Complete!
[root@unixcop ~]# 

Vous devez exécuter la commande suivante une fois pour initialiser la base de données Postgres.

[root@unixcop ~]# /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK

[root@unixcop ~]# 

Activez, démarrez et vérifiez également l'état de la base de données Postgres avec ces commandes.

[root@unixcop ~]# systemctl start postgresql-13
[root@unixcop ~]# systemctl enable postgresql-13
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-13.service → /usr/lib/systemd/system/postgresql-13.service.
[root@unixcop ~]# 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 Mon 2021-08-09 08:21:20 EDT; 21s ago
     Docs: https://www.postgresql.org/docs/13/static/
 Main PID: 2178 (postmaster)
    Tasks: 8 (limit: 11426)
   Memory: 16.8M
   CGroup: /system.slice/postgresql-13.service
           ├─2178 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
           ├─2179 postgres: logger 
           ├─2181 postgres: checkpointer 
           ├─2182 postgres: background writer 
           ├─2183 postgres: walwriter 
           ├─2184 postgres: autovacuum launcher 
           ├─2185 postgres: stats collector 
           └─2186 postgres: logical replication launcher 

Aug 09 08:21:20 unixcop systemd[1]: Starting PostgreSQL 13 database server...
Aug 09 08:21:20 unixcop postmaster[2178]: 2021-08-09 08:21:20.237 EDT [2178] LOG:  redirecting log output to logging collector process
Aug 09 08:21:20 unixcop postmaster[2178]: 2021-08-09 08:21:20.237 EDT [2178] HINT:  Future log output will appear in directory "log".
Aug 09 08:21:20 unixcop systemd[1]: Started PostgreSQL 13 database server.
[root@unixcop ~]# systemctl is-enabled postgresql-13
enabled
[root@unixcop ~]# 

Vérifiez également la version de PostgreSQL installé.

[root@unixcop ~]# psql -V
psql (PostgreSQL) 13.3
[root@unixcop ~]# 

Passer à postgres utilisateur et connectez-vous à psql shell pour définir le mot de passe de l'utilisateur administrateur.

[root@unixcop ~]# su - postgres
[postgres@unixcop ~]$ psql
psql (13.3)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD 'unixcop';
ALTER ROLE
postgres=# \q
[postgres@unixcop ~]$ exit
logout
[root@unixcop ~]# 

Configurer l'accès réseau pour le service de base de données Postgres

Vous remarquerez peut-être que le service PostgreSQL est initialement exécuté uniquement sur l'interface localhost.

Vous devez donc éditer le fichier de configuration PostgreSQL dans vim éditeur de texte.

# vi /var/lib/pgsql/13/data/postgresql.conf

Recherchez la directive suivante.

# listen_addresses = 'localhost'

Et remplacez-la par la directive suivante.

listen_addresses = '*'

Votre service de base de données Postgres est maintenant configuré pour écouter sur toutes les interfaces réseau.

Autoriser les clients du réseau à accéder au service PostgreSQL dans pg_hba.conf fichier.

# echo "host all all 192.168.13.0/24 md5" >> /var/lib/pgsql/13/data/pg_hba.conf

Redémarrez le service de base de données Postgres pour appliquer les modifications.

# systemctl restart postgresql-13.service

Le service Postgres s'exécute désormais sur toutes les interfaces réseau.

Configurer le pare-feu Linux pour la base de données Postgres

Nous allons autoriser le service Postgre en utilisant la commande firewall-cmd.

[root@unixcop ~]# firewall-cmd --permanent --add-service=postgresql
success
[root@unixcop ~]# firewall-cmd --reload
success
[root@unixcop ~]# 

Ainsi, le serveur de base de données Postgres a été installé sur le serveur Linux.

Installation du référentiel pgAdmin Yum sur CentOS 8

pgAdmin est une interface Web populaire pour l'administration de bases de données PostgreSQL.

Bien que pgAdmin soit également fourni dans les référentiels yum officiels de PostgreSQL. Mais cela ne fonctionne pas sur notre serveur CentOS 8.

Par conséquent, nous allons installer la dernière version stable de pgAdmin depuis le dépôt officiel yum de pgAdmin.

Comme nous allons ajouter ce référentiel yum, vous devez d'abord supprimer les référentiels PostgreSQL yum de votre serveur Linux.

# dnf remove -y pgdg-redhat-repo

Ajoutez le dépôt yum officiel pgAdmin dans votre système d'exploitation Linux avec la commande :

[root@unixcop ~]#  dnf install -y https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-1-1.noarch.rpm
Last metadata expiration check: 1 day, 0:04:44 ago on Sun Aug  8 10:39:31 2021.
pgadmin4-redhat-repo-1-1.noarch.rpm                                                                                   5.6 kB/s | 6.6 kB     00:01    
Dependencies resolved.
======================================================================================================================================================
 Package                                      Architecture                   Version                       Repository                            Size
======================================================================================================================================================
Installing:
 pgadmin4-redhat-repo                         noarch                         1-1                           @commandline                         6.6 k

Transaction Summary
======================================================================================================================================================
Install  1 Package

Total size: 6.6 k
Installed size: 4.0 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                              1/1 
  Installing       : pgadmin4-redhat-repo-1-1.noarch                                                                                              1/1 
  Verifying        : pgadmin4-redhat-repo-1-1.noarch                                                                                              1/1 

Installed:
  pgadmin4-redhat-repo-1-1.noarch                                                                                                                     

Complete!
[root@unixcop ~]# 

De plus, pgAdmin nécessite certains packages logiciels qui ne sont pas disponibles dans les référentiels yum standard.

Utilisez la commande dnf et installez le référentiel EPEL yum.

# dnf install -y epel-release

Construisez le cache pour les référentiels yum nouvellement installés avec la commande :

[root@unixcop ~]# dnf makecache
CentOS Linux 8 - AppStream                                                                                            2.6 kB/s | 4.3 kB     00:01    
CentOS Linux 8 - BaseOS                                                                                               5.4 kB/s | 3.9 kB     00:00    
CentOS Linux 8 - Extras                                                                                               2.8 kB/s | 1.5 kB     00:00    
Extra Packages for Enterprise Linux Modular 8 - x86_64                                                                 21 kB/s |  36 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64                                                                         22 kB/s |  33 kB     00:01    
pgadmin4                                                                                                              704  B/s | 833  B     00:01    
pgadmin4                                                                                                              3.8 MB/s | 3.8 kB     00:00    
Importing GPG key 0x210976F2:
 Userid     : "Package Manager (Package Signing Key) <[email protected]>"
 Fingerprint: E869 7E2E EF76 C02D 3A63 3277 8881 B2A8 2109 76F2
 From       : /etc/pki/rpm-gpg/PGADMIN_PKG_KEY
Is this ok [y/N]: y
pgadmin4                                                                                                              117 kB/s | 441 kB     00:03    
Metadata cache created.

Installation de l'interface utilisateur Web de pgAdmin

Vous pouvez maintenant installer pgAdmin en utilisant :

# dnf install -y pgadmin4

REMARQUE IMPORTANTE :

Pour configurer les politiques SELinux, le script de configuration pgAdmin nécessite semanage , qui est fournie dans les packages policycoreutils-python-utils. Par conséquent, vous devez l'installer avant d'exécuter le script d'installation de pgAdmin.

Vous pouvez également visiter ce lien pour résoudre correctement ce problème. Comment réparer l'erreur "commande semanage" introuvable dans CentOS

# dnf install -y policycoreutils-python-utils

Le logiciel pgAdmin est livré avec un script de configuration bien écrit pour configurer le service Web pgAdmin. Exécutez-le pour créer un utilisateur administrateur et un serveur Web Apache pour déployer le service Web pgAdmin.

[root@unixcop ~]# /usr/pgadmin4/bin/setup-web.sh
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: [email protected]
Password: 
Retype password:
pgAdmin 4 - Application Initialisation
======================================

Creating storage and log directories...
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
[root@unixcop ~]# 

Démarrez, activez et vérifiez l'état du service httpd.

[root@unixcop ~]# systemctl start httpd
[root@unixcop ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@unixcop ~]# 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 Mon 2021-08-09 08:48:49 EDT; 16s ago
     Docs: man:httpd.service(8)
 Main PID: 3881 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 241 (limit: 11426)
   Memory: 44.2M
   CGroup: /system.slice/httpd.service
           ├─3881 /usr/sbin/httpd -DFOREGROUND
           ├─3882 /usr/sbin/httpd -DFOREGROUND
           ├─3883 /usr/sbin/httpd -DFOREGROUND
           ├─3884 /usr/sbin/httpd -DFOREGROUND
           ├─3885 /usr/sbin/httpd -DFOREGROUND
           └─3886 /usr/sbin/httpd -DFOREGROUND

Aug 09 08:48:47 unixcop systemd[1]: Starting The Apache HTTP Server...
Aug 09 08:48:47 unixcop httpd[3881]: [Mon Aug 09 08:48:47.749981 2021] [so:warn] [pid 3881:tid 140142522952000] AH01574: module wsgi_module is alread>
Aug 09 08:48:49 unixcop httpd[3881]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:feca>
Aug 09 08:48:49 unixcop systemd[1]: Started The Apache HTTP Server.
Aug 09 08:48:52 unixcop httpd[3881]: Server configured, listening on: port 80
lines 1-21/21 (END)

Configurer le pare-feu Linux pour autoriser le trafic entrant vers le serveur Web Apache

[root@unixcop ~]# firewall-cmd --permanent --add-service=http
success
[root@unixcop ~]# firewall-cmd --reload
success
[root@unixcop ~]# 

Ouvrez l'URL http://your_ip_address/pgadmin4/ dans un navigateur Web.

Connectez-vous à pgAdmin en tant qu'utilisateur administrateur que nous avons créé par setup-web.sh script.

Pour ajouter votre serveur de base de données PostgreSQL dans l'inventaire pgAdmin, cliquez sur "Ajouter un nouveau serveur".

Indiquez le nom du serveur et cliquez sur "Connexion" onglet.

Fournissez les informations de connexion à la base de données dans cette boîte de dialogue que vous avez créée.

Cliquez ensuite sur "Enregistrer".

Notre serveur de base de données Postgres a été ajouté dans pgAdmin. Vous pouvez voir une arborescence de votre serveur de base de données dans le panneau de gauche.

Conclusion

Dans ce tutoriel, vous avez appris à installer PostgreSQL avec pgAdmin sur le serveur CentOS 8.


Cent OS
  1. Comment installer CentOS 8 (avec captures d'écran)

  2. Comment installer PostgreSQL sur CentOS 7

  3. Comment installer PostgreSQL 10 sur CentOS 6 / RHEL 6

  4. Comment installer et configurer Postgres 13 sur Centos 8

  5. Comment installer Postgres 14 sur Rocky Linux 8/Centos 8

Comment installer PostgreSQL dans CentOS 8

Comment installer PostgreSQL sur CentOS 6

Comment installer OpenNMS sur CentOS 7

Comment installer PostgreSQL et pgAdmin dans CentOS 8

Comment installer pgAdmin sur CentOS 7

Comment installer pgAdmin sur CentOS 8