I denne artikel lærer du, hvordan du installerer PostgreSQL 12 på Fedora 33. PostgreSQL er en af de populære open source-databaseservere.
Trin til at installere PostgreSQL 12 på Fedora 33.
Trin 1:Opdater Fedora-systempakker
sudo dnf update -y
Bemærk:Genstart dit system efter opdateringen.
sudo reboot
Trin 2:Tilføj PostgreSQL Yum Repository på Fedora 33
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-33-x86_64/pgdg-fedora-repo-latest.noarch.rpm
Tryk på "y ” for at bekræfte installationen
Eksempeloutput:
[root@fedora ~]# sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-33-x86_64/pgdg-fedora-repo-latest.noarch.rpm Last metadata expiration check: 0:28:12 ago on Sun 31 Jan 2021 07:39:13 AM EST. pgdg-fedora-repo-latest.noarch.rpm 6.6 kB/s | 10 kB 00:01 Dependencies resolved. ============================================================================================= Package Architecture Version Repository Size ============================================================================================= Installing: pgdg-fedora-repo noarch 42.0-13 @commandline 10 k Transaction Summary ============================================================================================= Install 1 Package Total size: 10 k Installed size: 11 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-fedora-repo-42.0-13.noarch 1/1 Verifying : pgdg-fedora-repo-42.0-13.noarch 1/1 Installed: pgdg-fedora-repo-42.0-13.noarch Complete! [root@fedora ~]#
Trin 3:Installer PostgreSQL 12 på Fedora 33
sudo dnf install postgresql12-server postgresql12
Tryk på "y ” for at bekræfte installationen
Eksempeloutput:
[root@fedora ~]# sudo dnf install postgresql12-server postgresql12 PostgreSQL common RPMs for Fedora 33 - x86_64 89 kB/s | 282 kB 00:03 PostgreSQL 13 for Fedora 33 - x86_64 61 kB/s | 194 kB 00:03 PostgreSQL 12 for Fedora 33 - x86_64 62 kB/s | 192 kB 00:03 PostgreSQL 11 for Fedora 33 - x86_64 66 kB/s | 193 kB 00:02 PostgreSQL 10 for Fedora 33 - x86_64 42 kB/s | 137 kB 00:03 PostgreSQL 9.6 for Fedora 33 - x86_64 43 kB/s | 117 kB 00:02 PostgreSQL 9.5 for Fedora 33 - x86_64 242 B/s | 506 B 00:02 Dependencies resolved. =========================================================================================================== Package Architecture Version Repository Size =========================================================================================================== Installing: postgresql12-server x86_64 12.5-1PGDG.f33 pgdg12 5.5 M Installing dependencies: postgresql12 x86_64 12.5-1PGDG.f33 pgdg12 1.6 M postgresql12-libs x86_64 12.5-1PGDG.f33 pgdg12 749 k Transaction Summary =========================================================================================================== Install 3 Packages Total download size: 7.8 M Installed size: 32 M Is this ok [y/N]: y Downloading Packages: (1/3): postgresql12-libs-12.5-1PGDG.f33.x86_64.rpm 299 kB/s | 749 kB 00:02 (2/3): postgresql12-12.5-1PGDG.f33.x86_64.rpm 435 kB/s | 1.6 MB 00:03 (3/3): postgresql12-server-12.5-1PGDG.f33.x86_64.rpm 668 kB/s | 5.5 MB 00:08 ---------------------------------------------------------------------------------------------------------------------------------------- Total 949 kB/s | 7.8 MB 00:08 warning: /var/cache/dnf/pgdg12-c8926cd352a04735/packages/postgresql12-12.5-1PGDG.f33.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY PostgreSQL 12 for Fedora 33 - 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 Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : postgresql12-libs-12.5-1PGDG.f33.x86_64 1/3 Running scriptlet: postgresql12-libs-12.5-1PGDG.f33.x86_64 1/3 Installing : postgresql12-12.5-1PGDG.f33.x86_64 2/3 Running scriptlet: postgresql12-12.5-1PGDG.f33.x86_64 2/3 Running scriptlet: postgresql12-server-12.5-1PGDG.f33.x86_64 3/3 Installing : postgresql12-server-12.5-1PGDG.f33.x86_64 3/3 Running scriptlet: postgresql12-server-12.5-1PGDG.f33.x86_64 3/3 Verifying : postgresql12-12.5-1PGDG.f33.x86_64 1/3 Verifying : postgresql12-libs-12.5-1PGDG.f33.x86_64 2/3 Verifying : postgresql12-server-12.5-1PGDG.f33.x86_64 3/3 Installed: postgresql12-12.5-1PGDG.f33.x86_64 postgresql12-libs-12.5-1PGDG.f33.x86_64 postgresql12-server-12.5-1PGDG.f33.x86_64 Complete! [root@fedora ~]#
Trin 4:Initialiser PostgreSQL-databasen
$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
Eksempeloutput:
[root@fedora ~]# sudo /usr/pgsql-12/bin/postgresql-12-setup initdb Initializing database ... OK [root@fedora ~]#
Trin 5:Start automatisk PostgreSQL-tjenesten ved opstart
sudo systemctl enable --now postgresql-12
Eksempeloutput
[root@fedora ~]# sudo systemctl enable --now postgresql-12 Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-12.service → /usr/lib/systemd/system/postgresql-12.service. [root@fedora ~]#
Trin 6:Bekræft PostgreSQL-tjenestestatus
systemctl status postgresql-12
Eksempeloutput
[root@fedora ~]# systemctl status postgresql-12 postgresql-12.service - PostgreSQL 12 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-01-31 08:21:10 EST; 52s ago Docs: https://www.postgresql.org/docs/12/static/ Process: 5468 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Main PID: 5473 (postmaster) Tasks: 8 (limit: 3446) Memory: 16.6M CPU: 84ms CGroup: /system.slice/postgresql-12.service ├─5473 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/ ├─5474 postgres: logger ├─5476 postgres: checkpointer ├─5477 postgres: background writer ├─5478 postgres: walwriter ├─5479 postgres: autovacuum launcher ├─5480 postgres: stats collector └─5481 postgres: logical replication launcher Jan 31 08:21:10 fedora systemd[1]: Starting PostgreSQL 12 database server... Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.806 EST [5473] LOG: starting PostgreSQL 12.5 on x86_64-pc-linux-gnu, comp> Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.808 EST [5473] LOG: listening on IPv6 address "::1", port 5432 Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.808 EST [5473] LOG: listening on IPv4 address "127.0.0.1", port 5432 Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.811 EST [5473] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQ> Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.813 EST [5473] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432" Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.832 EST [5473] LOG: redirecting log output to logging collector process Jan 31 08:21:10 fedora postmaster[5473]: 2021-01-31 08:21:10.832 EST [5473] HINT: Future log output will appear in directory "log". Jan 31 08:21:10 fedora systemd[1]: Started PostgreSQL 12 database server. [root@fedora ~]#
Trin 7:Konfigurer Firewall
(Valgfrit Hvis du bruger firewall, så følg nedenstående trin)
– Dette vil tillade fjernklienter at oprette forbindelse til PostgreSQL-databaseserver
sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload
Eksempeloutput
[root@fedora ~]# sudo firewall-cmd --add-service=postgresql --permanent success [root@fedora ~]# sudo firewall-cmd --reload success [root@fedora ~]#
Trin 8:Tillad fjernadgang til PostgreSQL
dette er valgfrit, du kan springe over, hvis du ikke vil tillade fjernadgang til din PostgreSQL-databaseserver
Rediger fil –> ” /var/lib/pgsql/12/data/postgresql.conf ”
$ sudo vim /var/lib/pgsql/12/data/postgresql.conf listen_addresses = '*'
Indstil Lyt til adresse til din server IP-adresse, eller du kan nævne "*" for alle grænseflader.
Du skal indstille fjernforbindelser fra tilladte værter.
$ sudo vim /var/lib/pgsql/12/data/pg_hba.conf # Accept from anywhere host all all 0.0.0.0/0 md5 # Accept from trusted subnet host all all 192.168.3.0/24 md5
du skal genstarte PostgreSQL-tjenesten efter ændringer i konfigurationsfilen.
sudo systemctl restart postgresql-12
Trin 9:Indstil PostgreSQL-administratorbrugerens adgangskode
$ sudo su - postgres $ psql -c "alter user postgres with password 'YourPassword'"
I ovenstående kommando skal du opdatere 'YourPassword' til en stærk adgangskode for Postgres-bruger.
Eksempeloutput:
[root@fedora ~]# sudo su - postgres [postgres@fedora ~]$ psql -c "alter user postgres with password 'YourPassword'" ALTER ROLE [postgres@fedora ~]$
I slutningen af selvstudiet har du lært, hvordan du installerer PostgreSQL 12 på Fedora 33.