I den här artikeln kommer du att lära dig hur du installerar PostgreSQL 12 på Fedora 33. PostgreSQL är en av de populära databasservrarna med öppen källkod.
Steg för att installera PostgreSQL 12 på Fedora 33.
Steg 1:Uppdatera Fedora-systempaket
sudo dnf update -y
Obs:Starta om systemet efter uppdateringen.
sudo reboot
Steg 2:Lägg till 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
Tryck på y ” för att bekräfta installationen
Exempelutdata:
[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 ~]#
Steg 3:Installera PostgreSQL 12 på Fedora 33
sudo dnf install postgresql12-server postgresql12
Tryck på y ” för att bekräfta installationen
Exempelutdata:
[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 ~]#
Steg 4:Initiera PostgreSQL-databasen
$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
Exempelutdata:
[root@fedora ~]# sudo /usr/pgsql-12/bin/postgresql-12-setup initdb Initializing database ... OK [root@fedora ~]#
Steg 5:Starta PostgreSQL-tjänsten automatiskt vid uppstart
sudo systemctl enable --now postgresql-12
Exempelutdata
[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 ~]#
Steg 6:Verifiera PostgreSQL-tjänstens status
systemctl status postgresql-12
Exempelutdata
[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 ~]#
Steg 7:Konfigurera brandväggen
(Valfritt Om du använder brandvägg, följ stegen nedan)
– Detta gör att fjärrklienter kan ansluta till PostgreSQL-databasserver
sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload
Exempelutdata
[root@fedora ~]# sudo firewall-cmd --add-service=postgresql --permanent success [root@fedora ~]# sudo firewall-cmd --reload success [root@fedora ~]#
Steg 8:Tillåt fjärråtkomst till PostgreSQL
detta är valfritt, du kan hoppa över om du inte vill tillåta fjärråtkomst till din PostgreSQL-databasserver
Redigera fil –> ” /var/lib/pgsql/12/data/postgresql.conf ”
$ sudo vim /var/lib/pgsql/12/data/postgresql.conf listen_addresses = '*'
Ställ in Lyssna på adress till din server IP-adress eller så kan du nämna "*" för alla gränssnitt.
Du måste ställa in fjärranslutningar från tillåtna värdar.
$ 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 måste starta om PostgreSQL-tjänsten efter ändringar som gjorts i konfigurationsfilen.
sudo systemctl restart postgresql-12
Steg 9:Ställ in PostgreSQL-adminanvändarens lösenord
$ sudo su - postgres $ psql -c "alter user postgres with password 'YourPassword'"
I kommandot ovan uppdaterar du "YourPassword" till ett starkt lösenord för Postgres-användare.
Exempelutdata:
[root@fedora ~]# sudo su - postgres [postgres@fedora ~]$ psql -c "alter user postgres with password 'YourPassword'" ALTER ROLE [postgres@fedora ~]$
I slutet av handledningen har du lärt dig hur du installerar PostgreSQL 12 på Fedora 33.